Skip to content

Commit 3cc998d

Browse files
committed
[WIP] more tests to debug
1 parent d9421d0 commit 3cc998d

File tree

1 file changed

+94
-4
lines changed

1 file changed

+94
-4
lines changed

packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,11 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
651651
});
652652
653653
cube('orders', {
654-
sql: 'select 1 as order_id, 100 as total, 1 as user_id',
654+
sql: \`
655+
SELECT 1 AS order_id, 100 AS total, 1 AS user_id UNION ALL
656+
SELECT 2 AS order_id, 200 AS total, 1 AS user_id UNION ALL
657+
SELECT 3 AS order_id, 500 AS total, 2 AS user_id
658+
\`,
655659
joins: {
656660
users: {
657661
relationship: 'hasMany',
@@ -677,7 +681,10 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
677681
}
678682
});
679683
cube('users', {
680-
sql: 'select 1 as user_id, false as internal',
684+
sql: \`
685+
SELECT 1 AS user_id, false AS internal UNION ALL
686+
SELECT 2 AS user_id, true AS internal
687+
\`,
681688
dimensions: {
682689
user_id: {
683690
type: 'number',
@@ -3376,7 +3383,7 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
33763383
]
33773384
));
33783385

3379-
it('multiplied measures missing column', async () => runQueryTest(
3386+
it('multiplied measures missing column grouped', async () => runQueryTest(
33803387
{
33813388
measures: [
33823389
{
@@ -3391,6 +3398,7 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
33913398
// eslint-disable-next-line no-template-curly-in-string
33923399
definition: '${revenue_view.sum_total}',
33933400
cubeName: 'revenue_view',
3401+
// cubeName: 'orders',
33943402
},
33953403
{
33963404
// eslint-disable-next-line no-new-func
@@ -3404,6 +3412,7 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
34043412
// eslint-disable-next-line no-template-curly-in-string
34053413
definition: 'COUNT(DISTINCT ${revenue_view.user_id})',
34063414
cubeName: 'revenue_view',
3415+
// cubeName: 'orders',
34073416
},
34083417
],
34093418
dimensions: [
@@ -3419,10 +3428,91 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
34193428
// eslint-disable-next-line no-template-curly-in-string
34203429
definition: '${revenue_view.internal}',
34213430
cubeName: 'revenue_view',
3431+
// cubeName: 'users',
34223432
},
34233433
],
3434+
order: [{
3435+
'revenue_view.internal': 'asc'
3436+
}]
34243437
},
3425-
[]
3438+
[
3439+
{
3440+
distinct_users: '1',
3441+
internal_user: false,
3442+
revenue_total: '300',
3443+
},
3444+
{
3445+
distinct_users: '1',
3446+
internal_user: true,
3447+
revenue_total: '500',
3448+
},
3449+
]
3450+
));
3451+
3452+
it('multiplied measures missing column ungrouped', async () => runQueryTest(
3453+
{
3454+
measures: [
3455+
{
3456+
// eslint-disable-next-line no-new-func
3457+
expression: new Function(
3458+
'revenue_view',
3459+
// eslint-disable-next-line no-template-curly-in-string
3460+
'return `${revenue_view.sum_total}`'
3461+
),
3462+
name: 'revenue_total',
3463+
expressionName: 'revenue_total',
3464+
// eslint-disable-next-line no-template-curly-in-string
3465+
definition: '${revenue_view.sum_total}',
3466+
cubeName: 'revenue_view',
3467+
// cubeName: 'orders',
3468+
},
3469+
{
3470+
// eslint-disable-next-line no-new-func
3471+
expression: new Function(
3472+
'revenue_view',
3473+
// eslint-disable-next-line no-template-curly-in-string
3474+
'return `${revenue_view.user_id}`'
3475+
),
3476+
name: 'distinct_users',
3477+
expressionName: 'distinct_users',
3478+
// eslint-disable-next-line no-template-curly-in-string
3479+
definition: '${revenue_view.user_id}',
3480+
cubeName: 'revenue_view',
3481+
// cubeName: 'orders',
3482+
},
3483+
{
3484+
// eslint-disable-next-line no-new-func
3485+
expression: new Function(
3486+
'revenue_view',
3487+
// eslint-disable-next-line no-template-curly-in-string
3488+
'return `${revenue_view.internal}`'
3489+
),
3490+
name: 'internal_user',
3491+
expressionName: 'internal_user',
3492+
// eslint-disable-next-line no-template-curly-in-string
3493+
definition: '${revenue_view.internal}',
3494+
cubeName: 'revenue_view',
3495+
// cubeName: 'users',
3496+
},
3497+
],
3498+
order: [{
3499+
'revenue_view.order_id': 'asc'
3500+
}],
3501+
ungrouped: true,
3502+
allowUngroupedWithoutPrimaryKey: true,
3503+
},
3504+
[
3505+
// {
3506+
// distinct_users: '1',
3507+
// internal_user: true,
3508+
// revenue_total: '500',
3509+
// },
3510+
// {
3511+
// distinct_users: '1',
3512+
// internal_user: false,
3513+
// revenue_total: '300',
3514+
// },
3515+
]
34263516
));
34273517

34283518
// TODO not implemented

0 commit comments

Comments
 (0)