Skip to content

Commit 2edcd0d

Browse files
committed
feat(cubesql): Lift used members through generate_column_expr
1 parent c1e0cb7 commit 2edcd0d

File tree

1 file changed

+22
-18
lines changed
  • rust/cubesql/cubesql/src/compile/engine/df

1 file changed

+22
-18
lines changed

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ impl CubeScanWrapperNode {
12641264
subqueries_sql.clone(),
12651265
)
12661266
.await?;
1267-
let join_condition = join_condition[0].expr.clone();
1267+
let join_condition = join_condition[0].0.expr.clone();
12681268
sql = new_sql;
12691269

12701270
let join_sql_expression = {
@@ -1310,22 +1310,22 @@ impl CubeScanWrapperNode {
13101310
measures: Some(
13111311
aggregate
13121312
.iter()
1313-
.map(|m| {
1313+
.map(|(m, _used_members)| {
13141314
Self::ungrouped_member_def(
13151315
m,
13161316
&ungrouped_scan_node.used_cubes,
13171317
)
13181318
})
13191319
.chain(
13201320
// TODO understand type of projections
1321-
projection.iter().map(|m| {
1321+
projection.iter().map(|(m, _used_members)| {
13221322
Self::ungrouped_member_def(
13231323
m,
13241324
&ungrouped_scan_node.used_cubes,
13251325
)
13261326
}),
13271327
)
1328-
.chain(window.iter().map(|m| {
1328+
.chain(window.iter().map(|(m, _used_members)| {
13291329
Self::ungrouped_member_def(
13301330
m,
13311331
&ungrouped_scan_node.used_cubes,
@@ -1337,7 +1337,7 @@ impl CubeScanWrapperNode {
13371337
group_by
13381338
.iter()
13391339
.zip(group_descs.iter())
1340-
.map(|(m, t)| {
1340+
.map(|((m, _used_members), t)| {
13411341
Self::dimension_member_def(
13421342
m,
13431343
&ungrouped_scan_node.used_cubes,
@@ -1349,7 +1349,7 @@ impl CubeScanWrapperNode {
13491349
segments: Some(
13501350
filter
13511351
.iter()
1352-
.map(|m| {
1352+
.map(|(m, _used_members)| {
13531353
Self::ungrouped_member_def(
13541354
m,
13551355
&ungrouped_scan_node.used_cubes,
@@ -1399,7 +1399,7 @@ impl CubeScanWrapperNode {
13991399
))
14001400
})?;
14011401
Ok(vec![
1402-
aliased_column.alias.clone(),
1402+
aliased_column.0.alias.clone(),
14031403
if *asc { "asc".to_string() } else { "desc".to_string() },
14041404
])
14051405
}
@@ -1470,24 +1470,24 @@ impl CubeScanWrapperNode {
14701470
.get_sql_templates()
14711471
.select(
14721472
sql.sql.to_string(),
1473-
projection,
1474-
group_by,
1473+
projection.into_iter().map(|(m, _)| m).collect(),
1474+
group_by.into_iter().map(|(m, _)| m).collect(),
14751475
group_descs,
1476-
aggregate,
1476+
aggregate.into_iter().map(|(m, _)| m).collect(),
14771477
// TODO
14781478
from_alias.unwrap_or("".to_string()),
14791479
if !filter.is_empty() {
14801480
Some(
14811481
filter
14821482
.iter()
1483-
.map(|f| f.expr.to_string())
1483+
.map(|(f, _)| f.expr.to_string())
14841484
.join(" AND "),
14851485
)
14861486
} else {
14871487
None
14881488
},
14891489
None,
1490-
order,
1490+
order.into_iter().map(|(m, _)| m).collect(),
14911491
limit,
14921492
offset,
14931493
distinct,
@@ -1549,7 +1549,7 @@ impl CubeScanWrapperNode {
15491549
can_rename_columns: bool,
15501550
push_to_cube_context: Option<&PushToCubeContext<'_>>,
15511551
subqueries: Arc<HashMap<String, String>>,
1552-
) -> result::Result<(Vec<AliasedColumn>, SqlQuery), CubeError> {
1552+
) -> result::Result<(Vec<(AliasedColumn, HashSet<String>)>, SqlQuery), CubeError> {
15531553
let mut aliased_columns = Vec::new();
15541554
for original_expr in exprs {
15551555
let expr = if let Some(column_remapping) = column_remapping {
@@ -1565,25 +1565,29 @@ impl CubeScanWrapperNode {
15651565
original_expr.clone()
15661566
};
15671567

1568+
let mut used_members = HashSet::new();
15681569
let (expr_sql, new_sql_query) = Self::generate_sql_for_expr(
15691570
plan.clone(),
15701571
sql,
15711572
generator.clone(),
15721573
expr.clone(),
15731574
push_to_cube_context,
15741575
subqueries.clone(),
1575-
None,
1576+
Some(&mut used_members),
15761577
)
15771578
.await?;
15781579
let expr_sql =
15791580
Self::escape_interpolation_quotes(expr_sql, push_to_cube_context.is_some());
15801581
sql = new_sql_query;
15811582

15821583
let alias = next_remapper.add_expr(&schema, &original_expr, &expr)?;
1583-
aliased_columns.push(AliasedColumn {
1584-
expr: expr_sql,
1585-
alias,
1586-
});
1584+
aliased_columns.push((
1585+
AliasedColumn {
1586+
expr: expr_sql,
1587+
alias,
1588+
},
1589+
used_members,
1590+
));
15871591
}
15881592
Ok((aliased_columns, sql))
15891593
}

0 commit comments

Comments
 (0)