From 90875b98adbf140054ab006aacbaefcd68f84d7e Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Fri, 29 Aug 2025 12:05:28 +0200 Subject: [PATCH 01/10] fix(tesseract): Dimnesions with granularity in group_by + drivers support --- .../postgres/sql-generation.test.ts | 190 ++++++++++++++++++ .../src/planner/filter/base_filter.rs | 1 - .../multi_stage/member_query_planner.rs | 1 - .../src/planner/query_properties.rs | 1 - .../src/planner/sql_evaluator/compiler.rs | 7 +- .../src/planner/sql_evaluator/dependecy.rs | 10 +- .../sql_evaluator/symbols/dimension_symbol.rs | 40 +++- .../symbols/time_dimension_symbol.rs | 1 - .../time_dimension/granularity_helper.rs | 2 +- 9 files changed, 233 insertions(+), 20 deletions(-) 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..b12c7b01c9607 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/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(), From f1861fcfc8092c611d81814b3f9ca4d99fe5e79e Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Fri, 29 Aug 2025 12:13:49 +0200 Subject: [PATCH 02/10] lint --- .../postgres/sql-generation.test.ts | 274 +++++++++--------- 1 file changed, 137 insertions(+), 137 deletions(-) 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 b12c7b01c9607..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 @@ -4447,177 +4447,177 @@ 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'] - }, + it('multi stage sum with group by time dim with granularity', async () => runQueryTest( { - 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' - }], - }, + 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__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__revenue: '300' }, { 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 () => { + 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 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'] - }, + it('multi stage sum multiple time dims group by time dim with granularity', async () => runQueryTest( { - 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' - }], - }, + 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( { - 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' + 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: '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' - } - ] - )); + + [ + + { + 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 From 9d26c361eb4c7baa8e2903cc4e96ae1d48e02309 Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Fri, 29 Aug 2025 17:30:41 +0200 Subject: [PATCH 03/10] drivers --- .github/workflows/drivers-tests.yml | 4 + .../src/adapter/RedshiftQuery.ts | 9 + .../fixtures/_schemas.json | 7 + .../fixtures/athena.json | 1 + .../fixtures/bigquery.json | 1 + .../fixtures/clickhouse.json | 1 + .../fixtures/databricks-jdbc.json | 1 + .../fixtures/mssql.json | 1 + .../fixtures/mysql.json | 1 + .../fixtures/postgres.json | 3 +- .../fixtures/redshift.json | 35 + .../fixtures/snowflake.json | 46 +- .../src/tests/testQueries.ts | 22 + .../athena-export-bucket-s3-full.test.ts.snap | 75 ++ ...gquery-export-bucket-gcs-full.test.ts.snap | 75 ++ .../databricks-jdbc-full.test.ts.snap | 74 ++ .../__snapshots__/postgres-full.test.ts.snap | 75 ++ .../__snapshots__/redshift-full.test.ts.snap | 414 ++++++++++ .../__snapshots__/snowflake-full.test.ts.snap | 712 +++++++++++++++++- .../optimizers/pre_aggregation/optimizer.rs | 3 +- 20 files changed, 1542 insertions(+), 18 deletions(-) diff --git a/.github/workflows/drivers-tests.yml b/.github/workflows/drivers-tests.yml index 7f16a79527882..46684054faca0 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-full + use_tesseract_sql_planner: true + - database: redshift-full + 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-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..0e4abd560b52f 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 ", diff --git a/packages/cubejs-testing-drivers/fixtures/bigquery.json b/packages/cubejs-testing-drivers/fixtures/bigquery.json index 0564ff0160bd2..a7fa69cccfbf7 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)", 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..9de9c246d82cb 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..2091067bca09d 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-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/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..ca08322e18292 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 @@ -1,5 +1,80 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +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.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/snowflake-driver SQL API: Complex Rollup 1`] = ` Array [ Object { @@ -8833,6 +8908,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 +11519,300 @@ 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: 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/logical_plan/optimizers/pre_aggregation/optimizer.rs b/rust/cubesqlplanner/cubesqlplanner/src/logical_plan/optimizers/pre_aggregation/optimizer.rs index d0d877d48d856..cb471a9267c24 100644 --- a/rust/cubesqlplanner/cubesqlplanner/src/logical_plan/optimizers/pre_aggregation/optimizer.rs +++ b/rust/cubesqlplanner/cubesqlplanner/src/logical_plan/optimizers/pre_aggregation/optimizer.rs @@ -49,9 +49,10 @@ impl PreAggregationOptimizer { query: Rc, pre_aggregation: &Rc, ) -> Result>, CubeError> { + let is_external = pre_aggregation.external.unwrap_or_default(); if query.multistage_members.is_empty() { self.try_rewrite_simple_query(&query, pre_aggregation) - } else if !self.allow_multi_stage { + } else if is_external && !self.allow_multi_stage { Ok(None) } else { self.try_rewrite_query_with_multistages(&query, pre_aggregation) From 6ebcccf524c9110182abb96bd1936187bfde418d Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Fri, 29 Aug 2025 17:37:56 +0200 Subject: [PATCH 04/10] fix --- packages/cubejs-testing-drivers/src/tests/testQueries.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cubejs-testing-drivers/src/tests/testQueries.ts b/packages/cubejs-testing-drivers/src/tests/testQueries.ts index 9de9c246d82cb..184cc9da45888 100644 --- a/packages/cubejs-testing-drivers/src/tests/testQueries.ts +++ b/packages/cubejs-testing-drivers/src/tests/testQueries.ts @@ -1575,10 +1575,10 @@ export function testQueries(type: string, { includeIncrementalSchemaSuite, exten dimension: 'BigECommerce.orderDate', granularity: 'quarter', }, { - dimension: 'BigECommerce.orderDate', - granularity: 'month', - dateRange: ['2020-01-01', '2020-12-31'], - }], + dimension: 'BigECommerce.orderDate', + granularity: 'month', + dateRange: ['2020-01-01', '2020-12-31'], + }], order: [ ['BigECommerce.orderDate', 'asc'], ], From 689bb82d3b3293aa5d68d93da0a7cf7f7adb9ad6 Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Fri, 29 Aug 2025 17:56:10 +0200 Subject: [PATCH 05/10] fix --- .github/workflows/drivers-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/drivers-tests.yml b/.github/workflows/drivers-tests.yml index 46684054faca0..994d995417434 100644 --- a/.github/workflows/drivers-tests.yml +++ b/.github/workflows/drivers-tests.yml @@ -269,9 +269,9 @@ jobs: include: - database: postgres use_tesseract_sql_planner: true - - database: snowflake-full + - database: snowflake use_tesseract_sql_planner: true - - database: redshift-full + - database: redshift use_tesseract_sql_planner: true - database: bigquery-export-bucket-gcs use_tesseract_sql_planner: true From 31e6e5cff63dfe1ec7e22c37c6ded3b545ed3b49 Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Fri, 29 Aug 2025 18:33:44 +0200 Subject: [PATCH 06/10] fix --- .../src/logical_plan/optimizers/pre_aggregation/optimizer.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rust/cubesqlplanner/cubesqlplanner/src/logical_plan/optimizers/pre_aggregation/optimizer.rs b/rust/cubesqlplanner/cubesqlplanner/src/logical_plan/optimizers/pre_aggregation/optimizer.rs index cb471a9267c24..d0d877d48d856 100644 --- a/rust/cubesqlplanner/cubesqlplanner/src/logical_plan/optimizers/pre_aggregation/optimizer.rs +++ b/rust/cubesqlplanner/cubesqlplanner/src/logical_plan/optimizers/pre_aggregation/optimizer.rs @@ -49,10 +49,9 @@ impl PreAggregationOptimizer { query: Rc, pre_aggregation: &Rc, ) -> Result>, CubeError> { - let is_external = pre_aggregation.external.unwrap_or_default(); if query.multistage_members.is_empty() { self.try_rewrite_simple_query(&query, pre_aggregation) - } else if is_external && !self.allow_multi_stage { + } else if !self.allow_multi_stage { Ok(None) } else { self.try_rewrite_query_with_multistages(&query, pre_aggregation) From 678e2cb50fd81b37d10231a61f7231408c20ce3a Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Fri, 29 Aug 2025 19:02:47 +0200 Subject: [PATCH 07/10] fix --- packages/cubejs-testing-drivers/fixtures/snowflake.json | 1 + .../test/__snapshots__/databricks-jdbc-full.test.ts.snap | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/cubejs-testing-drivers/fixtures/snowflake.json b/packages/cubejs-testing-drivers/fixtures/snowflake.json index cdc97106c8e95..43c3f38d660ef 100644 --- a/packages/cubejs-testing-drivers/fixtures/snowflake.json +++ b/packages/cubejs-testing-drivers/fixtures/snowflake.json @@ -278,6 +278,7 @@ "SQL API: Extended nested Rollup over asterisk", "SQL API: SQL push down push to cube quoted alias", + "querying BigECommerce: multi-stage group by time dimension", "querying BigECommerce: rolling window by 2 day without date range", 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 2091067bca09d..2b06d66dc9aef 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,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Queries with the @cubejs-backend/databricks-driver querying BigECommerce: multi-stage group by time dimension 1`] = ` +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", From 8ae4bc4ece82016e8ba2b8126907c1177ff2080e Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Fri, 29 Aug 2025 19:32:09 +0200 Subject: [PATCH 08/10] fix --- .../fixtures/bigquery.json | 1 + .../fixtures/snowflake.json | 1 - .../databricks-jdbc-full.test.ts.snap | 40 ++--- .../__snapshots__/snowflake-full.test.ts.snap | 150 +++++++++--------- .../multi_stage_measure_calculation.rs | 13 +- 5 files changed, 107 insertions(+), 98 deletions(-) diff --git a/packages/cubejs-testing-drivers/fixtures/bigquery.json b/packages/cubejs-testing-drivers/fixtures/bigquery.json index a7fa69cccfbf7..a83f3b47b2cd2 100644 --- a/packages/cubejs-testing-drivers/fixtures/bigquery.json +++ b/packages/cubejs-testing-drivers/fixtures/bigquery.json @@ -224,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/snowflake.json b/packages/cubejs-testing-drivers/fixtures/snowflake.json index 43c3f38d660ef..cdc97106c8e95 100644 --- a/packages/cubejs-testing-drivers/fixtures/snowflake.json +++ b/packages/cubejs-testing-drivers/fixtures/snowflake.json @@ -278,7 +278,6 @@ "SQL API: Extended nested Rollup over asterisk", "SQL API: SQL push down push to cube quoted alias", - "querying BigECommerce: multi-stage group by time dimension", "querying BigECommerce: rolling window by 2 day without date range", 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 2b06d66dc9aef..afa422bcc2bee 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 @@ -6,71 +6,71 @@ Array [ "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", + "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.19920", - "BigECommerce.totalProfitForQuarter": "619.44850", + "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.59450", - "BigECommerce.totalProfitForQuarter": "619.44850", + "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.41760", - "BigECommerce.totalProfitForQuarter": "394.33860", + "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.68490", - "BigECommerce.totalProfitForQuarter": "394.33860", + "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.23610", - "BigECommerce.totalProfitForQuarter": "394.33860", + "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.13320", - "BigECommerce.totalProfitForQuarter": "461.13320", + "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.99700", - "BigECommerce.totalProfitForQuarter": "1576.63240", + "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.66170", - "BigECommerce.totalProfitForQuarter": "1576.63240", + "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", + "BigECommerce.totalProfit": 303.9737, + "BigECommerce.totalProfitForQuarter": 1576.6324, }, ] `; 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 ca08322e18292..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 @@ -1,80 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -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.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/snowflake-driver SQL API: Complex Rollup 1`] = ` Array [ Object { @@ -11813,6 +11738,81 @@ Array [ ] `; +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 { 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 {}", From 85c9021bc767a852a9a3e48353df1fc4c34caa23 Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Fri, 29 Aug 2025 19:55:47 +0200 Subject: [PATCH 09/10] fix --- .../test/__snapshots__/databricks-jdbc-full.test.ts.snap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 afa422bcc2bee..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 @@ -48,7 +48,7 @@ Array [ "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.totalProfit": 461.1332, "BigECommerce.totalProfitForQuarter": 461.1332, }, Object { @@ -62,8 +62,8 @@ Array [ "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, + "BigECommerce.totalProfit": 1132.6617, + "BigECommerce.totalProfitForQuarter": 1576.6324, }, Object { "BigECommerce.orderDate": "2020-12-01T00:00:00.000", From bc0704efe4e536439a6f43b89ae33e3364efa14b Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Fri, 29 Aug 2025 20:26:19 +0200 Subject: [PATCH 10/10] fix --- packages/cubejs-testing-drivers/fixtures/athena.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cubejs-testing-drivers/fixtures/athena.json b/packages/cubejs-testing-drivers/fixtures/athena.json index 0e4abd560b52f..13e148d474467 100644 --- a/packages/cubejs-testing-drivers/fixtures/athena.json +++ b/packages/cubejs-testing-drivers/fixtures/athena.json @@ -192,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",