adriangb commented on code in PR #20091:
URL: https://github.com/apache/datafusion/pull/20091#discussion_r2749770625
##########
datafusion/expr/src/logical_plan/plan.rs:
##########
@@ -2807,14 +2829,129 @@ impl TableScan {
Ok(Self {
table_name,
source: table_source,
- projection,
+ projection: projection_exprs,
projected_schema,
filters,
fetch,
})
}
}
+/// Builder for creating `TableScan` nodes with expression-based projections.
+///
+/// This builder provides a flexible way to construct `TableScan` nodes,
+/// particularly when working with expression-based projections directly.
+#[derive(Clone)]
+pub struct TableScanBuilder {
Review Comment:
This is a bit of refactor that while not strictly necessary for this PR I
think will be helpful for future (and makes the code in this PR nicer).
##########
datafusion/expr/src/utils.rs:
##########
@@ -1286,6 +1286,36 @@ pub fn format_state_name(name: &str, state_name: &str)
-> String {
format!("{name}[{state_name}]")
}
+/// Convert projection expressions (assumed to be column references) to column
indices.
+///
+/// This function takes a list of expressions (which should be `Expr::Column`
variants)
+/// and returns the indices of those columns in the given schema. Returns
`None` if
+/// any expression is not a simple column reference, or if the column is not
found
+/// in the schema.
+///
+/// # Arguments
+/// * `exprs` - A slice of expressions, expected to be `Expr::Column` variants
+/// * `schema` - The schema to look up column indices in
+///
+/// # Returns
+/// * `Some(Vec<usize>)` - If all expressions are column references found in
the schema
+/// * `None` - If any expression is not a column reference or not found in
schema
+pub fn projection_indices_from_exprs(
Review Comment:
I'm not super sold on this function. I feel there is a footgun where you
don't know if `None` means complex expressions (maybe you forgot to check for
them?) or if `None` means a column was not found in the schema (also something
that maybe should never happen?).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]