@@ -84,6 +84,27 @@ cubes:
8484 type: string
8585 add_group_by: [orders.customerId]
8686
87+ - name: changeTypeComplexWithJoin
88+ sql: >
89+ CASE
90+ WHEN {revenueYearAgo} IS NULL THEN 'New'
91+ WHEN {revenue} > {revenueYearAgo} THEN 'Grow'
92+ ELSE 'Down'
93+ END
94+ multi_stage: true
95+ type: string
96+ add_group_by: [first_date.customerId]
97+
98+ - name: changeTypeConcat
99+ sql: "CONCAT({changeTypeComplex}, '-test')"
100+ type: string
101+ multi_stage: true
102+
103+ - name: twoDimsConcat
104+ sql: "CONCAT({changeTypeComplex}, '-', {first_date.customerType2})"
105+ type: string
106+ multi_stage: true
107+
87108
88109 measures:
89110 - name: count
@@ -111,6 +132,55 @@ cubes:
111132 END
112133 type: string
113134
135+ - name: first_date
136+ sql: >
137+ SELECT 1 AS id, '2023-03-01T00:00:00Z'::timestamptz AS createdAt, 1 AS customerId UNION ALL
138+ SELECT 8 AS id, '2023-09-01T00:00:00Z'::timestamptz AS createdAt, 2 AS customerId UNION ALL
139+ SELECT 16 AS id, '2024-09-01T00:00:00Z'::timestamptz AS createdAt, 3 AS customerId UNION ALL
140+ SELECT 23 AS id, '2025-03-01T00:00:00Z'::timestamptz AS createdAt, 4 AS customerId UNION ALL
141+ SELECT 29 AS id, '2025-03-01T00:00:00Z'::timestamptz AS createdAt, 5 AS customerId UNION ALL
142+ SELECT 36 AS id, '2025-09-01T00:00:00Z'::timestamptz AS createdAt, 6 AS customerId
143+
144+ joins:
145+ - name: orders
146+ sql: "{first_date.customerId} = {orders.customerId}"
147+ relationship: one_to_many
148+
149+ dimensions:
150+ - name: customerId
151+ sql: customerId
152+ type: number
153+
154+ - name: createdAt
155+ sql: createdAt
156+ type: time
157+
158+ - name: customerType
159+ sql: >
160+ CASE
161+ WHEN {orders.revenue} < 10000 THEN 'Low'
162+ WHEN {orders.revenue} < 20000 THEN 'Medium'
163+ ELSE 'Top'
164+ END
165+ multi_stage: true
166+ type: string
167+ add_group_by: [first_date.customerId]
168+
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+
179+ - name: customerTypeConcat
180+ sql: "CONCAT('Customer type: ', {customerType})"
181+ multi_stage: true
182+ type: string
183+ add_group_by: [first_date.customerId]
114184
115185
116186 ` ) ;
@@ -242,6 +312,205 @@ cubes:
242312 } ,
243313 ] ,
244314 { joinGraph, cubeEvaluator, compiler } ) ) ;
315+ it ( 'bucketing with dimension over complex dimension' , async ( ) => dbRunner . runQueryTest ( {
316+ dimensions : [ 'orders.changeTypeConcat' ] ,
317+ measures : [ 'orders.revenue' , 'orders.revenueYearAgo' ] ,
318+ timeDimensions : [
319+ {
320+ dimension : 'orders.createdAt' ,
321+ granularity : 'year' ,
322+ dateRange : [ '2024-01-02T00:00:00' , '2026-01-01T00:00:00' ]
323+ }
324+ ] ,
325+ timezone : 'UTC' ,
326+ order : [ {
327+ id : 'orders.changeTypeConcat'
328+ } , { id : 'orders.createdAt' } ] ,
329+ } ,
330+ [
331+ {
332+ orders__change_type_concat : 'Down-test' ,
333+ orders__created_at_year : '2024-01-01T00:00:00.000Z' ,
334+ orders__revenue : '20400' ,
335+ orders__revenue_year_ago : '22800'
336+ } ,
337+ {
338+ orders__change_type_concat : 'Down-test' ,
339+ orders__created_at_year : '2025-01-01T00:00:00.000Z' ,
340+ orders__revenue : '17800' ,
341+ orders__revenue_year_ago : '20400'
342+ } ,
343+ {
344+ orders__change_type_concat : 'Grow-test' ,
345+ orders__created_at_year : '2024-01-01T00:00:00.000Z' ,
346+ orders__revenue : '11700' ,
347+ orders__revenue_year_ago : '9400'
348+ } ,
349+ {
350+ orders__change_type_concat : 'Grow-test' ,
351+ orders__created_at_year : '2025-01-01T00:00:00.000Z' ,
352+ orders__revenue : '14100' ,
353+ orders__revenue_year_ago : '11700'
354+ } ,
355+ ] ,
356+ { joinGraph, cubeEvaluator, compiler } ) ) ;
357+ it ( 'bucketing with join and bucket dimension' , async ( ) => dbRunner . runQueryTest ( {
358+ dimensions : [ 'orders.changeTypeComplexWithJoin' ] ,
359+ measures : [ 'orders.revenue' , 'orders.revenueYearAgo' ] ,
360+ timeDimensions : [
361+ {
362+ dimension : 'orders.createdAt' ,
363+ granularity : 'year' ,
364+ dateRange : [ '2024-01-02T00:00:00' , '2026-01-01T00:00:00' ]
365+ }
366+ ] ,
367+ timezone : 'UTC' ,
368+ order : [ {
369+ id : 'orders.changeTypeComplexWithJoin'
370+ } , { id : 'orders.createdAt' } ] ,
371+ } ,
372+ [
373+ {
374+ orders__change_type_complex_with_join : 'Down' ,
375+ orders__created_at_year : '2024-01-01T00:00:00.000Z' ,
376+ orders__revenue : '20400' ,
377+ orders__revenue_year_ago : '22800'
378+ } ,
379+ {
380+ orders__change_type_complex_with_join : 'Down' ,
381+ orders__created_at_year : '2025-01-01T00:00:00.000Z' ,
382+ orders__revenue : '17800' ,
383+ orders__revenue_year_ago : '20400'
384+ } ,
385+ {
386+ orders__change_type_complex_with_join : 'Grow' ,
387+ orders__created_at_year : '2024-01-01T00:00:00.000Z' ,
388+ orders__revenue : '11700' ,
389+ orders__revenue_year_ago : '9400'
390+ } ,
391+ {
392+ orders__change_type_complex_with_join : 'Grow' ,
393+ orders__created_at_year : '2025-01-01T00:00:00.000Z' ,
394+ orders__revenue : '14100' ,
395+ orders__revenue_year_ago : '11700'
396+ } ,
397+ ] ,
398+ { joinGraph, cubeEvaluator, compiler } ) ) ;
399+ it ( 'bucketing dim reference other cube measure' , async ( ) => dbRunner . runQueryTest ( {
400+ dimensions : [ 'first_date.customerType' ] ,
401+ measures : [ 'orders.revenue' ] ,
402+ timezone : 'UTC' ,
403+ order : [ {
404+ id : 'first_date.customerType'
405+ } ] ,
406+ } ,
407+ [
408+ { first_date__customer_type : 'Low' , orders__revenue : '8100' } ,
409+ { first_date__customer_type : 'Medium' , orders__revenue : '41700' } ,
410+ { first_date__customer_type : 'Top' , orders__revenue : '46400' }
411+ ] ,
412+ { 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 } ) ) ;
245514 } else {
246515 // This test is working only in tesseract
247516 test . skip ( 'multi stage over sub query' , ( ) => { expect ( 1 ) . toBe ( 1 ) ; } ) ;
0 commit comments