@@ -223,7 +223,11 @@ export class BaseQuery {
223
223
/** @type {import('./BaseTimeDimension').BaseTimeDimension[] } */
224
224
this . timeDimensions = ( this . options . timeDimensions || [ ] ) . map ( dimension => {
225
225
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 ) ;
227
231
if ( ! join ) {
228
232
return undefined ;
229
233
}
@@ -440,9 +444,16 @@ export class BaseQuery {
440
444
*/
441
445
get allJoinHints ( ) {
442
446
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
446
457
447
458
// One cube may join the other cube via transitive joined cubes,
448
459
// members from which are referenced in the join `on` clauses.
@@ -501,7 +512,12 @@ export class BaseQuery {
501
512
502
513
while ( newJoin ?. joins . length > 0 && ! isJoinTreesEqual ( prevJoins , newJoin ) && cnt < 10000 ) {
503
514
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
+
505
521
if ( ! isOrderPreserved ( prevJoinMembersJoinHints , joinMembersJoinHints ) ) {
506
522
throw new UserError ( `Can not construct joins for the query, potential loop detected: ${ prevJoinMembersJoinHints . join ( '->' ) } vs ${ joinMembersJoinHints . join ( '->' ) } ` ) ;
507
523
}
@@ -2392,7 +2408,8 @@ export class BaseQuery {
2392
2408
) ;
2393
2409
2394
2410
if ( shouldBuildJoinForMeasureSelect ) {
2395
- const joinHints = this . collectJoinHintsFromMembers ( measures ) ;
2411
+ const { joinHints, joinAliases } = this . collectJoinHintsFromMembers ( measures ) ;
2412
+ // TODO: Use joinAliases for join hints building
2396
2413
const measuresJoin = this . joinGraph . buildJoin ( joinHints ) ;
2397
2414
if ( measuresJoin . multiplicationFactor [ keyCubeName ] ) {
2398
2415
throw new UserError (
@@ -2473,10 +2490,14 @@ export class BaseQuery {
2473
2490
2474
2491
const cubes = this . collectFrom ( nonViewMembers , this . collectCubeNamesFor . bind ( this ) , 'collectCubeNamesFor' ) ;
2475
2492
// Not using `collectJoinHintsFromMembers([measure])` because it would collect too many join hints from view
2493
+ const { joinHints : collectedJoinHints , joinAliases } = this . collectJoinHintsFromMembers ( nonViewMembers ) ;
2476
2494
const joinHints = [
2477
2495
measure . joinHint ,
2478
- ...this . collectJoinHintsFromMembers ( nonViewMembers ) ,
2496
+ ...collectedJoinHints ,
2479
2497
] ;
2498
+
2499
+ // TODO: Use joinAliases for join hints building
2500
+
2480
2501
if ( R . any ( cubeName => keyCubeName !== cubeName , cubes ) ) {
2481
2502
const measuresJoin = this . joinGraph . buildJoin ( joinHints ) ;
2482
2503
if ( measuresJoin . multiplicationFactor [ keyCubeName ] ) {
@@ -2657,10 +2678,23 @@ export class BaseQuery {
2657
2678
}
2658
2679
2659
2680
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
+ } ;
2664
2698
}
2665
2699
2666
2700
/**
@@ -3385,12 +3419,15 @@ export class BaseQuery {
3385
3419
}
3386
3420
3387
3421
collectJoinHintsFor ( fn ) {
3388
- const context = { joinHints : [ ] } ;
3422
+ const context = { joinHints : [ ] , joinAliases : [ ] } ;
3389
3423
this . evaluateSymbolSqlWithContext (
3390
3424
fn ,
3391
3425
context
3392
3426
) ;
3393
- return context . joinHints ;
3427
+ return {
3428
+ joinHints : context . joinHints ,
3429
+ joinAliases : context . joinAliases ,
3430
+ } ;
3394
3431
}
3395
3432
3396
3433
/**
0 commit comments