@@ -1264,6 +1264,8 @@ impl CubeScanWrapperNode {
12641264 subqueries_sql. clone ( ) ,
12651265 )
12661266 . await ?;
1267+
1268+ let join_condition_members = & join_condition[ 0 ] . 1 ;
12671269 let join_condition = join_condition[ 0 ] . 0 . expr . clone ( ) ;
12681270 sql = new_sql;
12691271
@@ -1275,6 +1277,7 @@ impl CubeScanWrapperNode {
12751277 expr : join_condition,
12761278 alias : "__join__alias__unused" . to_string ( ) ,
12771279 } ,
1280+ join_condition_members,
12781281 & ungrouped_scan_node. used_cubes ,
12791282 ) ?;
12801283 serde_json:: json!( res) . to_string ( )
@@ -1310,24 +1313,27 @@ impl CubeScanWrapperNode {
13101313 measures : Some (
13111314 aggregate
13121315 . iter ( )
1313- . map ( |( m, _used_members ) | {
1316+ . map ( |( m, used_members ) | {
13141317 Self :: ungrouped_member_def (
13151318 m,
1319+ used_members,
13161320 & ungrouped_scan_node. used_cubes ,
13171321 )
13181322 } )
13191323 . chain (
13201324 // TODO understand type of projections
1321- projection. iter ( ) . map ( |( m, _used_members ) | {
1325+ projection. iter ( ) . map ( |( m, used_members ) | {
13221326 Self :: ungrouped_member_def (
13231327 m,
1328+ used_members,
13241329 & ungrouped_scan_node. used_cubes ,
13251330 )
13261331 } ) ,
13271332 )
1328- . chain ( window. iter ( ) . map ( |( m, _used_members ) | {
1333+ . chain ( window. iter ( ) . map ( |( m, used_members ) | {
13291334 Self :: ungrouped_member_def (
13301335 m,
1336+ used_members,
13311337 & ungrouped_scan_node. used_cubes ,
13321338 )
13331339 } ) )
@@ -1337,9 +1343,10 @@ impl CubeScanWrapperNode {
13371343 group_by
13381344 . iter ( )
13391345 . zip ( group_descs. iter ( ) )
1340- . map ( |( ( m, _used_members ) , t) | {
1346+ . map ( |( ( m, used_members ) , t) | {
13411347 Self :: dimension_member_def (
13421348 m,
1349+ used_members,
13431350 & ungrouped_scan_node. used_cubes ,
13441351 t,
13451352 )
@@ -1349,9 +1356,10 @@ impl CubeScanWrapperNode {
13491356 segments : Some (
13501357 filter
13511358 . iter ( )
1352- . map ( |( m, _used_members ) | {
1359+ . map ( |( m, used_members ) | {
13531360 Self :: ungrouped_member_def (
13541361 m,
1362+ used_members,
13551363 & ungrouped_scan_node. used_cubes ,
13561364 )
13571365 } )
@@ -1592,40 +1600,55 @@ impl CubeScanWrapperNode {
15921600 Ok ( ( aliased_columns, sql) )
15931601 }
15941602
1595- fn make_member_def (
1603+ fn make_member_def < ' m > (
15961604 column : & AliasedColumn ,
1597- used_cubes : & Vec < String > ,
1605+ used_members : impl IntoIterator < Item = & ' m String > ,
1606+ ungrouped_scan_cubes : & Vec < String > ,
15981607 ) -> Result < UngrouppedMemberDef > {
1608+ let used_cubes = used_members
1609+ . into_iter ( )
1610+ . flat_map ( |member| member. split_once ( '.' ) )
1611+ . map ( |( cube, _rest) | cube)
1612+ . unique ( )
1613+ . map ( |cube| cube. to_string ( ) )
1614+ . collect :: < Vec < _ > > ( ) ;
1615+ let cube_name = used_cubes
1616+ . first ( )
1617+ . or_else ( || ungrouped_scan_cubes. first ( ) )
1618+ . ok_or_else ( || {
1619+ DataFusionError :: Internal ( format ! (
1620+ "Can't generate SQL for column without cubes: {:?}" ,
1621+ column
1622+ ) )
1623+ } ) ?
1624+ . clone ( ) ;
1625+
15991626 let res = UngrouppedMemberDef {
1600- cube_name : used_cubes
1601- . iter ( )
1602- . next ( )
1603- . ok_or_else ( || {
1604- DataFusionError :: Internal ( format ! (
1605- "Can't generate SQL for column without cubes: {:?}" ,
1606- column
1607- ) )
1608- } ) ?
1609- . to_string ( ) ,
1627+ cube_name,
16101628 alias : column. alias . clone ( ) ,
1611- cube_params : used_cubes. clone ( ) ,
1629+ cube_params : used_cubes,
16121630 expr : column. expr . clone ( ) ,
16131631 grouping_set : None ,
16141632 } ;
16151633 Ok ( res)
16161634 }
16171635
1618- fn ungrouped_member_def ( column : & AliasedColumn , used_cubes : & Vec < String > ) -> Result < String > {
1619- let res = Self :: make_member_def ( column, used_cubes) ?;
1636+ fn ungrouped_member_def < ' m > (
1637+ column : & AliasedColumn ,
1638+ used_members : impl IntoIterator < Item = & ' m String > ,
1639+ ungrouped_scan_cubes : & Vec < String > ,
1640+ ) -> Result < String > {
1641+ let res = Self :: make_member_def ( column, used_members, ungrouped_scan_cubes) ?;
16201642 Ok ( serde_json:: json!( res) . to_string ( ) )
16211643 }
16221644
1623- fn dimension_member_def (
1645+ fn dimension_member_def < ' m > (
16241646 column : & AliasedColumn ,
1625- used_cubes : & Vec < String > ,
1647+ used_members : impl IntoIterator < Item = & ' m String > ,
1648+ ungrouped_scan_cubes : & Vec < String > ,
16261649 grouping_type : & Option < GroupingSetDesc > ,
16271650 ) -> Result < String > {
1628- let mut res = Self :: make_member_def ( column, used_cubes ) ?;
1651+ let mut res = Self :: make_member_def ( column, used_members , ungrouped_scan_cubes ) ?;
16291652 res. grouping_set = grouping_type. clone ( ) ;
16301653 Ok ( serde_json:: json!( res) . to_string ( ) )
16311654 }
0 commit comments