Skip to content

Commit 1856756

Browse files
committed
in work
1 parent a93a7cd commit 1856756

File tree

9 files changed

+248
-148
lines changed

9 files changed

+248
-148
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseDimension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class BaseDimension {
2828
const dimensionPath = dimension as string | null;
2929
if (dimensionPath !== null) {
3030
const { path, joinHint } = CubeSymbols.joinHintFromPath(dimensionPath);
31+
console.log("!!! dimension", dimensionPath, path, joinHint);
3132
this.dimension = path;
3233
this.joinHint = joinHint;
3334
}

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ export class BaseQuery {
637637
*/
638638
buildSqlAndParams(exportAnnotatedSql) {
639639
if (this.useNativeSqlPlanner) {
640-
let isRelatedToPreAggregation = false;
641-
/* if (this.options.preAggregationQuery) {
640+
const isRelatedToPreAggregation = false;
641+
/* if (this.options.preAggregationQuery) {
642642
isRelatedToPreAggregation = true;
643643
} else if (!this.options.disableExternalPreAggregations && this.externalQueryClass) {
644644
if (this.externalPreAggregationQuery()) {
@@ -659,9 +659,11 @@ export class BaseQuery {
659659
return this.newQueryWithoutNative().buildSqlAndParams(exportAnnotatedSql);
660660
} */
661661

662+
console.log("!!!!!! EEEEEEEEEE");
662663
return this.buildSqlAndParamsRust(exportAnnotatedSql);
663664
}
664665

666+
console.log("!!!!!! RRRRRRRRR");
665667
if (!this.options.preAggregationQuery && !this.options.disableExternalPreAggregations && this.externalQueryClass) {
666668
if (this.externalPreAggregationQuery()) { // TODO performance
667669
return this.externalQuery().buildSqlAndParams(exportAnnotatedSql);
@@ -726,17 +728,15 @@ export class BaseQuery {
726728
return res;
727729
}
728730

729-
//FIXME Temporary solution
731+
// FIXME Temporary solution
730732
findPreAggregationForQueryRust() {
731733
if (!this.preAggregations.preAggregationForQuery) {
732734
let optionsOrder = this.options.order;
733735
if (optionsOrder && !Array.isArray(optionsOrder)) {
734736
optionsOrder = [optionsOrder];
735737
}
736738
const order = optionsOrder ? R.pipe(
737-
R.map((hash) => {
738-
return ((!hash || !hash.id) ? null : hash);
739-
}),
739+
R.map((hash) => ((!hash || !hash.id) ? null : hash)),
740740
R.reject(R.isNil),
741741
)(optionsOrder) : undefined;
742742

@@ -769,7 +769,7 @@ export class BaseQuery {
769769
}
770770
}
771771

772-
const res = buildResult.result;
772+
const res = buildResult.result;
773773
if (res[2]) {
774774
this.preAggregations.preAggregationForQuery = res[2];
775775
}
@@ -973,7 +973,6 @@ export class BaseQuery {
973973
multiStageMembers,
974974
} = this.fullKeyQueryAggregateMeasures();
975975

976-
977976
if (!multipliedMeasures.length && !cumulativeMeasures.length && !multiStageMembers.length) {
978977
return this.simpleQuery();
979978
}
@@ -1211,7 +1210,6 @@ export class BaseQuery {
12111210

12121211
const multipliedMeasures = measuresToRender(true, false)(measureToHierarchy);
12131212
const regularMeasures = measuresToRender(false, false)(measureToHierarchy);
1214-
12151213
const cumulativeMeasures =
12161214
R.pipe(
12171215
R.map(multiplied => R.xprod([multiplied], measuresToRender(multiplied, true)(measureToHierarchy))),
@@ -1335,6 +1333,7 @@ export class BaseQuery {
13351333

13361334
childrenMultiStageContext(memberPath, queryContext, wouldNodeApplyFilters) {
13371335
let member;
1336+
console.log("!!!! children ", memberPath);
13381337
if (this.cubeEvaluator.isMeasure(memberPath)) {
13391338
member = this.newMeasure(memberPath);
13401339
} else if (this.cubeEvaluator.isDimension(memberPath)) {

packages/cubejs-schema-compiler/src/adapter/PreAggregations.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class PreAggregations {
2121
* @return {unknown[]}
2222
*/
2323
preAggregationsDescription() {
24+
return [];
2425
const preAggregations = [this.preAggregationsDescriptionLocal()].concat(
2526
this.query.subQueryDimensions.map(d => this.query.subQueryDescription(d).subQuery)
2627
.map(q => q.preAggregations.preAggregationsDescription())
@@ -311,8 +312,8 @@ export class PreAggregations {
311312
const dimensionsList = query.dimensions.map(dim => dim.expressionPath());
312313
const segmentsList = query.segments.map(s => s.expressionPath());
313314
const ownedDimensions = PreAggregations.ownedMembers(query, flattenDimensionMembers);
314-
console.log("!!! dimensions", dimensionsList);
315-
console.log("!!! ownedDimensions", ownedDimensions);
315+
console.log('!!! dimensions', dimensionsList);
316+
console.log('!!! ownedDimensions', ownedDimensions);
316317
const ownedTimeDimensions = query.timeDimensions.map(td => {
317318
const owned = PreAggregations.ownedMembers(query, [td]);
318319
let { dimension } = td;
@@ -833,6 +834,7 @@ export class PreAggregations {
833834
* @returns {Array<Object>}
834835
*/
835836
rollupMatchResults() {
837+
return [];
836838
const { query } = this;
837839

838840
const canUsePreAggregation = this.canUsePreAggregationFn(query);

packages/cubejs-schema-compiler/src/compiler/CubeEvaluator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ export class CubeEvaluator extends CubeSymbols {
669669

670670
const cubeAndName = Array.isArray(path) ? path : path.split('.');
671671
if (!this.evaluatedCubes[cubeAndName[0]]) {
672+
console.trace("!!!!");
672673
throw new UserError(`Cube '${cubeAndName[0]}' not found for path '${path}'`);
673674
}
674675

packages/cubejs-schema-compiler/test/integration/postgres/pre-aggregations-multi-stage.test.ts

Lines changed: 151 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,28 @@ describe('PreAggregationsMultiStage', () => {
4848
sql: 'id',
4949
type: 'countDistinctApprox'
5050
},
51-
revenue_per_id: {
51+
revenuePerId: {
5252
multi_stage: true,
5353
sql: \`\${revenue} / \${id}\`,
5454
type: 'sum',
5555
add_group_by: [visitors.id],
56-
},
56+
},
57+
58+
revenueAndTime: {
59+
multi_stage: true,
60+
sql: \`LENGTH(CONCAT(\${revenue}, ' - ', \${createdAtDay}))\`,
61+
type: 'sum',
62+
add_group_by: [createdAtDay],
63+
},
5764
5865
ratio: {
5966
sql: \`\${uniqueSourceCount} / nullif(\${checkinsTotal}, 0)\`,
6067
type: 'number'
68+
},
69+
70+
testMeas: {
71+
type: 'countDistinct',
72+
sql: \`\${createdAtDay}\`
6173
}
6274
},
6375
@@ -73,14 +85,31 @@ describe('PreAggregationsMultiStage', () => {
7385
},
7486
createdAt: {
7587
type: 'time',
76-
sql: 'created_at'
88+
sql: 'created_at',
89+
granularities: {
90+
three_days: {
91+
interval: '1 days',
92+
title: '1 days',
93+
origin: '2017-01-01'
94+
}
95+
}
7796
},
7897
checkinsCount: {
7998
type: 'number',
8099
sql: \`\${visitor_checkins.count}\`,
81100
subQuery: true,
82101
propagateFiltersToSubQuery: true
83102
},
103+
revTest: {
104+
sql: \`CONCAT(\${source}, \${createdAtDay})\`,
105+
type: 'string',
106+
},
107+
108+
createdAtDay: {
109+
type: 'time',
110+
sql: \`\${createdAt.three_days}\`,
111+
},
112+
84113
85114
86115
},
@@ -100,6 +129,14 @@ describe('PreAggregationsMultiStage', () => {
100129
granularity: 'day',
101130
partitionGranularity: 'month',
102131
},
132+
revenueAndTimeRollup: {
133+
type: 'rollup',
134+
measureReferences: [revenue],
135+
dimensionReferences: [source],
136+
timeDimensionReference: createdAt,
137+
granularity: 'day',
138+
partitionGranularity: 'month',
139+
},
103140
}
104141
})
105142
@@ -134,7 +171,7 @@ describe('PreAggregationsMultiStage', () => {
134171
},
135172
created_at: {
136173
type: 'time',
137-
sql: 'created_at'
174+
sql: 'created_at',
138175
}
139176
},
140177
@@ -143,56 +180,118 @@ describe('PreAggregationsMultiStage', () => {
143180
144181
`);
145182

183+
if (getEnv('nativeSqlPlanner')) {
184+
it('simple multi stage with add_group_by', () => compiler.compile().then(() => {
185+
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
186+
measures: [
187+
'visitors.revenuePerId'
188+
],
189+
timeDimensions: [{
190+
dimension: 'visitors.createdAt',
191+
granularity: 'day',
192+
dateRange: ['2017-01-01', '2017-01-30']
193+
}],
194+
timezone: 'America/Los_Angeles',
195+
order: [{
196+
id: 'visitors.createdAt'
197+
}],
198+
preAggregationsSchema: ''
199+
});
146200

147-
it('simple multi stage with add_group_by', () => compiler.compile().then(() => {
148-
if (!getEnv('nativeSqlPlanner')) {
149-
return;
150-
}
151-
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
152-
measures: [
153-
'visitors.revenue_per_id'
154-
],
155-
timeDimensions: [{
156-
dimension: 'visitors.createdAt',
157-
granularity: 'day',
158-
dateRange: ['2017-01-01', '2017-01-30']
159-
}],
160-
timezone: 'America/Los_Angeles',
161-
order: [{
162-
id: 'visitors.createdAt'
163-
}],
164-
preAggregationsSchema: ''
165-
});
166-
167-
const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription();
168-
const sqlAndParams = query.buildSqlAndParams();
169-
console.log("!!!! sqlAndParamsl", sqlAndParams);
170-
expect(preAggregationsDescription[0].tableName).toEqual('rvis_rollupalias');
171-
expect(sqlAndParams[0]).toContain('rvis_rollupalias');
172-
173-
return dbRunner.evaluateQueryWithPreAggregations(query).then(res => {
174-
console.log("!!!! res", res);
175-
expect(res).toEqual(
201+
const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription();
202+
const sqlAndParams = query.buildSqlAndParams();
203+
console.log('!!!! sqlAndParamsl', sqlAndParams);
204+
expect(preAggregationsDescription[0].tableName).toEqual('vis_revenue_per_id_rollup');
205+
expect(sqlAndParams[0]).toContain('vis_revenue_per_id_rollup');
206+
207+
return dbRunner.evaluateQueryWithPreAggregations(query).then(res => {
208+
expect(res).toEqual(
209+
[
210+
{
211+
vis__created_at_day: '2017-01-02T00:00:00.000Z',
212+
vis__revenue_per_id: '100.0000000000000000'
213+
},
214+
{
215+
vis__created_at_day: '2017-01-04T00:00:00.000Z',
216+
vis__revenue_per_id: '100.0000000000000000'
217+
},
218+
{
219+
vis__created_at_day: '2017-01-05T00:00:00.000Z',
220+
vis__revenue_per_id: '100.0000000000000000'
221+
},
222+
{
223+
vis__created_at_day: '2017-01-06T00:00:00.000Z',
224+
vis__revenue_per_id: '200.0000000000000000'
225+
}
226+
]
227+
228+
);
229+
});
230+
}));
231+
}
232+
233+
it('simple multi stage with add_group_by and time proxy dimension 11', () => compiler.compile().then(() => {
234+
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
235+
measures: [
236+
'visitors.revenueAndTime'
237+
],
238+
dimensions: ['visitors.source'],
239+
timezone: 'America/Los_Angeles',
240+
order: [{
241+
id: 'visitors.source'
242+
}],
243+
preAggregationsSchema: ''
244+
});
245+
246+
const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription();
247+
const sqlAndParams = query.buildSqlAndParams();
248+
console.log('!!!! sqlAndParamsl', sqlAndParams);
249+
expect(preAggregationsDescription[0].tableName).toEqual('vis_revenue_and_time_rollup');
250+
expect(sqlAndParams[0]).toContain('vis_revenue_and_time_rollup');
251+
252+
return dbRunner.evaluateQueryWithPreAggregations(query).then(res => {
253+
console.log('!!!! res', res);
254+
expect(res).toEqual(
255+
[
256+
{ vis__source: 'google', vis__revenue_and_time: '25' },
257+
{ vis__source: 'some', vis__revenue_and_time: '50' },
258+
{ vis__source: null, vis__revenue_and_time: '50' }
259+
]
260+
261+
);
262+
});
263+
}));
264+
265+
it('simple multi stage with add_group_by and time proxy dimension tttmp', () => compiler.compile().then(() => {
266+
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
267+
measures: [
268+
'visitors.testMeas'
269+
],
270+
dimensions: ['visitor_checkins.source'],
271+
timezone: 'America/Los_Angeles',
272+
order: [{
273+
id: 'visitor_checkins.source'
274+
}],
275+
preAggregationsSchema: ''
276+
});
277+
278+
const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription();
279+
const sqlAndParams = query.buildSqlAndParams();
280+
console.log('!!!! sqlAndParamsl', sqlAndParams);
281+
/* console.log('!!!! sqlAndParamsl', sqlAndParams);
282+
expect(preAggregationsDescription[0].tableName).toEqual('vis_revenue_and_time_rollup');
283+
expect(sqlAndParams[0]).toContain('vis_revenue_and_time_rollup'); */
284+
285+
return dbRunner.evaluateQueryWithPreAggregations(query).then(res => {
286+
console.log('!!!! res', res);
287+
expect(res).toEqual(
176288
[
177-
{
178-
vis__created_at_day: '2017-01-02T00:00:00.000Z',
179-
vis__revenue_per_id: '100'
180-
},
181-
{
182-
vis__created_at_day: '2017-01-04T00:00:00.000Z',
183-
vis__revenue_per_id: '100'
184-
},
185-
{
186-
vis__created_at_day: '2017-01-05T00:00:00.000Z',
187-
vis__revenue_per_id: '100'
188-
},
189-
{
190-
vis__created_at_day: '2017-01-06T00:00:00.000Z',
191-
vis__revenue_per_id: '200'
192-
}
289+
{ vis__source: 'google', vis__revenue_and_time: '25' },
290+
{ vis__source: 'some', vis__revenue_and_time: '50' },
291+
{ vis__source: null, vis__revenue_and_time: '50' }
193292
]
194293

195-
);
196-
});
197-
}));
294+
);
295+
});
296+
}));
198297
});

0 commit comments

Comments
 (0)