@@ -19,42 +19,29 @@ class PreAggregations {
1919 }
2020
2121 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 ) ;
4427 }
45- return this . preAggregationDescriptionsFor ( preAggregationForQuery . cube , preAggregationForQuery ) ;
4628 }
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 [ ] ;
5845 }
5946
6047 preAggregationCubes ( ) {
@@ -65,13 +52,13 @@ class PreAggregations {
6552 preAggregationDescriptionsFor ( cube , foundPreAggregation ) {
6653 if ( this . canPartitionsBeUsed ( foundPreAggregation ) ) {
6754 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 (
7057 cube , this . addPartitionRangeTo ( foundPreAggregation , dimension , range )
7158 )
72- ) ;
59+ ) ) ;
7360 }
74- return [ this . preAggregationDescriptionFor ( cube , foundPreAggregation ) ] ;
61+ return this . preAggregationDescriptionsForRecursive ( cube , foundPreAggregation ) ;
7562 }
7663
7764 canPartitionsBeUsed ( foundPreAggregation ) {
@@ -103,6 +90,12 @@ class PreAggregations {
10390 return { dimension, partitionDimension } ;
10491 }
10592
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+
10699 preAggregationDescriptionFor ( cube , foundPreAggregation ) {
107100 const { preAggregationName, preAggregation } = foundPreAggregation ;
108101 const tableName = this . preAggregationTableName ( cube , preAggregationName , preAggregation ) ;
0 commit comments