diff --git a/.github/workflows/drivers-tests.yml b/.github/workflows/drivers-tests.yml index 7f16a79527882..994d995417434 100644 --- a/.github/workflows/drivers-tests.yml +++ b/.github/workflows/drivers-tests.yml @@ -269,6 +269,10 @@ jobs: include: - database: postgres use_tesseract_sql_planner: true + - database: snowflake + use_tesseract_sql_planner: true + - database: redshift + use_tesseract_sql_planner: true - database: bigquery-export-bucket-gcs use_tesseract_sql_planner: true - database: athena-export-bucket-s3 diff --git a/packages/cubejs-schema-compiler/src/adapter/RedshiftQuery.ts b/packages/cubejs-schema-compiler/src/adapter/RedshiftQuery.ts index 893f6e4d9bf27..129c11ad09067 100644 --- a/packages/cubejs-schema-compiler/src/adapter/RedshiftQuery.ts +++ b/packages/cubejs-schema-compiler/src/adapter/RedshiftQuery.ts @@ -85,6 +85,15 @@ export class RedshiftQuery extends PostgresQuery { const templates = super.sqlTemplates(); templates.functions.DLOG10 = 'LOG(10, {{ args_concat }})'; templates.functions.DATEDIFF = 'DATEDIFF({{ date_part }}, {{ args[1] }}, {{ args[2] }})'; + templates.statements.time_series_select = 'SELECT dates.f::timestamp date_from, dates.t::timestamp date_to \n' + + 'FROM (\n' + + '{% for time_item in seria %}' + + ' select \'{{ time_item[0] }}\' f, \'{{ time_item[1] }}\' t \n' + + '{% if not loop.last %} UNION ALL\n{% endif %}' + + '{% endfor %}' + + ') AS dates'; + delete templates.statements.generated_time_series_select; + delete templates.operators.is_not_distinct_from; delete templates.functions.COVAR_POP; delete templates.functions.COVAR_SAMP; delete templates.window_frame_types.range; diff --git a/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts b/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts index 0e2d10080f7ef..64e1d54b3cb02 100644 --- a/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts +++ b/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts @@ -302,6 +302,18 @@ describe('SQL Generation', () => { type: 'sum', group_by: [visitors.source] }, + visitors_revenue_per_year: { + multi_stage: true, + sql: \`\${revenue}\`, + type: 'sum', + group_by: [visitors.created_at.year] + }, + visitors_revenue_reduce_day: { + multi_stage: true, + sql: \`\${revenue}\`, + type: 'sum', + reduce_by: [visitors.created_at.day] + }, visitors_revenue_without_date: { multi_stage: true, sql: \`\${revenue}\`, @@ -4434,6 +4446,184 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL }] )); + if (getEnv('nativeSqlPlanner')) { + it('multi stage sum with group by time dim with granularity', async () => runQueryTest( + { + measures: ['visitors.visitors_revenue_per_year', 'visitors.revenue'], + dimensions: ['visitors.source'], + timeDimensions: [{ + dimension: 'visitors.created_at', + granularity: 'year', + dateRange: ['2016-01-01', '2017-01-30'] + }], + timezone: 'America/Los_Angeles', + order: [{ + id: 'visitors.source' + }, { + id: 'visitors.created_at' + }], + }, + + [{ + visitors__source: 'google', + visitors__created_at_year: '2017-01-01T00:00:00.000Z', + visitors__visitors_revenue_per_year: '1500', + visitors__revenue: '300' + }, + { + visitors__source: 'some', + visitors__created_at_year: '2017-01-01T00:00:00.000Z', + visitors__visitors_revenue_per_year: '1500', + visitors__revenue: '300' + }, + { + visitors__source: null, + visitors__created_at_year: '2016-01-01T00:00:00.000Z', + visitors__visitors_revenue_per_year: '500', + visitors__revenue: '500' + }, + { + visitors__source: null, + visitors__created_at_year: '2017-01-01T00:00:00.000Z', + visitors__visitors_revenue_per_year: '1500', + visitors__revenue: '900' + }] + )); + } else { + it.skip('multi stage sum with group by time dim with granularity', async () => { + // Works only in Tesseract + }); + } + + if (getEnv('nativeSqlPlanner')) { + it('multi stage sum multiple time dims group by time dim with granularity', async () => runQueryTest( + { + measures: ['visitors.visitors_revenue_per_year', 'visitors.revenue'], + dimensions: ['visitors.source'], + timeDimensions: [{ + dimension: 'visitors.created_at', + granularity: 'year', + dateRange: ['2014-01-01', '2018-01-30'] + }, + { + dimension: 'visitors.created_at', + granularity: 'day', + dateRange: ['2014-01-01', '2018-01-30'] + }], + timezone: 'America/Los_Angeles', + order: [{ + id: 'visitors.source' + }, { + id: 'visitors.created_at' + }], + }, + + [ + { + visitors__source: 'google', + visitors__created_at_year: '2017-01-01T00:00:00.000Z', + visitors__created_at_day: '2017-01-05T00:00:00.000Z', + visitors__visitors_revenue_per_year: '1500', + visitors__revenue: '300' + }, + { + visitors__source: 'some', + visitors__created_at_year: '2017-01-01T00:00:00.000Z', + visitors__created_at_day: '2017-01-02T00:00:00.000Z', + visitors__visitors_revenue_per_year: '1500', + visitors__revenue: '100' + }, + { + visitors__source: 'some', + visitors__created_at_year: '2017-01-01T00:00:00.000Z', + visitors__created_at_day: '2017-01-04T00:00:00.000Z', + visitors__visitors_revenue_per_year: '1500', + visitors__revenue: '200' + }, + { + visitors__source: null, + visitors__created_at_year: '2016-01-01T00:00:00.000Z', + visitors__created_at_day: '2016-09-06T00:00:00.000Z', + visitors__visitors_revenue_per_year: '500', + visitors__revenue: '500' + }, + { + visitors__source: null, + visitors__created_at_year: '2017-01-01T00:00:00.000Z', + visitors__created_at_day: '2017-01-06T00:00:00.000Z', + visitors__visitors_revenue_per_year: '1500', + visitors__revenue: '900' + } + ] + )); + } else { + it.skip('multi stage sum multiple time dims group by time dim with granularity', async () => { + // Works only in Tesseract + }); + } + + if (getEnv('nativeSqlPlanner')) { + it('multi stage sum multiple time dims reduce by time dim with granularity', async () => runQueryTest( + { + measures: ['visitors.visitors_revenue_reduce_day', 'visitors.revenue'], + timeDimensions: [{ + dimension: 'visitors.created_at', + granularity: 'year', + dateRange: ['2014-01-01', '2018-01-30'] + }, + { + dimension: 'visitors.created_at', + granularity: 'day', + dateRange: ['2014-01-01', '2018-01-30'] + }], + timezone: 'America/Los_Angeles', + order: [{ + id: 'visitors.source' + }, { + id: 'visitors.created_at' + }], + }, + + [ + + { + visitors__created_at_year: '2016-01-01T00:00:00.000Z', + visitors__created_at_day: '2016-09-06T00:00:00.000Z', + visitors__visitors_revenue_reduce_day: '500', + visitors__revenue: '500' + }, + { + visitors__created_at_year: '2017-01-01T00:00:00.000Z', + visitors__created_at_day: '2017-01-02T00:00:00.000Z', + visitors__visitors_revenue_reduce_day: '1500', + visitors__revenue: '100' + }, + { + visitors__created_at_year: '2017-01-01T00:00:00.000Z', + visitors__created_at_day: '2017-01-04T00:00:00.000Z', + visitors__visitors_revenue_reduce_day: '1500', + visitors__revenue: '200' + }, + { + visitors__created_at_year: '2017-01-01T00:00:00.000Z', + visitors__created_at_day: '2017-01-05T00:00:00.000Z', + visitors__visitors_revenue_reduce_day: '1500', + visitors__revenue: '300' + }, + { + visitors__created_at_year: '2017-01-01T00:00:00.000Z', + visitors__created_at_day: '2017-01-06T00:00:00.000Z', + visitors__visitors_revenue_reduce_day: '1500', + visitors__revenue: '900' + } + ] + )); + } else { + it.skip('multi stage sum multiple time dims reduce by time dim with granularity', async () => { + // Works only in Tesseract + }); + } + if (getEnv('nativeSqlPlanner')) { it('multi stage sum with group by over view', async () => runQueryTest( { diff --git a/packages/cubejs-testing-drivers/fixtures/_schemas.json b/packages/cubejs-testing-drivers/fixtures/_schemas.json index 2b5f19fd4dbd2..54cd412eef34d 100644 --- a/packages/cubejs-testing-drivers/fixtures/_schemas.json +++ b/packages/cubejs-testing-drivers/fixtures/_schemas.json @@ -424,6 +424,13 @@ "type": "prior" }] }, + { + "name": "totalProfitForQuarter", + "type": "sum", + "sql": "{totalProfit}", + "multi_stage": true, + "group_by": ["orderDate.quarter"] + }, { "name": "totalProfitForStatus", "type": "sum", diff --git a/packages/cubejs-testing-drivers/fixtures/athena.json b/packages/cubejs-testing-drivers/fixtures/athena.json index edf557f5cbf31..13e148d474467 100644 --- a/packages/cubejs-testing-drivers/fixtures/athena.json +++ b/packages/cubejs-testing-drivers/fixtures/athena.json @@ -157,6 +157,7 @@ "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", "Tesseract: SQL API: Timeshift measure from cube", + "querying BigECommerce: multi-stage group by time dimension", "---------------------------------------", "Custom Granularities ", @@ -191,6 +192,7 @@ "querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", "SQL API: Timeshift measure from cube", + "querying BigECommerce: multi-stage group by time dimension", "querying BigECommerce: rolling window by 2 week", "querying custom granularities ECommerce: count by three_months_by_march + no dimension", diff --git a/packages/cubejs-testing-drivers/fixtures/bigquery.json b/packages/cubejs-testing-drivers/fixtures/bigquery.json index 0564ff0160bd2..a83f3b47b2cd2 100644 --- a/packages/cubejs-testing-drivers/fixtures/bigquery.json +++ b/packages/cubejs-testing-drivers/fixtures/bigquery.json @@ -171,6 +171,7 @@ "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", "Tesseract: SQL API: Timeshift measure from cube", + "querying BigECommerce: multi-stage group by time dimension", "---------------------------------------", "SKIPPED SQL API (Need work)", @@ -223,6 +224,7 @@ "querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", "querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", "SQL API: Timeshift measure from cube", + "querying BigECommerce: multi-stage group by time dimension", "---- Different results comparing to baseQuery version. Need to investigate ----", "SQL API: SQL push down push to cube quoted alias", diff --git a/packages/cubejs-testing-drivers/fixtures/clickhouse.json b/packages/cubejs-testing-drivers/fixtures/clickhouse.json index c0fa6c20dd51b..57ab79daa2f93 100644 --- a/packages/cubejs-testing-drivers/fixtures/clickhouse.json +++ b/packages/cubejs-testing-drivers/fixtures/clickhouse.json @@ -208,6 +208,7 @@ "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", "Tesseract: SQL API: Timeshift measure from cube", + "querying BigECommerce: multi-stage group by time dimension", "---------------------------------------", "Custom Granularities ", diff --git a/packages/cubejs-testing-drivers/fixtures/databricks-jdbc.json b/packages/cubejs-testing-drivers/fixtures/databricks-jdbc.json index c7fd29f22e96e..906c419ea322f 100644 --- a/packages/cubejs-testing-drivers/fixtures/databricks-jdbc.json +++ b/packages/cubejs-testing-drivers/fixtures/databricks-jdbc.json @@ -224,6 +224,7 @@ "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", "Tesseract: SQL API: Timeshift measure from cube", + "querying BigECommerce: multi-stage group by time dimension", "---------------------------------------", "Custom Granularities ", diff --git a/packages/cubejs-testing-drivers/fixtures/mssql.json b/packages/cubejs-testing-drivers/fixtures/mssql.json index 7590b07529a88..3d71be829f3e4 100644 --- a/packages/cubejs-testing-drivers/fixtures/mssql.json +++ b/packages/cubejs-testing-drivers/fixtures/mssql.json @@ -150,6 +150,7 @@ "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", "Tesseract: SQL API: Timeshift measure from cube", + "querying BigECommerce: multi-stage group by time dimension", "---------------------------------------", "SKIPPED SQL API (Need work)", diff --git a/packages/cubejs-testing-drivers/fixtures/mysql.json b/packages/cubejs-testing-drivers/fixtures/mysql.json index d38f245880029..dcc64654a99e1 100644 --- a/packages/cubejs-testing-drivers/fixtures/mysql.json +++ b/packages/cubejs-testing-drivers/fixtures/mysql.json @@ -146,6 +146,7 @@ "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", "Tesseract: SQL API: Timeshift measure from cube", + "querying BigECommerce: multi-stage group by time dimension", "---------------------------------------", "Custom Granularities ", diff --git a/packages/cubejs-testing-drivers/fixtures/postgres.json b/packages/cubejs-testing-drivers/fixtures/postgres.json index 425f429f1ca75..fae424089f166 100644 --- a/packages/cubejs-testing-drivers/fixtures/postgres.json +++ b/packages/cubejs-testing-drivers/fixtures/postgres.json @@ -170,7 +170,8 @@ "querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", - "Tesseract: SQL API: Timeshift measure from cube" + "Tesseract: SQL API: Timeshift measure from cube", + "querying BigECommerce: multi-stage group by time dimension" ], "tesseractSkip": [ "querying Products: dimensions -- doesn't work wo ordering", diff --git a/packages/cubejs-testing-drivers/fixtures/redshift.json b/packages/cubejs-testing-drivers/fixtures/redshift.json index 1f875247ab784..8c019c86dd77c 100644 --- a/packages/cubejs-testing-drivers/fixtures/redshift.json +++ b/packages/cubejs-testing-drivers/fixtures/redshift.json @@ -182,10 +182,45 @@ "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", "Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", "Tesseract: SQL API: Timeshift measure from cube", + "querying BigECommerce: multi-stage group by time dimension", "---------------------------------------", "SKIPPED SQL API (Need work) ", "---------------------------------------", "SQL API: SQL push down push to cube quoted alias" + ], + "tesseractSkip": [ + "querying custom granularities ECommerce: count by three_months_by_march + no dimension", + "querying custom granularities ECommerce: count by three_months_by_march + dimension", + "querying Products: dimensions -- doesn't work wo ordering", + "querying ECommerce: total quantity, avg discount, total sales, total profit by product + order + total -- rounding in athena", + "querying ECommerce: total quantity, avg discount, total sales, total profit by product + order + total -- noisy test", + "querying custom granularities (with preaggregation) ECommerce: totalQuantity by half_year + no dimension", + "querying custom granularities (with preaggregation) ECommerce: totalQuantity by half_year + dimension", + "querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", + "querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", + "SQL API: Timeshift measure from cube", + + "querying BigECommerce: rolling window by 2 day without date range", + "querying BigECommerce: rolling window by 2 month without date range", + "querying BigECommerce: rolling window YTD without date range", + "querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByLeading without date range", + + "SQL API: Simple Rollup", + "SQL API: Complex Rollup", + "SQL API: Rollup with aliases", + "SQL API: Rollup over exprs", + "SQL API: Nested Rollup", + "SQL API: Nested Rollup with aliases", + "SQL API: Nested Rollup over asterisk", + "SQL API: Extended nested Rollup over asterisk", + "SQL API: SQL push down push to cube quoted alias", + + "---- Different results comparing to baseQuery version. Need to investigate ----", + "querying BigECommerce: rolling window YTD (month + week)", + "querying BigECommerce: rolling window YTD (month + week + no gran)", + "querying BigECommerce: rolling window YTD without granularity", + "SQL API: Rolling Window YTD (year + month + day + date_trunc equal)", + "SQL API: Rolling Window YTD (year + month + day + date_trunc IN)" ] } diff --git a/packages/cubejs-testing-drivers/fixtures/snowflake.json b/packages/cubejs-testing-drivers/fixtures/snowflake.json index 5ce6c0bab6ef9..cdc97106c8e95 100644 --- a/packages/cubejs-testing-drivers/fixtures/snowflake.json +++ b/packages/cubejs-testing-drivers/fixtures/snowflake.json @@ -246,6 +246,50 @@ "querying BigECommerce: rolling window YTD without date range", "querying BigECommerce with Retail Calendar: totalCountRetailYearAgo", "querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", - "querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo" + "querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", + "querying BigECommerce: multi-stage group by time dimension" + ], + "tesseractSkip": [ + "for the Customers.RollingExternal", + "for the Customers.RollingInternal", + "for the ECommerce.SimpleAnalysisExternal", + "for the ECommerce.SimpleAnalysisInternal", + "for the ECommerce.TimeAnalysisInternal", + "for the ECommerce.TimeAnalysisExternal", + "querying Products: dimensions -- doesn't work wo ordering", + "querying ECommerce: total quantity, avg discount, total sales, total profit by product + order + total -- rounding in athena", + "querying ECommerce: total sales, total profit by month + order (date) + total -- doesn't work with the BigQuery", + "querying ECommerce: total quantity, avg discount, total sales, total profit by product + order + total -- noisy test", + "querying BigECommerce: null sum", + "querying BigECommerce: null boolean", + "querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByLeading without date range", + + "querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo", + "querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo", + "SQL API: Timeshift measure from cube", + + "SQL API: Simple Rollup", + "SQL API: Complex Rollup", + "SQL API: Rollup with aliases", + "SQL API: Rollup over exprs", + "SQL API: Nested Rollup", + "SQL API: Nested Rollup with aliases", + "SQL API: Nested Rollup over asterisk", + "SQL API: Extended nested Rollup over asterisk", + "SQL API: SQL push down push to cube quoted alias", + + + + "querying BigECommerce: rolling window by 2 day without date range", + "querying BigECommerce: rolling window by 2 month without date range", + "querying BigECommerce: rolling window YTD without date range", + "querying custom granularities (with preaggregation) ECommerce: totalQuantity by half_year + no dimension", + + "---- Different results comparing to baseQuery version. Need to investigate ----", + "querying BigECommerce: rolling window YTD (month + week)", + "querying BigECommerce: rolling window YTD (month + week + no gran)", + "querying BigECommerce: rolling window YTD without granularity", + "SQL API: Rolling Window YTD (year + month + day + date_trunc equal)", + "SQL API: Rolling Window YTD (year + month + day + date_trunc IN)" ] } diff --git a/packages/cubejs-testing-drivers/src/tests/testQueries.ts b/packages/cubejs-testing-drivers/src/tests/testQueries.ts index 588aef55ea942..184cc9da45888 100644 --- a/packages/cubejs-testing-drivers/src/tests/testQueries.ts +++ b/packages/cubejs-testing-drivers/src/tests/testQueries.ts @@ -1564,6 +1564,28 @@ export function testQueries(type: string, { includeIncrementalSchemaSuite, exten expect(response.rawData()).toMatchSnapshot(); }); + execute('querying BigECommerce: multi-stage group by time dimension', async () => { + const response = await client.load({ + measures: [ + 'BigECommerce.totalProfit', + 'BigECommerce.totalProfitForQuarter' + ], + timeDimensions: [ + { + dimension: 'BigECommerce.orderDate', + granularity: 'quarter', + }, { + dimension: 'BigECommerce.orderDate', + granularity: 'month', + dateRange: ['2020-01-01', '2020-12-31'], + }], + order: [ + ['BigECommerce.orderDate', 'asc'], + ], + }); + expect(response.rawData()).toMatchSnapshot(); + }); + execute('querying BigECommerce: rolling window by 2 week', async () => { const response = await client.load({ measures: [ diff --git a/packages/cubejs-testing-drivers/test/__snapshots__/athena-export-bucket-s3-full.test.ts.snap b/packages/cubejs-testing-drivers/test/__snapshots__/athena-export-bucket-s3-full.test.ts.snap index 5f57696f312a4..71925c876adc2 100644 --- a/packages/cubejs-testing-drivers/test/__snapshots__/athena-export-bucket-s3-full.test.ts.snap +++ b/packages/cubejs-testing-drivers/test/__snapshots__/athena-export-bucket-s3-full.test.ts.snap @@ -30,6 +30,81 @@ Array [ ] `; +exports[`Queries with the @cubejs-backend/athena-driver querying BigECommerce: multi-stage group by time dimension 1`] = ` +Array [ + Object { + "BigECommerce.orderDate": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "29.65480", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "6.19920", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "583.59450", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "6.41760", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "353.68490", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "34.23610", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-07-01T00:00:00.000", + "BigECommerce.totalProfit": "461.13320", + "BigECommerce.totalProfitForQuarter": "461.13320", + }, + Object { + "BigECommerce.orderDate": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "139.99700", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, + Object { + "BigECommerce.orderDate": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "1132.66170", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, + Object { + "BigECommerce.orderDate": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "303.97370", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, +] +`; + exports[`Queries with the @cubejs-backend/athena-driver SQL API: Rolling Window YTD (year + month + day + date_trunc IN) 1`] = ` Array [ Object { diff --git a/packages/cubejs-testing-drivers/test/__snapshots__/bigquery-export-bucket-gcs-full.test.ts.snap b/packages/cubejs-testing-drivers/test/__snapshots__/bigquery-export-bucket-gcs-full.test.ts.snap index ce1b0de4f267c..18ce55e51a583 100644 --- a/packages/cubejs-testing-drivers/test/__snapshots__/bigquery-export-bucket-gcs-full.test.ts.snap +++ b/packages/cubejs-testing-drivers/test/__snapshots__/bigquery-export-bucket-gcs-full.test.ts.snap @@ -30,6 +30,81 @@ Array [ ] `; +exports[`Queries with the @cubejs-backend/bigquery-driver querying BigECommerce: multi-stage group by time dimension 1`] = ` +Array [ + Object { + "BigECommerce.orderDate": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "29.65480", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "6.19920", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "583.59450", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "6.41760", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "353.68490", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "34.23610", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-07-01T00:00:00.000", + "BigECommerce.totalProfit": "461.13320", + "BigECommerce.totalProfitForQuarter": "461.13320", + }, + Object { + "BigECommerce.orderDate": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "139.99700", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, + Object { + "BigECommerce.orderDate": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "1132.66170", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, + Object { + "BigECommerce.orderDate": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "303.97370", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, +] +`; + exports[`Queries with the @cubejs-backend/bigquery-driver SQL API: Nested Rollup 1`] = ` Array [ Object { diff --git a/packages/cubejs-testing-drivers/test/__snapshots__/databricks-jdbc-full.test.ts.snap b/packages/cubejs-testing-drivers/test/__snapshots__/databricks-jdbc-full.test.ts.snap index 768525e4489e2..14e1053b45d13 100644 --- a/packages/cubejs-testing-drivers/test/__snapshots__/databricks-jdbc-full.test.ts.snap +++ b/packages/cubejs-testing-drivers/test/__snapshots__/databricks-jdbc-full.test.ts.snap @@ -1,5 +1,79 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Queries with the @cubejs-backend/databricks-jdbc-driver querying BigECommerce: multi-stage group by time dimension 1`] = ` +Array [ + Object { + "BigECommerce.orderDate": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": 29.6548, + "BigECommerce.totalProfitForQuarter": 619.4485, + }, + Object { + "BigECommerce.orderDate": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": 6.1992, + "BigECommerce.totalProfitForQuarter": 619.4485, + }, + Object { + "BigECommerce.orderDate": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": 583.5945, + "BigECommerce.totalProfitForQuarter": 619.4485, + }, + Object { + "BigECommerce.orderDate": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": 6.4176, + "BigECommerce.totalProfitForQuarter": 394.3386, + }, + Object { + "BigECommerce.orderDate": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": 353.6849, + "BigECommerce.totalProfitForQuarter": 394.3386, + }, + Object { + "BigECommerce.orderDate": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": 34.2361, + "BigECommerce.totalProfitForQuarter": 394.3386, + }, + Object { + "BigECommerce.orderDate": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-07-01T00:00:00.000", + "BigECommerce.totalProfit": 461.1332, + "BigECommerce.totalProfitForQuarter": 461.1332, + }, + Object { + "BigECommerce.orderDate": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": 139.997, + "BigECommerce.totalProfitForQuarter": 1576.6324, + }, + Object { + "BigECommerce.orderDate": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": 1132.6617, + "BigECommerce.totalProfitForQuarter": 1576.6324, + }, + Object { + "BigECommerce.orderDate": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": 303.9737, + "BigECommerce.totalProfitForQuarter": 1576.6324, + }, +] +`; exports[`Queries with the @cubejs-backend/databricks-jdbc-driver SQL API: Complex Rollup 1`] = ` Array [ Object { diff --git a/packages/cubejs-testing-drivers/test/__snapshots__/postgres-full.test.ts.snap b/packages/cubejs-testing-drivers/test/__snapshots__/postgres-full.test.ts.snap index 20bcb0c7b8f4f..c3c890744fe26 100644 --- a/packages/cubejs-testing-drivers/test/__snapshots__/postgres-full.test.ts.snap +++ b/packages/cubejs-testing-drivers/test/__snapshots__/postgres-full.test.ts.snap @@ -11624,6 +11624,81 @@ Array [ ] `; +exports[`Queries with the @cubejs-backend/postgres-driver querying BigECommerce: multi-stage group by time dimension 1`] = ` +Array [ + Object { + "BigECommerce.orderDate": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "29.65480", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "6.19920", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "583.59450", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "6.41760", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "353.68490", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "34.23610", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-07-01T00:00:00.000", + "BigECommerce.totalProfit": "461.13320", + "BigECommerce.totalProfitForQuarter": "461.13320", + }, + Object { + "BigECommerce.orderDate": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "139.99700", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, + Object { + "BigECommerce.orderDate": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "1132.66170", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, + Object { + "BigECommerce.orderDate": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "303.97370", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, +] +`; + exports[`Queries with the @cubejs-backend/postgres-driver querying BigECommerce: null boolean 1`] = ` Array [ Object { diff --git a/packages/cubejs-testing-drivers/test/__snapshots__/redshift-full.test.ts.snap b/packages/cubejs-testing-drivers/test/__snapshots__/redshift-full.test.ts.snap index 95d5d9e95ab34..d869ceed038ea 100644 --- a/packages/cubejs-testing-drivers/test/__snapshots__/redshift-full.test.ts.snap +++ b/packages/cubejs-testing-drivers/test/__snapshots__/redshift-full.test.ts.snap @@ -1797,6 +1797,81 @@ Array [ ] `; +exports[`Queries with the @cubejs-backend/redshift-driver querying BigECommerce: multi-stage group by time dimension 1`] = ` +Array [ + Object { + "BigECommerce.orderDate": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "29.65480", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "6.19920", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "583.59450", + "BigECommerce.totalProfitForQuarter": "619.44850", + }, + Object { + "BigECommerce.orderDate": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "6.41760", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "353.68490", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "34.23610", + "BigECommerce.totalProfitForQuarter": "394.33860", + }, + Object { + "BigECommerce.orderDate": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-07-01T00:00:00.000", + "BigECommerce.totalProfit": "461.13320", + "BigECommerce.totalProfitForQuarter": "461.13320", + }, + Object { + "BigECommerce.orderDate": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "139.99700", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, + Object { + "BigECommerce.orderDate": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "1132.66170", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, + Object { + "BigECommerce.orderDate": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "303.97370", + "BigECommerce.totalProfitForQuarter": "1576.63240", + }, +] +`; + exports[`Queries with the @cubejs-backend/redshift-driver SQL API: Date/time comparison with SQL push down 1`] = ` Array [ Object { @@ -8825,6 +8900,334 @@ Array [ ] `; +exports[`Queries with the @cubejs-backend/redshift-driver Tesseract: SQL API: Timeshift measure from cube 1`] = ` +Array [ + Object { + "orderDate": 2020-01-01T00:00:00.000Z, + "totalQuantity": 6, + "totalQuantityPriorMonth": null, + }, + Object { + "orderDate": 2020-02-01T00:00:00.000Z, + "totalQuantity": 2, + "totalQuantityPriorMonth": 6, + }, + Object { + "orderDate": 2020-03-01T00:00:00.000Z, + "totalQuantity": 13, + "totalQuantityPriorMonth": 2, + }, + Object { + "orderDate": 2020-04-01T00:00:00.000Z, + "totalQuantity": 3, + "totalQuantityPriorMonth": 13, + }, + Object { + "orderDate": 2020-05-01T00:00:00.000Z, + "totalQuantity": 15, + "totalQuantityPriorMonth": 3, + }, + Object { + "orderDate": 2020-06-01T00:00:00.000Z, + "totalQuantity": 18, + "totalQuantityPriorMonth": 15, + }, + Object { + "orderDate": 2020-07-01T00:00:00.000Z, + "totalQuantity": null, + "totalQuantityPriorMonth": 18, + }, + Object { + "orderDate": 2020-09-01T00:00:00.000Z, + "totalQuantity": 27, + "totalQuantityPriorMonth": null, + }, + Object { + "orderDate": 2020-10-01T00:00:00.000Z, + "totalQuantity": 11, + "totalQuantityPriorMonth": 27, + }, + Object { + "orderDate": 2020-11-01T00:00:00.000Z, + "totalQuantity": 43, + "totalQuantityPriorMonth": 11, + }, + Object { + "orderDate": 2020-12-01T00:00:00.000Z, + "totalQuantity": 22, + "totalQuantityPriorMonth": 43, + }, +] +`; + +exports[`Queries with the @cubejs-backend/redshift-driver Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo 1`] = ` +Array [ + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailMonthAgo": "1", + "RetailCalendar.retail_date": "2020-02-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-02-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailMonthAgo": "1", + "RetailCalendar.retail_date": "2020-03-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-03-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailMonthAgo": "2", + "RetailCalendar.retail_date": "2020-04-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-04-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "5", + "BigECommerce.totalCountRetailMonthAgo": "1", + "RetailCalendar.retail_date": "2020-05-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-05-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "7", + "BigECommerce.totalCountRetailMonthAgo": "5", + "RetailCalendar.retail_date": "2020-06-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-06-01T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailMonthAgo": "7", + "RetailCalendar.retail_date": "2020-07-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-07-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "6", + "BigECommerce.totalCountRetailMonthAgo": null, + "RetailCalendar.retail_date": "2020-09-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-09-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "4", + "BigECommerce.totalCountRetailMonthAgo": "6", + "RetailCalendar.retail_date": "2020-10-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-10-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "9", + "BigECommerce.totalCountRetailMonthAgo": "5", + "RetailCalendar.retail_date": "2020-11-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-11-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "7", + "BigECommerce.totalCountRetailMonthAgo": "8", + "RetailCalendar.retail_date": "2020-12-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-12-01T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailMonthAgo": "7", + "RetailCalendar.retail_date": "2021-01-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2021-01-01T00:00:00.000", + }, +] +`; + +exports[`Queries with the @cubejs-backend/redshift-driver Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo 1`] = ` +Array [ + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-02-16T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-02-16T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-02-23T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-02-23T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-03-15T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-03-15T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-03-22T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-03-22T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-03-29T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-03-29T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-04-05T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-04-05T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-04-12T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-04-12T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-05-10T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-10T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-05-17T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-17T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-05-24T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-24T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-05-31T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-31T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-06-07T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-07T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-06-14T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-14T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-06-21T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-21T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-06-28T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-28T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-08-30T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-08-30T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-09-06T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-06T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-09-13T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-13T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-09-20T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-20T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-09-27T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-27T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-10-11T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-10-11T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-10-18T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-10-18T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-10-25T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-10-25T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-11-01T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-11-08T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-08T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-11-15T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-15T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-11-22T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-22T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-11-29T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-29T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-12-06T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-06T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-12-13T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-13T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-12-20T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-20T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-12-27T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-27T00:00:00.000", + }, +] +`; + exports[`Queries with the @cubejs-backend/redshift-driver filtering Customers: contains + dimensions, first 1`] = ` Array [ Object { @@ -11108,6 +11511,17 @@ Array [ ] `; +exports[`Queries with the @cubejs-backend/redshift-driver querying BigECommerce with Retail Calendar: totalCountRetailYearAgo 1`] = ` +Array [ + Object { + "BigECommerce.count": "42", + "BigECommerce.totalCountRetailYearAgo": "2", + "RetailCalendar.retail_date": "2020-02-02T00:00:00.000", + "RetailCalendar.retail_date.year": "2020-02-02T00:00:00.000", + }, +] +`; + exports[`Queries with the @cubejs-backend/redshift-driver querying BigECommerce: filtering with possible casts 1`] = ` Array [ Object { diff --git a/packages/cubejs-testing-drivers/test/__snapshots__/snowflake-full.test.ts.snap b/packages/cubejs-testing-drivers/test/__snapshots__/snowflake-full.test.ts.snap index 823c06e7c0ea0..80eeb0bd555d9 100644 --- a/packages/cubejs-testing-drivers/test/__snapshots__/snowflake-full.test.ts.snap +++ b/packages/cubejs-testing-drivers/test/__snapshots__/snowflake-full.test.ts.snap @@ -8833,6 +8833,334 @@ Array [ ] `; +exports[`Queries with the @cubejs-backend/snowflake-driver Tesseract: SQL API: Timeshift measure from cube 1`] = ` +Array [ + Object { + "orderDate": 2020-01-01T00:00:00.000Z, + "totalQuantity": 6, + "totalQuantityPriorMonth": null, + }, + Object { + "orderDate": 2020-02-01T00:00:00.000Z, + "totalQuantity": 2, + "totalQuantityPriorMonth": 6, + }, + Object { + "orderDate": 2020-03-01T00:00:00.000Z, + "totalQuantity": 13, + "totalQuantityPriorMonth": 2, + }, + Object { + "orderDate": 2020-04-01T00:00:00.000Z, + "totalQuantity": 3, + "totalQuantityPriorMonth": 13, + }, + Object { + "orderDate": 2020-05-01T00:00:00.000Z, + "totalQuantity": 15, + "totalQuantityPriorMonth": 3, + }, + Object { + "orderDate": 2020-06-01T00:00:00.000Z, + "totalQuantity": 18, + "totalQuantityPriorMonth": 15, + }, + Object { + "orderDate": 2020-07-01T00:00:00.000Z, + "totalQuantity": null, + "totalQuantityPriorMonth": 18, + }, + Object { + "orderDate": 2020-09-01T00:00:00.000Z, + "totalQuantity": 27, + "totalQuantityPriorMonth": null, + }, + Object { + "orderDate": 2020-10-01T00:00:00.000Z, + "totalQuantity": 11, + "totalQuantityPriorMonth": 27, + }, + Object { + "orderDate": 2020-11-01T00:00:00.000Z, + "totalQuantity": 43, + "totalQuantityPriorMonth": 11, + }, + Object { + "orderDate": 2020-12-01T00:00:00.000Z, + "totalQuantity": 22, + "totalQuantityPriorMonth": 43, + }, +] +`; + +exports[`Queries with the @cubejs-backend/snowflake-driver Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo 1`] = ` +Array [ + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailMonthAgo": "1", + "RetailCalendar.retail_date": "2020-02-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-02-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailMonthAgo": "1", + "RetailCalendar.retail_date": "2020-03-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-03-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailMonthAgo": "2", + "RetailCalendar.retail_date": "2020-04-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-04-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "5", + "BigECommerce.totalCountRetailMonthAgo": "1", + "RetailCalendar.retail_date": "2020-05-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-05-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "7", + "BigECommerce.totalCountRetailMonthAgo": "5", + "RetailCalendar.retail_date": "2020-06-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-06-01T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailMonthAgo": "7", + "RetailCalendar.retail_date": "2020-07-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-07-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "6", + "BigECommerce.totalCountRetailMonthAgo": null, + "RetailCalendar.retail_date": "2020-09-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-09-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "4", + "BigECommerce.totalCountRetailMonthAgo": "6", + "RetailCalendar.retail_date": "2020-10-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-10-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "9", + "BigECommerce.totalCountRetailMonthAgo": "5", + "RetailCalendar.retail_date": "2020-11-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-11-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "7", + "BigECommerce.totalCountRetailMonthAgo": "8", + "RetailCalendar.retail_date": "2020-12-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-12-01T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailMonthAgo": "7", + "RetailCalendar.retail_date": "2021-01-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2021-01-01T00:00:00.000", + }, +] +`; + +exports[`Queries with the @cubejs-backend/snowflake-driver Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo 1`] = ` +Array [ + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-02-16T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-02-16T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-02-23T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-02-23T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-03-15T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-03-15T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-03-22T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-03-22T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-03-29T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-03-29T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-04-05T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-04-05T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-04-12T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-04-12T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-05-10T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-10T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-05-17T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-17T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-05-24T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-24T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-05-31T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-31T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-06-07T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-07T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-06-14T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-14T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-06-21T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-21T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-06-28T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-28T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-08-30T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-08-30T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-09-06T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-06T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-09-13T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-13T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-09-20T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-20T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-09-27T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-27T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-10-11T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-10-11T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-10-18T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-10-18T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-10-25T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-10-25T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-11-01T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-11-08T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-08T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-11-15T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-15T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-11-22T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-22T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-11-29T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-29T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-12-06T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-06T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-12-13T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-13T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-12-20T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-20T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-12-27T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-27T00:00:00.000", + }, +] +`; + exports[`Queries with the @cubejs-backend/snowflake-driver filtering Customers: contains + dimensions, first 1`] = ` Array [ Object { @@ -11116,6 +11444,375 @@ Array [ ] `; +exports[`Queries with the @cubejs-backend/snowflake-driver querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo 1`] = ` +Array [ + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailMonthAgo": "1", + "RetailCalendar.retail_date": "2020-02-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-02-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailMonthAgo": "1", + "RetailCalendar.retail_date": "2020-03-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-03-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailMonthAgo": "2", + "RetailCalendar.retail_date": "2020-04-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-04-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "5", + "BigECommerce.totalCountRetailMonthAgo": "1", + "RetailCalendar.retail_date": "2020-05-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-05-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "7", + "BigECommerce.totalCountRetailMonthAgo": "5", + "RetailCalendar.retail_date": "2020-06-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-06-01T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailMonthAgo": "7", + "RetailCalendar.retail_date": "2020-07-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-07-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "6", + "BigECommerce.totalCountRetailMonthAgo": null, + "RetailCalendar.retail_date": "2020-09-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-09-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "4", + "BigECommerce.totalCountRetailMonthAgo": "6", + "RetailCalendar.retail_date": "2020-10-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-10-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "9", + "BigECommerce.totalCountRetailMonthAgo": "5", + "RetailCalendar.retail_date": "2020-11-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-11-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "7", + "BigECommerce.totalCountRetailMonthAgo": "8", + "RetailCalendar.retail_date": "2020-12-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2020-12-01T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailMonthAgo": "7", + "RetailCalendar.retail_date": "2021-01-01T00:00:00.000", + "RetailCalendar.retail_date.month": "2021-01-01T00:00:00.000", + }, +] +`; + +exports[`Queries with the @cubejs-backend/snowflake-driver querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo 1`] = ` +Array [ + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-02-16T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-02-16T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-02-23T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-02-23T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-03-15T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-03-15T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-03-22T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-03-22T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-03-29T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-03-29T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-04-05T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-04-05T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-04-12T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-04-12T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-05-10T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-10T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-05-17T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-17T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-05-24T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-24T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-05-31T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-05-31T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-06-07T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-07T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-06-14T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-14T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-06-21T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-21T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-06-28T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-06-28T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-08-30T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-08-30T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-09-06T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-06T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-09-13T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-13T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-09-20T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-20T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-09-27T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-09-27T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-10-11T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-10-11T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-10-18T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-10-18T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-10-25T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-10-25T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-11-01T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-01T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-11-08T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-08T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-11-15T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-15T00:00:00.000", + }, + Object { + "BigECommerce.count": "1", + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-11-22T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-22T00:00:00.000", + }, + Object { + "BigECommerce.count": "3", + "BigECommerce.totalCountRetailWeekAgo": "1", + "RetailCalendar.retail_date": "2020-11-29T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-11-29T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "3", + "RetailCalendar.retail_date": "2020-12-06T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-06T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": null, + "RetailCalendar.retail_date": "2020-12-13T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-13T00:00:00.000", + }, + Object { + "BigECommerce.count": "2", + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-12-20T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-20T00:00:00.000", + }, + Object { + "BigECommerce.count": null, + "BigECommerce.totalCountRetailWeekAgo": "2", + "RetailCalendar.retail_date": "2020-12-27T00:00:00.000", + "RetailCalendar.retail_date.week": "2020-12-27T00:00:00.000", + }, +] +`; + +exports[`Queries with the @cubejs-backend/snowflake-driver querying BigECommerce with Retail Calendar: totalCountRetailYearAgo 1`] = ` +Array [ + Object { + "BigECommerce.count": "42", + "BigECommerce.totalCountRetailYearAgo": "2", + "RetailCalendar.retail_date": "2020-02-02T00:00:00.000", + "RetailCalendar.retail_date.year": "2020-02-02T00:00:00.000", + }, +] +`; + +exports[`Queries with the @cubejs-backend/snowflake-driver querying BigECommerce: filtering with possible casts 1`] = ` +Array [ + Object { + "BigECommerce.orderDate": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-01-01T00:00:00.000", + "BigECommerce.totalSales": "48.896", + }, + Object { + "BigECommerce.orderDate": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-12-01T00:00:00.000", + "BigECommerce.totalSales": "232.880", + }, +] +`; + +exports[`Queries with the @cubejs-backend/snowflake-driver querying BigECommerce: multi-stage group by time dimension 1`] = ` +Array [ + Object { + "BigECommerce.orderDate": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-01-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "29.6548", + "BigECommerce.totalProfitForQuarter": "619.4485", + }, + Object { + "BigECommerce.orderDate": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-02-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "6.1992", + "BigECommerce.totalProfitForQuarter": "619.4485", + }, + Object { + "BigECommerce.orderDate": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-03-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-01-01T00:00:00.000", + "BigECommerce.totalProfit": "583.5945", + "BigECommerce.totalProfitForQuarter": "619.4485", + }, + Object { + "BigECommerce.orderDate": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-04-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "6.4176", + "BigECommerce.totalProfitForQuarter": "394.3386", + }, + Object { + "BigECommerce.orderDate": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-05-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "353.6849", + "BigECommerce.totalProfitForQuarter": "394.3386", + }, + Object { + "BigECommerce.orderDate": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-06-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-04-01T00:00:00.000", + "BigECommerce.totalProfit": "34.2361", + "BigECommerce.totalProfitForQuarter": "394.3386", + }, + Object { + "BigECommerce.orderDate": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-09-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-07-01T00:00:00.000", + "BigECommerce.totalProfit": "461.1332", + "BigECommerce.totalProfitForQuarter": "461.1332", + }, + Object { + "BigECommerce.orderDate": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-10-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "139.9970", + "BigECommerce.totalProfitForQuarter": "1576.6324", + }, + Object { + "BigECommerce.orderDate": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-11-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "1132.6617", + "BigECommerce.totalProfitForQuarter": "1576.6324", + }, + Object { + "BigECommerce.orderDate": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.month": "2020-12-01T00:00:00.000", + "BigECommerce.orderDate.quarter": "2020-10-01T00:00:00.000", + "BigECommerce.totalProfit": "303.9737", + "BigECommerce.totalProfitForQuarter": "1576.6324", + }, +] +`; + exports[`Queries with the @cubejs-backend/snowflake-driver querying BigECommerce: partitioned pre-agg 1`] = ` Array [ Object { @@ -18248,18 +18945,3 @@ Array [ }, ] `; - -exports[`Queries with the @cubejs-backend/snowflake-driver querying BigECommerce: filtering with possible casts 1`] = ` -Array [ - Object { - "BigECommerce.orderDate": "2020-01-01T00:00:00.000", - "BigECommerce.orderDate.month": "2020-01-01T00:00:00.000", - "BigECommerce.totalSales": "48.896", - }, - Object { - "BigECommerce.orderDate": "2020-12-01T00:00:00.000", - "BigECommerce.orderDate.month": "2020-12-01T00:00:00.000", - "BigECommerce.totalSales": "232.880", - }, -] -`; diff --git a/rust/cubesqlplanner/cubesqlplanner/src/physical_plan_builder/processors/multi_stage_measure_calculation.rs b/rust/cubesqlplanner/cubesqlplanner/src/physical_plan_builder/processors/multi_stage_measure_calculation.rs index d4de13e45af2e..73e15c5d527f8 100644 --- a/rust/cubesqlplanner/cubesqlplanner/src/physical_plan_builder/processors/multi_stage_measure_calculation.rs +++ b/rust/cubesqlplanner/cubesqlplanner/src/physical_plan_builder/processors/multi_stage_measure_calculation.rs @@ -26,7 +26,7 @@ impl<'a> LogicalNodeProcessor<'a, MultiStageMeasureCalculation> measure_calculation: &MultiStageMeasureCalculation, context: &PushDownBuilderContext, ) -> Result { - let query_tools = self.builder.query_tools(); + let (query_tools, templates) = self.builder.qtools_and_templates(); let from = self .builder .process_node(measure_calculation.source.as_ref(), context)?; @@ -81,7 +81,16 @@ impl<'a> LogicalNodeProcessor<'a, MultiStageMeasureCalculation> if let Some(reference) = references_builder.find_reference_for_member(&dim.full_name(), &None) { - Ok(format!("{}", reference)) + let table_ref = if let Some(table_name) = reference.source() { + format!("{}.", templates.quote_identifier(table_name)?) + } else { + format!("") + }; + Ok(format!( + "{}{}", + table_ref, + templates.quote_identifier(&reference.name())? + )) } else { Err(CubeError::internal(format!( "Alias not found for partition_by dimension {}", diff --git a/rust/cubesqlplanner/cubesqlplanner/src/planner/filter/base_filter.rs b/rust/cubesqlplanner/cubesqlplanner/src/planner/filter/base_filter.rs index 1c45f8cd1f043..a0a7b36fdd9f1 100644 --- a/rust/cubesqlplanner/cubesqlplanner/src/planner/filter/base_filter.rs +++ b/rust/cubesqlplanner/cubesqlplanner/src/planner/filter/base_filter.rs @@ -203,7 +203,6 @@ impl BaseFilter { let Some(granularity_obj) = GranularityHelper::make_granularity_obj( self.query_tools.cube_evaluator().clone(), &mut evaluator_compiler, - self.query_tools.timezone().clone(), &symbol.cube_name(), &symbol.name(), Some(query_granularity.clone()), diff --git a/rust/cubesqlplanner/cubesqlplanner/src/planner/planners/multi_stage/member_query_planner.rs b/rust/cubesqlplanner/cubesqlplanner/src/planner/planners/multi_stage/member_query_planner.rs index bdc8b1dea0728..fabc624dbf22f 100644 --- a/rust/cubesqlplanner/cubesqlplanner/src/planner/planners/multi_stage/member_query_planner.rs +++ b/rust/cubesqlplanner/cubesqlplanner/src/planner/planners/multi_stage/member_query_planner.rs @@ -132,7 +132,6 @@ impl MultiStageMemberQueryPlanner { let Some(granularity_obj) = GranularityHelper::make_granularity_obj( self.query_tools.cube_evaluator().clone(), &mut evaluator_compiler, - self.query_tools.timezone().clone(), &time_dimension.cube_name(), &time_dimension.name(), Some(query_granularity.clone()), diff --git a/rust/cubesqlplanner/cubesqlplanner/src/planner/query_properties.rs b/rust/cubesqlplanner/cubesqlplanner/src/planner/query_properties.rs index 5a9cb93ad1043..6da48c4558ab9 100644 --- a/rust/cubesqlplanner/cubesqlplanner/src/planner/query_properties.rs +++ b/rust/cubesqlplanner/cubesqlplanner/src/planner/query_properties.rs @@ -172,7 +172,6 @@ impl QueryProperties { let granularity_obj = GranularityHelper::make_granularity_obj( query_tools.cube_evaluator().clone(), &mut evaluator_compiler, - query_tools.timezone().clone(), &base_symbol.cube_name(), &base_symbol.name(), d.granularity.clone(), diff --git a/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/compiler.rs b/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/compiler.rs index 6d1bbd594624e..12efd20c67d74 100644 --- a/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/compiler.rs +++ b/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/compiler.rs @@ -120,13 +120,16 @@ impl Compiler { Ok(collector.extract_result()) } + pub fn timezone(&self) -> Tz { + self.timezone.clone() + } + pub fn compile_sql_call( &mut self, cube_name: &String, member_sql: Rc, ) -> Result, CubeError> { - let dep_builder = - DependenciesBuilder::new(self, self.cube_evaluator.clone(), self.timezone.clone()); + let dep_builder = DependenciesBuilder::new(self, self.cube_evaluator.clone()); let deps = dep_builder.build(cube_name.clone(), member_sql.clone())?; let sql_call = SqlCall::new(member_sql, deps); Ok(Rc::new(sql_call)) diff --git a/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/dependecy.rs b/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/dependecy.rs index 6016ce4f9758f..7cce841a308ef 100644 --- a/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/dependecy.rs +++ b/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/dependecy.rs @@ -4,7 +4,6 @@ use crate::cube_bridge::evaluator::{CallDep, CubeEvaluator}; use crate::cube_bridge::member_sql::MemberSql; use crate::planner::sql_evaluator::TimeDimensionSymbol; use crate::planner::GranularityHelper; -use chrono_tz::Tz; use cubenativeutils::CubeError; use std::collections::HashMap; use std::rc::Rc; @@ -65,19 +64,13 @@ pub enum Dependency { pub struct DependenciesBuilder<'a> { compiler: &'a mut Compiler, cube_evaluator: Rc, - timezone: Tz, } impl<'a> DependenciesBuilder<'a> { - pub fn new( - compiler: &'a mut Compiler, - cube_evaluator: Rc, - timezone: Tz, - ) -> Self { + pub fn new(compiler: &'a mut Compiler, cube_evaluator: Rc) -> Self { DependenciesBuilder { compiler, cube_evaluator, - timezone, } } @@ -173,7 +166,6 @@ impl<'a> DependenciesBuilder<'a> { if let Some(granularity_obj) = GranularityHelper::make_granularity_obj( self.cube_evaluator.clone(), self.compiler, - self.timezone.clone(), cube_name, &dep.name, Some(granularity.clone()), diff --git a/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/dimension_symbol.rs b/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/dimension_symbol.rs index 13d120f4fc114..f0246f5d71189 100644 --- a/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/dimension_symbol.rs +++ b/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/dimension_symbol.rs @@ -4,8 +4,10 @@ use crate::cube_bridge::dimension_definition::DimensionDefinition; use crate::cube_bridge::evaluator::CubeEvaluator; use crate::cube_bridge::member_sql::MemberSql; use crate::planner::query_tools::QueryTools; +use crate::planner::sql_evaluator::TimeDimensionSymbol; use crate::planner::sql_evaluator::{sql_nodes::SqlNode, Compiler, SqlCall, SqlEvaluatorVisitor}; use crate::planner::sql_templates::PlanSqlTemplates; +use crate::planner::GranularityHelper; use crate::planner::SqlInterval; use cubenativeutils::CubeError; use std::rc::Rc; @@ -287,6 +289,7 @@ impl DimensionSymbol { pub struct DimensionSymbolFactory { cube_name: String, name: String, + granularity: Option, sql: Option>, definition: Rc, cube_evaluator: Rc, @@ -302,10 +305,12 @@ impl DimensionSymbolFactory { .into_iter(); let cube_name = iter.next().unwrap(); let name = iter.next().unwrap(); + let granularity = iter.next(); let definition = cube_evaluator.dimension_by_path(full_name.clone())?; Ok(Self { cube_name, name, + granularity, sql: definition.sql()?, definition, cube_evaluator, @@ -338,6 +343,7 @@ impl SymbolFactory for DimensionSymbolFactory { let Self { cube_name, name, + granularity, sql, definition, cube_evaluator, @@ -477,9 +483,9 @@ impl SymbolFactory for DimensionSymbolFactory { && longitude.is_none() && !is_multi_stage); - Ok(MemberSymbol::new_dimension(DimensionSymbol::new( - cube_name, - name, + let symbol = MemberSymbol::new_dimension(DimensionSymbol::new( + cube_name.clone(), + name.clone(), alias, sql, is_reference, @@ -491,6 +497,32 @@ impl SymbolFactory for DimensionSymbolFactory { time_shift, time_shift_pk, is_self_time_shift_pk, - ))) + )); + + if let Some(granularity) = &granularity { + if let Some(granularity_obj) = GranularityHelper::make_granularity_obj( + cube_evaluator.clone(), + compiler, + &cube_name, + &name, + Some(granularity.clone()), + )? { + let time_dim_symbol = MemberSymbol::new_time_dimension(TimeDimensionSymbol::new( + symbol, + Some(granularity.clone()), + Some(granularity_obj), + None, + )); + return Ok(time_dim_symbol); + } else { + return Err(CubeError::user(format!( + "Undefined granularity {} for time dimension {}", + granularity, + symbol.full_name() + ))); + } + } + + Ok(symbol) } } diff --git a/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/time_dimension_symbol.rs b/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/time_dimension_symbol.rs index 4db4ab24b61fe..f9cc2d9491cf5 100644 --- a/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/time_dimension_symbol.rs +++ b/rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/time_dimension_symbol.rs @@ -79,7 +79,6 @@ impl TimeDimensionSymbol { let new_granularity_obj = GranularityHelper::make_granularity_obj( query_tools.cube_evaluator().clone(), &mut evaluator_compiler, - query_tools.timezone(), &&self.base_symbol.cube_name(), &self.base_symbol.name(), new_granularity.clone(), diff --git a/rust/cubesqlplanner/cubesqlplanner/src/planner/time_dimension/granularity_helper.rs b/rust/cubesqlplanner/cubesqlplanner/src/planner/time_dimension/granularity_helper.rs index d53ab63a24027..10bd055b21741 100644 --- a/rust/cubesqlplanner/cubesqlplanner/src/planner/time_dimension/granularity_helper.rs +++ b/rust/cubesqlplanner/cubesqlplanner/src/planner/time_dimension/granularity_helper.rs @@ -224,11 +224,11 @@ impl GranularityHelper { pub fn make_granularity_obj( cube_evaluator: Rc, compiler: &mut Compiler, - timezone: Tz, cube_name: &String, name: &String, granularity: Option, ) -> Result, CubeError> { + let timezone = compiler.timezone(); let granularity_obj = if let Some(granularity) = &granularity { let path = vec![ cube_name.clone(),