Skip to content

Commit 98ea418

Browse files
committed
fix + additional tests
1 parent 3dcf52a commit 98ea418

File tree

2 files changed

+122
-5
lines changed

2 files changed

+122
-5
lines changed

packages/cubejs-schema-compiler/test/integration/postgres/bucketing.test.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ cubes:
9898
- name: changeTypeConcat
9999
sql: "CONCAT({changeTypeComplex}, '-test')"
100100
type: string
101+
multi_stage: true
102+
103+
- name: twoDimsConcat
104+
sql: "CONCAT({changeTypeComplex}, '-', {first_date.customerType2})"
105+
type: string
106+
multi_stage: true
101107
102108
103109
measures:
@@ -160,6 +166,16 @@ cubes:
160166
type: string
161167
add_group_by: [first_date.customerId]
162168
169+
- name: customerType2
170+
sql: >
171+
CASE
172+
WHEN {orders.revenue} < 3000 THEN 'Low'
173+
ELSE 'Top'
174+
END
175+
multi_stage: true
176+
type: string
177+
add_group_by: [first_date.customerId]
178+
163179
- name: customerTypeConcat
164180
sql: "CONCAT('Customer type: ', {customerType})"
165181
multi_stage: true
@@ -394,6 +410,107 @@ cubes:
394410
{ first_date__customer_type: 'Top', orders__revenue: '46400' }
395411
],
396412
{ joinGraph, cubeEvaluator, compiler }));
413+
it('bucketing with two dimensions', async () => dbRunner.runQueryTest({
414+
dimensions: ['orders.changeTypeConcat', 'first_date.customerType2'],
415+
measures: ['orders.revenue', 'orders.revenueYearAgo'],
416+
timeDimensions: [
417+
{
418+
dimension: 'orders.createdAt',
419+
granularity: 'year',
420+
dateRange: ['2024-01-02T00:00:00', '2026-01-01T00:00:00']
421+
}
422+
],
423+
timezone: 'UTC',
424+
order: [{
425+
id: 'orders.changeTypeConcat'
426+
}, { id: 'orders.createdAt' }],
427+
},
428+
[
429+
{
430+
orders__change_type_concat: 'Down-test',
431+
first_date__customer_type2: 'Top',
432+
orders__created_at_year: '2024-01-01T00:00:00.000Z',
433+
orders__revenue: '20400',
434+
orders__revenue_year_ago: '22800'
435+
},
436+
{
437+
orders__change_type_concat: 'Down-test',
438+
first_date__customer_type2: 'Top',
439+
orders__created_at_year: '2025-01-01T00:00:00.000Z',
440+
orders__revenue: '17800',
441+
orders__revenue_year_ago: '20400'
442+
},
443+
{
444+
orders__change_type_concat: 'Grow-test',
445+
first_date__customer_type2: 'Low',
446+
orders__created_at_year: '2024-01-01T00:00:00.000Z',
447+
orders__revenue: '2700',
448+
orders__revenue_year_ago: '2100'
449+
},
450+
{
451+
orders__change_type_concat: 'Grow-test',
452+
first_date__customer_type2: 'Top',
453+
orders__created_at_year: '2024-01-01T00:00:00.000Z',
454+
orders__revenue: '9000',
455+
orders__revenue_year_ago: '7300'
456+
},
457+
{
458+
orders__change_type_concat: 'Grow-test',
459+
first_date__customer_type2: 'Top',
460+
orders__created_at_year: '2025-01-01T00:00:00.000Z',
461+
orders__revenue: '14100',
462+
orders__revenue_year_ago: '11700'
463+
}
464+
],
465+
{ joinGraph, cubeEvaluator, compiler }));
466+
it('bucketing with two dims concacted', async () => dbRunner.runQueryTest({
467+
dimensions: ['orders.twoDimsConcat'],
468+
measures: ['orders.revenue', 'orders.revenueYearAgo'],
469+
timeDimensions: [
470+
{
471+
dimension: 'orders.createdAt',
472+
granularity: 'year',
473+
dateRange: ['2024-01-02T00:00:00', '2026-01-01T00:00:00']
474+
}
475+
],
476+
timezone: 'UTC',
477+
order: [{
478+
id: 'orders.twoDimsConcat'
479+
}, { id: 'orders.createdAt' }],
480+
},
481+
[
482+
{
483+
orders__two_dims_concat: 'Down-Top',
484+
orders__created_at_year: '2024-01-01T00:00:00.000Z',
485+
orders__revenue: '20400',
486+
orders__revenue_year_ago: '22800'
487+
},
488+
{
489+
orders__two_dims_concat: 'Down-Top',
490+
orders__created_at_year: '2025-01-01T00:00:00.000Z',
491+
orders__revenue: '17800',
492+
orders__revenue_year_ago: '20400'
493+
},
494+
{
495+
orders__two_dims_concat: 'Grow-Low',
496+
orders__created_at_year: '2024-01-01T00:00:00.000Z',
497+
orders__revenue: '2700',
498+
orders__revenue_year_ago: '2100'
499+
},
500+
{
501+
orders__two_dims_concat: 'Grow-Top',
502+
orders__created_at_year: '2024-01-01T00:00:00.000Z',
503+
orders__revenue: '9000',
504+
orders__revenue_year_ago: '7300'
505+
},
506+
{
507+
orders__two_dims_concat: 'Grow-Top',
508+
orders__created_at_year: '2025-01-01T00:00:00.000Z',
509+
orders__revenue: '14100',
510+
orders__revenue_year_ago: '11700'
511+
}
512+
],
513+
{ joinGraph, cubeEvaluator, compiler }));
397514
} else {
398515
// This test is working only in tesseract
399516
test.skip('multi stage over sub query', () => { expect(1).toBe(1); });

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/collectors/join_hints_collector.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ impl TraversalVisitor for JoinHintsCollector {
3232
for item in add_group_by.iter() {
3333
self.apply(item, &())?;
3434
}
35-
for (dep, path) in dim.get_dependencies_with_path().into_iter() {
36-
if let Ok(dim) = dep.as_dimension() {
37-
if dim.is_multi_stage() {
38-
self.on_node_traverse(&dep, &path, &())?;
39-
}
35+
}
36+
for (dep, path) in dim.get_dependencies_with_path().into_iter() {
37+
if let Ok(dim) = dep.as_dimension() {
38+
if dim.is_multi_stage() {
39+
self.on_node_traverse(&dep, &path, &())?;
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)