@@ -1503,6 +1503,30 @@ impl CubeScanWrapperNode {
15031503 } )
15041504 }
15051505
1506+ fn remap_column_expression (
1507+ schema : & DFSchema ,
1508+ original_expr : & Expr ,
1509+ column_remapping : Option < & ColumnRemapping > ,
1510+ next_remapper : & mut Remapper ,
1511+ can_rename_columns : bool ,
1512+ ) -> result:: Result < ( Expr , String ) , CubeError > {
1513+ let expr = if let Some ( column_remapping) = column_remapping {
1514+ let mut expr = column_remapping. remap ( original_expr) ?;
1515+ if !can_rename_columns {
1516+ let original_alias = expr_name ( original_expr, & schema) ?;
1517+ if original_alias != expr_name ( & expr, & schema) ? {
1518+ expr = Expr :: Alias ( Box :: new ( expr) , original_alias. clone ( ) ) ;
1519+ }
1520+ }
1521+ expr
1522+ } else {
1523+ original_expr. clone ( )
1524+ } ;
1525+ let alias = next_remapper. add_expr ( & schema, original_expr, & expr) ?;
1526+
1527+ Ok ( ( expr, alias) )
1528+ }
1529+
15061530 async fn generate_column_expr (
15071531 schema : DFSchemaRef ,
15081532 exprs : impl IntoIterator < Item = Expr > ,
@@ -1516,18 +1540,14 @@ impl CubeScanWrapperNode {
15161540 ) -> result:: Result < ( Vec < AliasedColumn > , SqlQuery ) , CubeError > {
15171541 let mut aliased_columns = Vec :: new ( ) ;
15181542 for original_expr in exprs {
1519- let expr = if let Some ( column_remapping) = column_remapping {
1520- let mut expr = column_remapping. remap ( & original_expr) ?;
1521- if !can_rename_columns {
1522- let original_alias = expr_name ( & original_expr, & schema) ?;
1523- if original_alias != expr_name ( & expr, & schema) ? {
1524- expr = Expr :: Alias ( Box :: new ( expr) , original_alias. clone ( ) ) ;
1525- }
1526- }
1527- expr
1528- } else {
1529- original_expr. clone ( )
1530- } ;
1543+ let ( expr, alias) = Self :: remap_column_expression (
1544+ schema. as_ref ( ) ,
1545+ & original_expr,
1546+ column_remapping,
1547+ next_remapper,
1548+ can_rename_columns,
1549+ ) ?;
1550+
15311551 let ( expr_sql, new_sql_query) = Self :: generate_sql_for_expr (
15321552 sql,
15331553 generator. clone ( ) ,
@@ -1540,7 +1560,6 @@ impl CubeScanWrapperNode {
15401560 Self :: escape_interpolation_quotes ( expr_sql, push_to_cube_context. is_some ( ) ) ;
15411561 sql = new_sql_query;
15421562
1543- let alias = next_remapper. add_expr ( & schema, & original_expr, & expr) ?;
15441563 aliased_columns. push ( AliasedColumn {
15451564 expr : expr_sql,
15461565 alias,
0 commit comments