Skip to content

Commit e4982ae

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

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
@@ -1404,38 +1404,27 @@ impl CubeScanWrapperNode {
14041404
..
14051405
} => {
14061406
let col_name = expr_name(&expr, &schema)?;
1407-
let aliased_column = aggr_expr
1408-
.iter()
1409-
.find_position(|e| {
1410-
expr_name(e, &schema).map(|n| n == col_name).unwrap_or(false)
1411-
})
1412-
.map(|(i, _)| aggregate[i].clone()).or_else(|| {
1413-
projection_expr
1414-
.iter()
1415-
.find_position(|e| {
1416-
expr_name(e, &schema).map(|n| n == col_name).unwrap_or(false)
1417-
})
1418-
.map(|(i, _)| {
1419-
projection[i].clone()
1420-
})
1421-
}).or_else(|| {
1422-
flat_group_expr
1423-
.iter()
1424-
.find_position(|e| {
1425-
expr_name(e, &schema).map(|n| n == col_name).unwrap_or(false)
1426-
})
1427-
.map(|(i, _)| group_by[i].clone())
1428-
}).ok_or_else(|| {
1429-
DataFusionError::Execution(format!(
1430-
"Can't find column {} in projection {:?} or aggregate {:?} or group {:?}",
1431-
col_name,
1432-
projection_expr,
1433-
aggr_expr,
1434-
flat_group_expr
1435-
))
1436-
})?;
1407+
1408+
let find_column = |exprs: &[Expr], columns: &[(AliasedColumn, HashSet<String>)]| -> Option<AliasedColumn> {
1409+
exprs.iter().zip(columns.iter())
1410+
.find(|(e, _c)| expr_name(e, &schema).map(|n| n == col_name).unwrap_or(false))
1411+
.map(|(_e, c)| c.0.clone())
1412+
};
1413+
1414+
let aliased_column = find_column(&aggr_expr, &aggregate)
1415+
.or_else(|| find_column(&projection_expr, &projection))
1416+
.or_else(|| find_column(&flat_group_expr, &group_by))
1417+
.ok_or_else(|| {
1418+
DataFusionError::Execution(format!(
1419+
"Can't find column {} in projection {:?} or aggregate {:?} or group {:?}",
1420+
col_name,
1421+
projection_expr,
1422+
aggr_expr,
1423+
flat_group_expr
1424+
))
1425+
})?;
14371426
Ok(vec![
1438-
aliased_column.0.alias.clone(),
1427+
aliased_column.alias,
14391428
if *asc { "asc".to_string() } else { "desc".to_string() },
14401429
])
14411430
}

0 commit comments

Comments
 (0)