Skip to content

Commit 1e6264f

Browse files
committed
refactor(cubesql): Simplify order_expr handling in push-to-Cube case
1 parent a1e3c5f commit 1e6264f

File tree

1 file changed

+20
-31
lines changed
  • rust/cubesql/cubesql/src/compile/engine/df

1 file changed

+20
-31
lines changed

rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,38 +1333,27 @@ impl CubeScanWrapperNode {
13331333
..
13341334
} => {
13351335
let col_name = expr_name(&expr, &schema)?;
1336-
let aliased_column = aggr_expr
1337-
.iter()
1338-
.find_position(|e| {
1339-
expr_name(e, &schema).map(|n| &n == &col_name).unwrap_or(false)
1340-
})
1341-
.map(|(i, _)| aggregate[i].clone()).or_else(|| {
1342-
projection_expr
1343-
.iter()
1344-
.find_position(|e| {
1345-
expr_name(e, &schema).map(|n| &n == &col_name).unwrap_or(false)
1346-
})
1347-
.map(|(i, _)| {
1348-
projection[i].clone()
1349-
})
1350-
}).or_else(|| {
1351-
flat_group_expr
1352-
.iter()
1353-
.find_position(|e| {
1354-
expr_name(e, &schema).map(|n| &n == &col_name).unwrap_or(false)
1355-
})
1356-
.map(|(i, _)| group_by[i].clone())
1357-
}).ok_or_else(|| {
1358-
DataFusionError::Execution(format!(
1359-
"Can't find column {} in projection {:?} or aggregate {:?} or group {:?}",
1360-
col_name,
1361-
projection_expr,
1362-
aggr_expr,
1363-
flat_group_expr
1364-
))
1365-
})?;
1336+
1337+
let find_column = |exprs: &[Expr], columns: &[AliasedColumn]| -> Option<AliasedColumn> {
1338+
exprs.into_iter().zip(columns.into_iter())
1339+
.find(|(e, _c)| expr_name(e, &schema).map(|n| &n == &col_name).unwrap_or(false))
1340+
.map(|(_e, c)| c.clone())
1341+
};
1342+
1343+
let aliased_column = find_column(&aggr_expr, &aggregate)
1344+
.or_else(|| find_column(&projection_expr, &projection))
1345+
.or_else(|| find_column(&flat_group_expr, &group_by))
1346+
.ok_or_else(|| {
1347+
DataFusionError::Execution(format!(
1348+
"Can't find column {} in projection {:?} or aggregate {:?} or group {:?}",
1349+
col_name,
1350+
projection_expr,
1351+
aggr_expr,
1352+
flat_group_expr
1353+
))
1354+
})?;
13661355
Ok(vec![
1367-
aliased_column.alias.clone(),
1356+
aliased_column.alias,
13681357
if *asc { "asc".to_string() } else { "desc".to_string() },
13691358
])
13701359
}

0 commit comments

Comments
 (0)