adriangb commented on code in PR #18176:
URL: https://github.com/apache/datafusion/pull/18176#discussion_r2448519299
##########
datafusion/physical-plan/src/projection.rs:
##########
@@ -232,6 +236,163 @@ impl From<(Arc<dyn PhysicalExpr>, String)> for
ProjectionExpr {
}
}
+impl From<&(Arc<dyn PhysicalExpr>, String)> for ProjectionExpr {
+ fn from(value: &(Arc<dyn PhysicalExpr>, String)) -> Self {
+ Self::new(Arc::clone(&value.0), value.1.clone())
+ }
+}
+
+impl From<ProjectionExpr> for (Arc<dyn PhysicalExpr>, String) {
+ fn from(value: ProjectionExpr) -> Self {
+ (value.expr, value.alias)
+ }
+}
+
+/// A collection of projection expressions.
+///
+/// This struct encapsulates multiple `ProjectionExpr` instances,
+/// representing a complete projection operation and provides
+/// methods to manipulate and analyze the projection as a whole.
+#[derive(Debug, Clone)]
+pub struct Projection {
Review Comment:
I moved it into `physical-expr/projection.rs` and also moved
`ProjectionMapping` from `physical-expr/distribution/projection.rs` into this
new module. Does that sound okay to you?
##########
datafusion/physical-plan/src/projection.rs:
##########
@@ -127,42 +128,23 @@ impl ProjectionExec {
{
let input_schema = input.schema();
// convert argument to Vec<ProjectionExpr>
- let expr = expr.into_iter().map(Into::into).collect::<Vec<_>>();
+ let expr_vec = expr.into_iter().map(Into::into).collect::<Vec<_>>();
+ let projection = Projection::new(expr_vec);
- let fields: Result<Vec<Field>> = expr
- .iter()
- .map(|proj_expr| {
- let metadata = proj_expr
- .expr
- .return_field(&input_schema)?
- .metadata()
- .clone();
-
- let field = Field::new(
- &proj_expr.alias,
- proj_expr.expr.data_type(&input_schema)?,
- proj_expr.expr.nullable(&input_schema)?,
- )
- .with_metadata(metadata);
-
- Ok(field)
- })
- .collect();
-
- let schema = Arc::new(Schema::new_with_metadata(
- fields?,
- input_schema.metadata().clone(),
- ));
+ let schema = Arc::new(projection.project_schema(&input_schema)?);
// Construct a map from the input expressions to the output expression
of the Projection
let projection_mapping = ProjectionMapping::try_new(
- expr.iter().map(|p| (Arc::clone(&p.expr), p.alias.clone())),
+ projection
Review Comment:
done!
--
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]