tokoko commented on code in PR #13127:
URL: https://github.com/apache/datafusion/pull/13127#discussion_r1817962263
##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -566,36 +568,57 @@ pub async fn from_substrait_rel(
let mut input = LogicalPlanBuilder::from(
from_substrait_rel(ctx, input, extensions).await?,
);
- let mut names: HashSet<String> = HashSet::new();
- let mut exprs: Vec<Expr> = vec![];
- for e in &p.expressions {
- let x =
- from_substrait_rex(ctx, e, input.clone().schema(),
extensions)
+
+ let mut default_exprs: Vec<Expr> = vec![];
+
+ // By default, a Substrait Project emits all inputs fields
+ let input_schema = input.schema();
+ for index in 0..(input_schema.fields().len()) {
+ let e =
+
Expr::Column(Column::from(input_schema.qualified_field(index)));
+ default_exprs.push(e);
+ }
+ // followed by all expressions
+ for expr in &p.expressions {
+ let e =
+ from_substrait_rex(ctx, expr, input.clone().schema(),
extensions)
.await?;
// if the expression is WindowFunction, wrap in a Window
relation
- if let Expr::WindowFunction(_) = &x {
+ if let Expr::WindowFunction(_) = &e {
// Adding the same expression here and in the project
below
// works because the project's builder uses
columnize_expr(..)
// to transform it into a column reference
- input = input.window(vec![x.clone()])?
+ input = input.window(vec![e.clone()])?
}
- // Ensure the expression has a unique display name, so
that project's
- // validate_unique_names doesn't fail
- let name = x.schema_name().to_string();
- let mut new_name = name.clone();
- let mut i = 0;
- while names.contains(&new_name) {
- new_name = format!("{}__temp__{}", name, i);
- i += 1;
+ default_exprs.push(e);
+ }
+
+ // Ensure that all expressions have a unique display name, so
that
+ // validate_unique_names does not fail when constructing the
project.
+ let mut name_tracker = NameTracker::new();
+
+ let mut final_exprs: Vec<Expr> = vec![];
+ match retrieve_emit_kind(p.common.as_ref()) {
Review Comment:
Isn't this essentially the same thing as `apply_emit_kind`? I get that
translating substrait Project into two DF Projects feels odd, but I think that
would be more consistent with other Rels w/o treating Project as an exception.
imho this is going into optimizer territory... if we do this, why not also try
to fold emits into AggregateRel measures as well for example? I think it would
be better to simply trust DF optimizer to fold the extra SELECTs afterwards
where necessary.
--
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]