@@ -51,12 +51,29 @@ cubes:
5151 - EUR
5252 - GBP
5353
54+ - name: currency_ref
55+ type: string
56+ sql: "{currency}"
57+
58+
5459 - name: strategy
5560 type: switch
5661 values:
5762 - A
5863 - B
5964
65+ - name: strategy_ref
66+ type: string
67+ sql: "{strategy}"
68+
69+ - name: currency_and_stategy
70+ type: string
71+ sql: "CONCAT({currency}, '-', {strategy})"
72+
73+ - name: currency_and_strategy_ref
74+ type: string
75+ sql: "{currency_and_stategy}"
76+
6077 - name: currency_full_name
6178 type: string
6279 case:
@@ -103,11 +120,20 @@ cubes:
103120 else:
104121 sql: "{CUBE.amount_gbp}"
105122
123+ - name: amount_in_currency_ref
124+ type: number
125+ sql: "{CUBE.amount_in_currency}"
126+
106127 - name: returned_count
107128 type: count
108129 filters:
109130 - sql: "{CUBE}.STATUS = 'returned'"
110131
132+ - name: amount_in_currency_percent_of_usd
133+ type: number
134+ sql: "FLOOR({CUBE.amount_in_currency_ref} / {CUBE.amount_usd} * 100)"
135+
136+
111137 - name: return_rate
112138 type: number
113139 sql: "({returned_count} / NULLIF({completed_count}, 0)) * 100.0"
@@ -300,6 +326,67 @@ views:
300326 ] ,
301327 { joinGraph, cubeEvaluator, compiler } ) ) ;
302328
329+ it ( 'basic cross join by proxy dim' , async ( ) => dbRunner . runQueryTest ( {
330+ dimensions : [ 'orders.currency_ref' ] ,
331+ timeDimensions : [
332+ {
333+ dimension : 'orders.date' ,
334+ granularity : 'year'
335+ }
336+ ] ,
337+ timezone : 'UTC'
338+ } , [
339+ {
340+ orders__currency_ref : 'EUR' ,
341+ orders__date_year : '2022-01-01T00:00:00.000Z'
342+ } ,
343+ {
344+ orders__currency_ref : 'GBP' ,
345+ orders__date_year : '2022-01-01T00:00:00.000Z'
346+ } ,
347+ {
348+ orders__currency_ref : 'USD' ,
349+ orders__date_year : '2022-01-01T00:00:00.000Z'
350+ } ,
351+ {
352+ orders__currency_ref : 'EUR' ,
353+ orders__date_year : '2023-01-01T00:00:00.000Z'
354+ } ,
355+ {
356+ orders__currency_ref : 'GBP' ,
357+ orders__date_year : '2023-01-01T00:00:00.000Z'
358+ } ,
359+ {
360+ orders__currency_ref : 'USD' ,
361+ orders__date_year : '2023-01-01T00:00:00.000Z'
362+ } ,
363+ {
364+ orders__currency_ref : 'EUR' ,
365+ orders__date_year : '2024-01-01T00:00:00.000Z'
366+ } ,
367+ {
368+ orders__currency_ref : 'GBP' ,
369+ orders__date_year : '2024-01-01T00:00:00.000Z'
370+ } ,
371+ {
372+ orders__currency_ref : 'USD' ,
373+ orders__date_year : '2024-01-01T00:00:00.000Z'
374+ } ,
375+ {
376+ orders__currency_ref : 'EUR' ,
377+ orders__date_year : '2025-01-01T00:00:00.000Z'
378+ } ,
379+ {
380+ orders__currency_ref : 'GBP' ,
381+ orders__date_year : '2025-01-01T00:00:00.000Z'
382+ } ,
383+ {
384+ orders__currency_ref : 'USD' ,
385+ orders__date_year : '2025-01-01T00:00:00.000Z'
386+ }
387+ ] ,
388+ { joinGraph, cubeEvaluator, compiler } ) ) ;
389+
303390 it ( 'basic double cross join' , async ( ) => dbRunner . runQueryTest ( {
304391 dimensions : [ 'orders.currency' , 'orders.strategy' ] ,
305392 timeDimensions : [
@@ -382,6 +469,76 @@ views:
382469 ] ,
383470 { joinGraph, cubeEvaluator, compiler } ) ) ;
384471
472+ it ( 'basic double cross join by proxy' , async ( ) => dbRunner . runQueryTest ( {
473+ dimensions : [ 'orders.currency_and_strategy_ref' ] ,
474+ timeDimensions : [
475+ {
476+ dimension : 'orders.date' ,
477+ granularity : 'year' ,
478+ dateRange : [ '2024-01-01' , '2026-01-01' ]
479+ }
480+ ] ,
481+ timezone : 'UTC' ,
482+ order : [ {
483+ id : 'orders.date'
484+ } , {
485+ id : 'orders.currency'
486+ } , {
487+ id : 'orders.strategy'
488+ } ,
489+ ] ,
490+ } , [
491+ {
492+ orders__currency_and_strategy_ref : 'EUR-A' ,
493+ orders__date_year : '2024-01-01T00:00:00.000Z'
494+ } ,
495+ {
496+ orders__currency_and_strategy_ref : 'EUR-B' ,
497+ orders__date_year : '2024-01-01T00:00:00.000Z'
498+ } ,
499+ {
500+ orders__currency_and_strategy_ref : 'GBP-A' ,
501+ orders__date_year : '2024-01-01T00:00:00.000Z'
502+ } ,
503+ {
504+ orders__currency_and_strategy_ref : 'GBP-B' ,
505+ orders__date_year : '2024-01-01T00:00:00.000Z'
506+ } ,
507+ {
508+ orders__currency_and_strategy_ref : 'USD-A' ,
509+ orders__date_year : '2024-01-01T00:00:00.000Z'
510+ } ,
511+ {
512+ orders__currency_and_strategy_ref : 'USD-B' ,
513+ orders__date_year : '2024-01-01T00:00:00.000Z'
514+ } ,
515+ {
516+ orders__currency_and_strategy_ref : 'EUR-A' ,
517+ orders__date_year : '2025-01-01T00:00:00.000Z'
518+ } ,
519+ {
520+ orders__currency_and_strategy_ref : 'EUR-B' ,
521+ orders__date_year : '2025-01-01T00:00:00.000Z'
522+ } ,
523+ {
524+ orders__currency_and_strategy_ref : 'GBP-A' ,
525+ orders__date_year : '2025-01-01T00:00:00.000Z'
526+ } ,
527+ {
528+ orders__currency_and_strategy_ref : 'GBP-B' ,
529+ orders__date_year : '2025-01-01T00:00:00.000Z'
530+ } ,
531+ {
532+ orders__currency_and_strategy_ref : 'USD-A' ,
533+ orders__date_year : '2025-01-01T00:00:00.000Z'
534+ } ,
535+ {
536+ orders__currency_and_strategy_ref : 'USD-B' ,
537+ orders__date_year : '2025-01-01T00:00:00.000Z'
538+ }
539+ ] ,
540+ { joinGraph, cubeEvaluator, compiler } ) ) ;
541+
385542 it ( 'basic cross join with measure' , async ( ) => dbRunner . runQueryTest ( {
386543 dimensions : [ 'orders.strategy' ] ,
387544 measures : [ 'orders.revenue' ] ,
@@ -489,6 +646,53 @@ views:
489646 expect ( sqlAndParams [ 0 ] ) . not . toMatch ( / C R O S S .+ J O I N / ) ;
490647 } ) ;
491648
649+ it ( 'basic cross join with filters proxy dim' , async ( ) => {
650+ const sqlAndParams = await dbRunner . runQueryTest ( {
651+ dimensions : [ 'orders.strategy_ref' ] ,
652+ measures : [ 'orders.revenue' ] ,
653+ timeDimensions : [
654+ {
655+ dimension : 'orders.date' ,
656+ granularity : 'year'
657+ }
658+ ] ,
659+ filters : [
660+ { dimension : 'orders.strategy_ref' , operator : 'equals' , values : [ 'B' ] }
661+ ] ,
662+ timezone : 'UTC' ,
663+ order : [ {
664+ id : 'orders.date'
665+ } , {
666+ id : 'orders.currency'
667+ } ,
668+ ] ,
669+ } , [
670+ {
671+ orders__date_year : '2022-01-01T00:00:00.000Z' ,
672+ orders__strategy_ref : 'B' ,
673+ orders__revenue : '5' ,
674+ } ,
675+ {
676+ orders__date_year : '2023-01-01T00:00:00.000Z' ,
677+ orders__strategy_ref : 'B' ,
678+ orders__revenue : '15' ,
679+ } ,
680+ {
681+ orders__date_year : '2024-01-01T00:00:00.000Z' ,
682+ orders__strategy_ref : 'B' ,
683+ orders__revenue : '30' ,
684+ } ,
685+ {
686+ orders__date_year : '2025-01-01T00:00:00.000Z' ,
687+ orders__strategy_ref : 'B' ,
688+ orders__revenue : '5' ,
689+ }
690+ ] ,
691+ { joinGraph, cubeEvaluator, compiler } ) ;
692+
693+ expect ( sqlAndParams [ 0 ] ) . not . toMatch ( / C R O S S .+ J O I N / ) ;
694+ } ) ;
695+
492696 it ( 'dimension switch expression simple' , async ( ) => dbRunner . runQueryTest ( {
493697 dimensions : [ 'orders.currency' , 'orders.currency_full_name' ] ,
494698 measures : [ 'orders.revenue' ] ,
@@ -603,6 +807,57 @@ views:
603807 ] ,
604808 { joinGraph, cubeEvaluator, compiler } ) ) ;
605809
810+ it ( 'complex measure switch cross join' , async ( ) => dbRunner . runQueryTest ( {
811+ dimensions : [ 'orders.currency' ] ,
812+ measures : [ 'orders.amount_in_currency_percent_of_usd' ] ,
813+ timeDimensions : [
814+ {
815+ dimension : 'orders.date' ,
816+ granularity : 'year' ,
817+ dateRange : [ '2024-01-01' , '2026-01-01' ]
818+ }
819+ ] ,
820+ timezone : 'UTC' ,
821+ order : [ {
822+ id : 'orders.date'
823+ } , {
824+ id : 'orders.currency'
825+ } ,
826+ ] ,
827+ } , [
828+ {
829+ orders__currency : 'EUR' ,
830+ orders__date_year : '2024-01-01T00:00:00.000Z' ,
831+ orders__amount_in_currency_percent_of_usd : '97'
832+ } ,
833+ {
834+ orders__currency : 'GBP' ,
835+ orders__date_year : '2024-01-01T00:00:00.000Z' ,
836+ orders__amount_in_currency_percent_of_usd : '80'
837+ } ,
838+ {
839+ orders__currency : 'USD' ,
840+ orders__date_year : '2024-01-01T00:00:00.000Z' ,
841+ orders__amount_in_currency_percent_of_usd : '100'
842+ } ,
843+ {
844+ orders__currency : 'EUR' ,
845+ orders__date_year : '2025-01-01T00:00:00.000Z' ,
846+ orders__amount_in_currency_percent_of_usd : '95'
847+ } ,
848+ {
849+ orders__currency : 'GBP' ,
850+ orders__date_year : '2025-01-01T00:00:00.000Z' ,
851+ orders__amount_in_currency_percent_of_usd : '82'
852+ } ,
853+ {
854+ orders__currency : 'USD' ,
855+ orders__date_year : '2025-01-01T00:00:00.000Z' ,
856+ orders__amount_in_currency_percent_of_usd : '100'
857+ }
858+ ] ,
859+ { joinGraph, cubeEvaluator, compiler } ) ) ;
860+
606861 it ( 'measure switch with filter' , async ( ) => {
607862 const sqlAndParams = await dbRunner . runQueryTest ( {
608863 dimensions : [ 'orders.currency' ] ,
@@ -643,6 +898,45 @@ views:
643898 expect ( sqlAndParams [ 0 ] ) . not . toMatch ( / C A S E / ) ;
644899 expect ( sqlAndParams [ 0 ] ) . not . toMatch ( / C R O S S .+ J O I N / ) ;
645900 } ) ;
901+
902+ it ( 'complex measure switch with filter' , async ( ) => {
903+ const sqlAndParams = await dbRunner . runQueryTest ( {
904+ dimensions : [ 'orders.currency' ] ,
905+ measures : [ 'orders.amount_in_currency_percent_of_usd' ] ,
906+ timeDimensions : [
907+ {
908+ dimension : 'orders.date' ,
909+ granularity : 'year' ,
910+ dateRange : [ '2024-01-01' , '2026-01-01' ]
911+ }
912+ ] ,
913+ filters : [
914+ { dimension : 'orders.currency' , operator : 'equals' , values : [ 'EUR' ] }
915+ ] ,
916+ timezone : 'UTC' ,
917+ order : [ {
918+ id : 'orders.date'
919+ } , {
920+ id : 'orders.currency'
921+ } ,
922+ ] ,
923+ } , [
924+ {
925+ orders__currency : 'EUR' ,
926+ orders__date_year : '2024-01-01T00:00:00.000Z' ,
927+ orders__amount_in_currency_percent_of_usd : '97'
928+ } ,
929+ {
930+ orders__currency : 'EUR' ,
931+ orders__date_year : '2025-01-01T00:00:00.000Z' ,
932+ orders__amount_in_currency_percent_of_usd : '95'
933+ } ,
934+ ] ,
935+ { joinGraph, cubeEvaluator, compiler } ) ;
936+
937+ expect ( sqlAndParams [ 0 ] ) . not . toMatch ( / C A S E / ) ;
938+ expect ( sqlAndParams [ 0 ] ) . not . toMatch ( / C R O S S .+ J O I N / ) ;
939+ } ) ;
646940 } else {
647941 // This test is working only in tesseract
648942 test . skip ( 'calc groups testst' , ( ) => { expect ( 1 ) . toBe ( 1 ) ; } ) ;
0 commit comments