czhang06 commented on code in PR #27802:
URL: https://github.com/apache/datafusion/pull/27802#discussion_r4724157935
##########
datafusion/expr/src/expr_rewriter/order_by.rs:
##########
@@ -61,14 +67,27 @@ fn rewrite_sort_col_by_aggs(
/// Remember that:
/// 1. given a projection with exprs: [a, b + c]
/// 2. t produces an output schema with two columns "a", "b + c"
+///
+/// A column that already resolves against `output_schema` is left as is.
+/// Projection expressions are written over the input, so an unqualified
+/// input column can share its name with a different output column (e.g.
+/// `price AS old_price, 10 - price AS price`); matching it against the
+/// projection would sort by the wrong output column.
fn rewrite_in_terms_of_projection(
expr: Expr,
proj_exprs: &[Expr],
input: &LogicalPlan,
+ output_schema: &DFSchema,
) -> Result<Expr> {
// assumption is that each item in exprs, such as "b + c" is
// available as an output column named "b + c"
expr.transform(|expr| {
+ if let Expr::Column(col) = &expr
+ && output_schema.has_column(col)
Review Comment:
Done in 31c434c, went with output-wins everywhere.
--
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]