Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion rust/cubesql/cubesql/src/compile/rewrite/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
error::DataFusionError,
logical_plan::{
build_join_schema, build_table_udf_schema, exprlist_to_fields,
exprlist_to_fields_from_schema, normalize_cols,
exprlist_to_fields_from_schema, normalize_col as df_normalize_col,
plan::{Aggregate, Extension, Filter, Join, Projection, Sort, TableUDFs, Window},
replace_col_to_expr, Column, CrossJoin, DFField, DFSchema, DFSchemaRef, Distinct,
EmptyRelation, Expr, ExprRewritable, ExprRewriter, GroupingSet, Like, Limit, LogicalPlan,
Expand Down Expand Up @@ -2441,3 +2441,29 @@
})
.collect::<Result<Vec<_>, _>>()
}

/// Recursively normalize all Column expressions in a list of expression trees
fn normalize_cols(
exprs: impl IntoIterator<Item = impl Into<Expr>>,
plan: &LogicalPlan,
) -> Result<Vec<Expr>, CubeError> {
exprs
.into_iter()
.map(|e| normalize_col(e.into(), plan))
.collect()
}

/// Recursively call [`df_normalize_col`] on all Column expressions
/// in the `expr` expression tree, realiasing the expressions if the name is different.
fn normalize_col(expr: Expr, plan: &LogicalPlan) -> Result<Expr, CubeError> {
if let Expr::Alias(_, _) = expr {
return Ok(df_normalize_col(expr, plan)?);
}
let original_expr_name = expr_name(&expr)?;
let mut normalized_expr = df_normalize_col(expr, plan)?;
let normalized_expr_name = expr_name(&normalized_expr)?;
if original_expr_name != normalized_expr_name {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalized_expr = normalized_expr.alias(&original_expr_name);

Check warning on line 2466 in rust/cubesql/cubesql/src/compile/rewrite/converter.rs

View check run for this annotation

Codecov / codecov/patch

rust/cubesql/cubesql/src/compile/rewrite/converter.rs#L2466

Added line #L2466 was not covered by tests
}
Ok(normalized_expr)
}
Loading