@@ -547,6 +547,60 @@ describe('SQL Generation', () => {
547
547
},
548
548
}
549
549
});
550
+
551
+ cube('orders', {
552
+ sql: 'select 1 as order_id, 100 as total, 1 as user_id',
553
+ joins: {
554
+ users: {
555
+ relationship: 'hasMany',
556
+ sql: \`\${CUBE.user_id} = \${users.user_id}\`
557
+ }
558
+ },
559
+ measures: {
560
+ sum_total: {
561
+ type: 'sum',
562
+ sql: 'total'
563
+ }
564
+ },
565
+ dimensions: {
566
+ order_id: {
567
+ type: 'number',
568
+ sql: 'order_id',
569
+ primaryKey: true
570
+ },
571
+ user_id: {
572
+ type: 'number',
573
+ sql: 'user_id',
574
+ }
575
+ }
576
+ });
577
+ cube('users', {
578
+ sql: 'select 1 as user_id, false as internal',
579
+ dimensions: {
580
+ user_id: {
581
+ type: 'number',
582
+ sql: 'user_id',
583
+ primaryKey: true
584
+ },
585
+ internal: {
586
+ type: 'boolean',
587
+ sql: 'internal'
588
+ },
589
+ }
590
+ });
591
+ view('revenue_view', {
592
+ cubes: [
593
+ {
594
+ join_path: 'orders',
595
+ includes: ['sum_total', 'user_id']
596
+ },
597
+ {
598
+ join_path: 'orders.users',
599
+ includes: ['internal']
600
+ }
601
+ ]
602
+ });
603
+
550
604
` ) ;
551
605
552
606
it ( 'simple join' , async ( ) => {
@@ -3032,6 +3086,55 @@ describe('SQL Generation', () => {
3032
3086
]
3033
3087
) ) ;
3034
3088
3089
+ it ( 'multiplied measures missing column' , async ( ) => runQueryTest (
3090
+ {
3091
+ measures : [
3092
+ {
3093
+ // eslint-disable-next-line no-new-func
3094
+ expression : new Function (
3095
+ 'revenue_view' ,
3096
+ // eslint-disable-next-line no-template-curly-in-string
3097
+ 'return `${revenue_view.sum_total}`'
3098
+ ) ,
3099
+ name : 'revenue_total' ,
3100
+ expressionName : 'revenue_total' ,
3101
+ // eslint-disable-next-line no-template-curly-in-string
3102
+ definition : '${revenue_view.sum_total}' ,
3103
+ cubeName : 'revenue_view' ,
3104
+ } ,
3105
+ {
3106
+ // eslint-disable-next-line no-new-func
3107
+ expression : new Function (
3108
+ 'revenue_view' ,
3109
+ // eslint-disable-next-line no-template-curly-in-string
3110
+ 'return `COUNT(DISTINCT ${revenue_view.user_id})`'
3111
+ ) ,
3112
+ name : 'distinct_users' ,
3113
+ expressionName : 'distinct_users' ,
3114
+ // eslint-disable-next-line no-template-curly-in-string
3115
+ definition : 'COUNT(DISTINCT ${revenue_view.user_id})' ,
3116
+ cubeName : 'revenue_view' ,
3117
+ } ,
3118
+ ] ,
3119
+ dimensions : [
3120
+ {
3121
+ // eslint-disable-next-line no-new-func
3122
+ expression : new Function (
3123
+ 'revenue_view' ,
3124
+ // eslint-disable-next-line no-template-curly-in-string
3125
+ 'return `${revenue_view.internal}`'
3126
+ ) ,
3127
+ name : 'internal_user' ,
3128
+ expressionName : 'internal_user' ,
3129
+ // eslint-disable-next-line no-template-curly-in-string
3130
+ definition : '${revenue_view.internal}' ,
3131
+ cubeName : 'revenue_view' ,
3132
+ } ,
3133
+ ] ,
3134
+ } ,
3135
+ [ ]
3136
+ ) ) ;
3137
+
3035
3138
// TODO not implemented
3036
3139
// it('multi stage bucketing', async () => runQueryTest(
3037
3140
// {
0 commit comments