Mailing List Thread: https://lists.apache.org/thread/9bvwjsxrt0o5tqfyf47wfw81z0kjgp7o
Is your feature request related to a problem or challenge?
The problem I'm encountering is related to #7981. Namely:
- when a plan gets optimized into a equivalent representation using other primitive plans it is necessary to have the optimized output match the schema of the originally created plan
- the primitive plan combination in question can involve columnized expressions as output field names (e.g. with aggregations), so in order to align it with the original schema aliasing is required
- there in lies the problem—all logical plans with a schema use
exprlist_to_fields to generate the initial schema, however this function will always result in a unqualified field for Expr::Alias unlike for Expr::Column, hence the schemas can never match
Describe the solution you'd like
Introduce a new enum variant along the lines of:
pub struct QualifiedAlias {
pub expr: Box<Expr>,
pub relation: OwnedTableReference,
pub name: String,
}
or alternatively extend the existing alias expression to accommodate for an optional relation:
pub struct Alias {
pub expr: Box<Expr>,
pub relation: Option<OwnedTableReference>,
pub name: String,
}
This would allow for 1-1 mapping between fields and column aliases.
Describe alternatives you've considered
Everything else seems like a hack:
- always strip qualifiers with
DFSchema::strip_qualifiers when building the schema in plan constructors; this will result in conflicts for joins
- push the qualifier down into the field name like in a5cff4e; the issue here is the unexpected derived column naming
- make
ExprSchemable::to_field try to parse the qualifer and name from an alias name; seems error prone, confusing and potentially problematic for column names with dots
Additional context
It seems like previously this could have been done with Projection::try_new_with_schema, but it looks like the overriding schema isn't being propagated through the optimizers after #7919.
Mailing List Thread: https://lists.apache.org/thread/9bvwjsxrt0o5tqfyf47wfw81z0kjgp7o
Is your feature request related to a problem or challenge?
The problem I'm encountering is related to #7981. Namely:
exprlist_to_fieldsto generate the initial schema, however this function will always result in a unqualified field forExpr::Aliasunlike forExpr::Column, hence the schemas can never matchDescribe the solution you'd like
Introduce a new enum variant along the lines of:
or alternatively extend the existing alias expression to accommodate for an optional relation:
This would allow for 1-1 mapping between fields and column aliases.
Describe alternatives you've considered
Everything else seems like a hack:
DFSchema::strip_qualifierswhen building the schema in plan constructors; this will result in conflicts for joinsExprSchemable::to_fieldtry to parse the qualifer and name from an alias name; seems error prone, confusing and potentially problematic for column names with dotsAdditional context
It seems like previously this could have been done with
Projection::try_new_with_schema, but it looks like the overriding schema isn't being propagated through the optimizers after #7919.