11import R from 'ramda' ;
22
33import { CubeSymbols , PreAggregationDefinition } from '../compiler/CubeSymbols' ;
4+ import { FinishedJoinTree , JoinEdge } from '../compiler/JoinGraph' ;
45import { UserError } from '../compiler/UserError' ;
56import { BaseQuery } from './BaseQuery' ;
67import {
@@ -15,8 +16,6 @@ import { BaseGroupFilter } from './BaseGroupFilter';
1516import { BaseDimension } from './BaseDimension' ;
1617import { BaseSegment } from './BaseSegment' ;
1718
18- export type RollupJoin = any ;
19-
2019export type PartitionTimeDimension = {
2120 dimension : string ;
2221 dateRange : [ string , string ] ;
@@ -45,6 +44,7 @@ export type PreAggregationForQuery = {
4544 references : PreAggregationReferences ;
4645 preAggregationsToJoin ?: PreAggregationForQuery [ ] ;
4746 referencedPreAggregations ?: PreAggregationForQuery [ ] ;
47+ // eslint-disable-next-line no-use-before-define
4848 rollupJoin ?: RollupJoin ;
4949 sqlAlias ?: string ;
5050} ;
@@ -66,6 +66,18 @@ export type EvaluateReferencesContext = {
6666
6767export type BaseMember = BaseDimension | BaseMeasure | BaseFilter | BaseGroupFilter | BaseSegment ;
6868
69+ export type JoinEdgeWithMembers = JoinEdge & {
70+ fromMembers : string [ ] ;
71+ toMembers : string [ ] ;
72+ } ;
73+
74+ export type RollupJoinItem = JoinEdgeWithMembers & {
75+ fromPreAggObj : PreAggregationForQuery ;
76+ toPreAggObj : PreAggregationForQuery ;
77+ } ;
78+
79+ export type RollupJoin = RollupJoinItem [ ] ;
80+
6981export type CanUsePreAggregationFn = ( references : PreAggregationReferences ) => boolean ;
7082
7183/**
@@ -1050,7 +1062,7 @@ export class PreAggregations {
10501062 ) ;
10511063 const existingJoins = R . unnest ( preAggObjsToJoin . map (
10521064 // TODO join hints?
1053- p => this . resolveJoinMembers ( this . query . joinGraph . buildJoin ( this . cubesFromPreAggregation ( p ) ) )
1065+ p => this . resolveJoinMembers ( this . query . joinGraph . buildJoin ( this . cubesFromPreAggregation ( p ) ) ! )
10541066 ) ) ;
10551067 const nonExistingJoins = targetJoins . filter ( target => ! existingJoins . find (
10561068 existing => existing . originalFrom === target . originalFrom &&
@@ -1088,7 +1100,7 @@ export class PreAggregations {
10881100 return fromPreAggObj [ 0 ] ;
10891101 }
10901102
1091- private resolveJoinMembers ( join ) {
1103+ private resolveJoinMembers ( join : FinishedJoinTree ) : JoinEdgeWithMembers [ ] {
10921104 return join . joins . map ( j => {
10931105 const memberPaths = this . query . collectMemberNamesFor ( ( ) => this . query . evaluateSql ( j . originalFrom , j . join . sql ) ) . map ( m => m . split ( '.' ) ) ;
10941106 const invalidMembers = memberPaths . filter ( m => m [ 0 ] !== j . originalFrom && m [ 0 ] !== j . originalTo ) ;
@@ -1512,7 +1524,7 @@ export class PreAggregations {
15121524 } ) ;
15131525
15141526 if ( preAggregationForQuery . preAggregation . type === 'rollupJoin' ) {
1515- const join = preAggregationForQuery . rollupJoin ;
1527+ const join = preAggregationForQuery . rollupJoin ! ;
15161528
15171529 toJoin = [
15181530 sqlAndAlias ( join [ 0 ] . fromPreAggObj ) ,
0 commit comments