@@ -19,42 +19,29 @@ class PreAggregations {
19
19
}
20
20
21
21
preAggregationsDescriptionLocal ( ) {
22
- const preAggregationForQuery = this . findPreAggregationForQuery ( ) ;
23
- if ( preAggregationForQuery ) {
24
- if ( preAggregationForQuery . preAggregation . useOriginalSqlPreAggregations ) {
25
- const { preAggregations, result } =
26
- this . collectOriginalSqlPreAggregations (
27
- ( ) => this . preAggregationDescriptionsFor ( preAggregationForQuery . cube , preAggregationForQuery )
28
- ) ;
29
-
30
- const queryForEval = this . query . preAggregationQueryForSqlEvaluation (
31
- preAggregationForQuery . cube ,
32
- preAggregationForQuery . preAggregation
33
- ) ;
34
-
35
- // TODO consider recursive pre-aggregation descriptions instead of duplication of sub query logic
36
- return R . unnest ( preAggregations . map (
37
- p => this . preAggregationDescriptionsFor ( p . cube , p ) . concat (
38
- R . unnest (
39
- queryForEval . subQueryDimensions . map ( d => queryForEval . subQueryDescription ( d ) . subQuery )
40
- . map ( q => q . preAggregations . preAggregationDescriptionsFor ( p . cube , p ) )
41
- )
42
- )
43
- ) ) . concat ( result ) ;
22
+ const isInPreAggregationQuery = this . query . options . preAggregationQuery ;
23
+ if ( ! isInPreAggregationQuery ) {
24
+ const preAggregationForQuery = this . findPreAggregationForQuery ( ) ;
25
+ if ( preAggregationForQuery ) {
26
+ return this . preAggregationDescriptionsFor ( preAggregationForQuery . cube , preAggregationForQuery ) ;
44
27
}
45
- return this . preAggregationDescriptionsFor ( preAggregationForQuery . cube , preAggregationForQuery ) ;
46
28
}
47
- return R . pipe (
48
- R . map ( cube => {
49
- const foundPreAggregation = this . findPreAggregationToUseForCube ( cube ) ;
50
- if ( foundPreAggregation ) {
51
- return this . preAggregationDescriptionsFor ( cube , foundPreAggregation ) ;
52
- }
53
- return null ;
54
- } ) ,
55
- R . filter ( R . identity ) ,
56
- R . unnest
57
- ) ( this . preAggregationCubes ( ) ) ;
29
+ if (
30
+ ! isInPreAggregationQuery ||
31
+ isInPreAggregationQuery && this . query . options . useOriginalSqlPreAggregationsInPreAggregation ) {
32
+ return R . pipe (
33
+ R . map ( cube => {
34
+ const foundPreAggregation = this . findPreAggregationToUseForCube ( cube ) ;
35
+ if ( foundPreAggregation ) {
36
+ return this . preAggregationDescriptionsFor ( cube , foundPreAggregation ) ;
37
+ }
38
+ return null ;
39
+ } ) ,
40
+ R . filter ( R . identity ) ,
41
+ R . unnest
42
+ ) ( this . preAggregationCubes ( ) ) ;
43
+ }
44
+ return [ ] ;
58
45
}
59
46
60
47
preAggregationCubes ( ) {
@@ -65,13 +52,13 @@ class PreAggregations {
65
52
preAggregationDescriptionsFor ( cube , foundPreAggregation ) {
66
53
if ( this . canPartitionsBeUsed ( foundPreAggregation ) ) {
67
54
const { dimension, partitionDimension } = this . partitionDimension ( foundPreAggregation ) ;
68
- return partitionDimension . timeSeries ( ) . map (
69
- range => this . preAggregationDescriptionFor (
55
+ return R . unnest ( partitionDimension . timeSeries ( ) . map (
56
+ range => this . preAggregationDescriptionsForRecursive (
70
57
cube , this . addPartitionRangeTo ( foundPreAggregation , dimension , range )
71
58
)
72
- ) ;
59
+ ) ) ;
73
60
}
74
- return [ this . preAggregationDescriptionFor ( cube , foundPreAggregation ) ] ;
61
+ return this . preAggregationDescriptionsForRecursive ( cube , foundPreAggregation ) ;
75
62
}
76
63
77
64
canPartitionsBeUsed ( foundPreAggregation ) {
@@ -103,6 +90,12 @@ class PreAggregations {
103
90
return { dimension, partitionDimension } ;
104
91
}
105
92
93
+ preAggregationDescriptionsForRecursive ( cube , foundPreAggregation ) {
94
+ const query = this . query . preAggregationQueryForSqlEvaluation ( cube , foundPreAggregation . preAggregation ) ;
95
+ const descriptions = query !== this . query ? query . preAggregations . preAggregationsDescription ( ) : [ ] ;
96
+ return descriptions . concat ( this . preAggregationDescriptionFor ( cube , foundPreAggregation ) ) ;
97
+ }
98
+
106
99
preAggregationDescriptionFor ( cube , foundPreAggregation ) {
107
100
const { preAggregationName, preAggregation } = foundPreAggregation ;
108
101
const tableName = this . preAggregationTableName ( cube , preAggregationName , preAggregation ) ;
0 commit comments