@@ -223,7 +223,11 @@ export class BaseQuery {
223223 /** @type {import('./BaseTimeDimension').BaseTimeDimension[] } */
224224 this . timeDimensions = ( this . options . timeDimensions || [ ] ) . map ( dimension => {
225225 if ( ! dimension . dimension ) {
226- const join = this . joinGraph . buildJoin ( this . collectJoinHints ( true ) ) ;
226+ const { joinHints, joinAliases } = this . collectJoinHints ( true ) ;
227+
228+ // TODO: Use joinAliases for join hints building
229+
230+ const join = this . joinGraph . buildJoin ( joinHints ) ;
227231 if ( ! join ) {
228232 return undefined ;
229233 }
@@ -440,9 +444,16 @@ export class BaseQuery {
440444 */
441445 get allJoinHints ( ) {
442446 if ( ! this . collectedJoinHints ) {
443- const [ rootOfJoin , ...allMembersJoinHints ] = this . collectJoinHintsFromMembers ( this . allMembersConcat ( false ) ) ;
444- const customSubQueryJoinHints = this . collectJoinHintsFromMembers ( this . joinMembersFromCustomSubQuery ( ) ) ;
445- let joinMembersJoinHints = this . collectJoinHintsFromMembers ( this . joinMembersFromJoin ( this . join ) ) ;
447+ let { joinHints, joinAliases } = this . collectJoinHintsFromMembers ( this . allMembersConcat ( false ) ) ;
448+ const [ rootOfJoin , ...allMembersJoinHints ] = joinHints ;
449+
450+ ( { joinHints, joinAliases } = this . collectJoinHintsFromMembers ( this . joinMembersFromCustomSubQuery ( ) ) ) ;
451+ const customSubQueryJoinHints = joinHints ;
452+
453+ ( { joinHints, joinAliases } = this . collectJoinHintsFromMembers ( this . joinMembersFromJoin ( this . join ) ) ) ;
454+ let joinMembersJoinHints = joinHints ;
455+
456+ // TODO: Use joinAliases for join hints building
446457
447458 // One cube may join the other cube via transitive joined cubes,
448459 // members from which are referenced in the join `on` clauses.
@@ -501,7 +512,12 @@ export class BaseQuery {
501512
502513 while ( newJoin ?. joins . length > 0 && ! isJoinTreesEqual ( prevJoins , newJoin ) && cnt < 10000 ) {
503514 prevJoins = newJoin ;
504- joinMembersJoinHints = this . collectJoinHintsFromMembers ( this . joinMembersFromJoin ( newJoin ) ) ;
515+
516+ ( { joinHints, joinAliases } = this . collectJoinHintsFromMembers ( this . joinMembersFromJoin ( newJoin ) ) ) ;
517+ joinMembersJoinHints = joinHints ;
518+
519+ // TODO: Use joinAliases for join hints building
520+
505521 if ( ! isOrderPreserved ( prevJoinMembersJoinHints , joinMembersJoinHints ) ) {
506522 throw new UserError ( `Can not construct joins for the query, potential loop detected: ${ prevJoinMembersJoinHints . join ( '->' ) } vs ${ joinMembersJoinHints . join ( '->' ) } ` ) ;
507523 }
@@ -2392,7 +2408,8 @@ export class BaseQuery {
23922408 ) ;
23932409
23942410 if ( shouldBuildJoinForMeasureSelect ) {
2395- const joinHints = this . collectJoinHintsFromMembers ( measures ) ;
2411+ const { joinHints, joinAliases } = this . collectJoinHintsFromMembers ( measures ) ;
2412+ // TODO: Use joinAliases for join hints building
23962413 const measuresJoin = this . joinGraph . buildJoin ( joinHints ) ;
23972414 if ( measuresJoin . multiplicationFactor [ keyCubeName ] ) {
23982415 throw new UserError (
@@ -2473,10 +2490,14 @@ export class BaseQuery {
24732490
24742491 const cubes = this . collectFrom ( nonViewMembers , this . collectCubeNamesFor . bind ( this ) , 'collectCubeNamesFor' ) ;
24752492 // Not using `collectJoinHintsFromMembers([measure])` because it would collect too many join hints from view
2493+ const { joinHints : collectedJoinHints , joinAliases } = this . collectJoinHintsFromMembers ( nonViewMembers ) ;
24762494 const joinHints = [
24772495 measure . joinHint ,
2478- ...this . collectJoinHintsFromMembers ( nonViewMembers ) ,
2496+ ...collectedJoinHints ,
24792497 ] ;
2498+
2499+ // TODO: Use joinAliases for join hints building
2500+
24802501 if ( R . any ( cubeName => keyCubeName !== cubeName , cubes ) ) {
24812502 const measuresJoin = this . joinGraph . buildJoin ( joinHints ) ;
24822503 if ( measuresJoin . multiplicationFactor [ keyCubeName ] ) {
@@ -2657,10 +2678,23 @@ export class BaseQuery {
26572678 }
26582679
26592680 collectJoinHintsFromMembers ( members ) {
2660- return [
2661- ...members . map ( m => m . joinHint ) . filter ( h => h ?. length > 0 ) ,
2662- ...this . collectFrom ( members , this . collectJoinHintsFor . bind ( this ) , 'collectJoinHintsFromMembers' ) ,
2663- ] ;
2681+ const {
2682+ joinHints : collectedJoinHints ,
2683+ joinAliases : collectedJoinAliases ,
2684+ } = this . collectFrom ( members , this . collectJoinHintsFor . bind ( this ) , 'collectJoinHintsFromMembers' )
2685+ . reduce ( ( acc , { joinHints, joinAliases } ) => {
2686+ joinHints . forEach ( item => acc . joinHints . add ( item ) ) ;
2687+ acc . joinAliases . push ( ...joinAliases ) ;
2688+ return acc ;
2689+ } , { joinHints : new Set ( ) , joinAliases : [ ] } ) ;
2690+
2691+ return {
2692+ joinHints : [
2693+ ...members . map ( m => m . joinHint ) . filter ( h => h ?. length > 0 ) ,
2694+ ...Array . from ( collectedJoinHints ) ,
2695+ ] ,
2696+ joinAliases : collectedJoinAliases ,
2697+ } ;
26642698 }
26652699
26662700 /**
@@ -3385,12 +3419,15 @@ export class BaseQuery {
33853419 }
33863420
33873421 collectJoinHintsFor ( fn ) {
3388- const context = { joinHints : [ ] } ;
3422+ const context = { joinHints : [ ] , joinAliases : [ ] } ;
33893423 this . evaluateSymbolSqlWithContext (
33903424 fn ,
33913425 context
33923426 ) ;
3393- return context . joinHints ;
3427+ return {
3428+ joinHints : context . joinHints ,
3429+ joinAliases : context . joinAliases ,
3430+ } ;
33943431 }
33953432
33963433 /**
0 commit comments