@@ -84,6 +84,17 @@ 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+
8798 - name: changeTypeConcat
8899 sql: "CONCAT({changeTypeComplex}, '-test')"
89100 type: string
@@ -115,6 +126,45 @@ cubes:
115126 END
116127 type: string
117128
129+ - name: first_date
130+ sql: >
131+ SELECT 1 AS id, '2023-03-01T00:00:00Z'::timestamptz AS createdAt, 1 AS customerId UNION ALL
132+ SELECT 8 AS id, '2023-09-01T00:00:00Z'::timestamptz AS createdAt, 2 AS customerId UNION ALL
133+ SELECT 16 AS id, '2024-09-01T00:00:00Z'::timestamptz AS createdAt, 3 AS customerId UNION ALL
134+ SELECT 23 AS id, '2025-03-01T00:00:00Z'::timestamptz AS createdAt, 4 AS customerId UNION ALL
135+ SELECT 29 AS id, '2025-03-01T00:00:00Z'::timestamptz AS createdAt, 5 AS customerId UNION ALL
136+ SELECT 36 AS id, '2025-09-01T00:00:00Z'::timestamptz AS createdAt, 6 AS customerId
137+
138+ joins:
139+ - name: orders
140+ sql: "{first_date.customerId} = {orders.customerId}"
141+ relationship: one_to_many
142+
143+ dimensions:
144+ - name: customerId
145+ sql: customerId
146+ type: number
147+
148+ - name: createdAt
149+ sql: createdAt
150+ type: time
151+
152+ - name: customerType
153+ sql: >
154+ CASE
155+ WHEN {orders.revenue} < 10000 THEN 'Low'
156+ WHEN {orders.revenue} < 20000 THEN 'Medium'
157+ ELSE 'Top'
158+ END
159+ multi_stage: true
160+ type: string
161+ add_group_by: [first_date.customerId]
162+
163+ - name: customerTypeConcat
164+ sql: "CONCAT('Customer type: ', {customerType})"
165+ multi_stage: true
166+ type: string
167+ add_group_by: [first_date.customerId]
118168
119169
120170 ` ) ;
@@ -288,6 +338,62 @@ cubes:
288338 } ,
289339 ] ,
290340 { joinGraph, cubeEvaluator, compiler } ) ) ;
341+ it ( 'bucketing with join and bucket dimension' , async ( ) => dbRunner . runQueryTest ( {
342+ dimensions : [ 'orders.changeTypeComplexWithJoin' ] ,
343+ measures : [ 'orders.revenue' , 'orders.revenueYearAgo' ] ,
344+ timeDimensions : [
345+ {
346+ dimension : 'orders.createdAt' ,
347+ granularity : 'year' ,
348+ dateRange : [ '2024-01-02T00:00:00' , '2026-01-01T00:00:00' ]
349+ }
350+ ] ,
351+ timezone : 'UTC' ,
352+ order : [ {
353+ id : 'orders.changeTypeComplexWithJoin'
354+ } , { id : 'orders.createdAt' } ] ,
355+ } ,
356+ [
357+ {
358+ orders__change_type_complex_with_join : 'Down' ,
359+ orders__created_at_year : '2024-01-01T00:00:00.000Z' ,
360+ orders__revenue : '20400' ,
361+ orders__revenue_year_ago : '22800'
362+ } ,
363+ {
364+ orders__change_type_complex_with_join : 'Down' ,
365+ orders__created_at_year : '2025-01-01T00:00:00.000Z' ,
366+ orders__revenue : '17800' ,
367+ orders__revenue_year_ago : '20400'
368+ } ,
369+ {
370+ orders__change_type_complex_with_join : 'Grow' ,
371+ orders__created_at_year : '2024-01-01T00:00:00.000Z' ,
372+ orders__revenue : '11700' ,
373+ orders__revenue_year_ago : '9400'
374+ } ,
375+ {
376+ orders__change_type_complex_with_join : 'Grow' ,
377+ orders__created_at_year : '2025-01-01T00:00:00.000Z' ,
378+ orders__revenue : '14100' ,
379+ orders__revenue_year_ago : '11700'
380+ } ,
381+ ] ,
382+ { joinGraph, cubeEvaluator, compiler } ) ) ;
383+ it ( 'bucketing dim reference other cube measure' , async ( ) => dbRunner . runQueryTest ( {
384+ dimensions : [ 'first_date.customerType' ] ,
385+ measures : [ 'orders.revenue' ] ,
386+ timezone : 'UTC' ,
387+ order : [ {
388+ id : 'first_date.customerType'
389+ } ] ,
390+ } ,
391+ [
392+ { first_date__customer_type : 'Low' , orders__revenue : '8100' } ,
393+ { first_date__customer_type : 'Medium' , orders__revenue : '41700' } ,
394+ { first_date__customer_type : 'Top' , orders__revenue : '46400' }
395+ ] ,
396+ { joinGraph, cubeEvaluator, compiler } ) ) ;
291397 } else {
292398 // This test is working only in tesseract
293399 test . skip ( 'multi stage over sub query' , ( ) => { expect ( 1 ) . toBe ( 1 ) ; } ) ;
0 commit comments