Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cubejs-testing-drivers/fixtures/athena.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
"querying SwitchSourceTest: simple cross join",
"querying SwitchSourceTest: full cross join",
"querying SwitchSourceTest: filter by switch dimensions",
"querying BigECommerce: SeveralMultiStageMeasures",

"---------------------------------------",
"Custom Granularities ",
Expand Down Expand Up @@ -198,6 +199,7 @@
"Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo",
"SQL API: Timeshift measure from cube",
"querying BigECommerce: multi-stage group by time dimension",
"querying BigECommerce: SeveralMultiStageMeasures",

"querying BigECommerce: rolling window by 2 week",
"querying custom granularities ECommerce: count by three_months_by_march + no dimension",
Expand Down
1 change: 1 addition & 0 deletions packages/cubejs-testing-drivers/fixtures/bigquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
"querying BigECommerce: rolling count_distinct_approx window by 2 week",
"querying BigECommerce: rolling count_distinct_approx window by 2 month",
"querying BigECommerce: totalProfitYearAgo",
"querying BigECommerce: SeveralMultiStageMeasures",
"SQL API: post-aggregate percentage of total",
"SQL API: Simple Rollup",
"SQL API: Rollup over exprs",
Expand Down
1 change: 1 addition & 0 deletions packages/cubejs-testing-drivers/fixtures/clickhouse.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
"querying SwitchSourceTest: simple cross join",
"querying SwitchSourceTest: full cross join",
"querying SwitchSourceTest: filter by switch dimensions",
"querying BigECommerce: SeveralMultiStageMeasures",

"---------------------------------------",
"Custom Granularities ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
"Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailMonthAgo",
"Tesseract: querying BigECommerce with Retail Calendar: totalCountRetailWeekAgo",
"Tesseract: SQL API: Timeshift measure from cube",
"querying BigECommerce: SeveralMultiStageMeasures",

"---- Different results comparing to baseQuery version. Need to investigate ----",
"querying ECommerce: dimensions",
Expand Down
1 change: 1 addition & 0 deletions packages/cubejs-testing-drivers/fixtures/mssql.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"querying SwitchSourceTest: simple cross join",
"querying SwitchSourceTest: full cross join",
"querying SwitchSourceTest: filter by switch dimensions",
"querying BigECommerce: SeveralMultiStageMeasures",

"---------------------------------------",
"SKIPPED SQL API (Need work)",
Expand Down
1 change: 1 addition & 0 deletions packages/cubejs-testing-drivers/fixtures/mysql.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"querying SwitchSourceTest: simple cross join",
"querying SwitchSourceTest: full cross join",
"querying SwitchSourceTest: filter by switch dimensions",
"querying BigECommerce: SeveralMultiStageMeasures",

"---------------------------------------",
"Custom Granularities ",
Expand Down
3 changes: 2 additions & 1 deletion packages/cubejs-testing-drivers/fixtures/postgres.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@
"querying BigECommerce: multi-stage group by time dimension",
"querying SwitchSourceTest: simple cross join",
"querying SwitchSourceTest: full cross join",
"querying SwitchSourceTest: filter by switch dimensions"
"querying SwitchSourceTest: filter by switch dimensions",
"querying BigECommerce: SeveralMultiStageMeasures"
],
"tesseractSkip": [
"querying Products: dimensions -- doesn't work wo ordering",
Expand Down
2 changes: 2 additions & 0 deletions packages/cubejs-testing-drivers/fixtures/redshift.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"querying SwitchSourceTest: simple cross join",
"querying SwitchSourceTest: full cross join",
"querying SwitchSourceTest: filter by switch dimensions",
"querying BigECommerce: SeveralMultiStageMeasures",

"---------------------------------------",
"SKIPPED SQL API (Need work) ",
Expand All @@ -210,6 +211,7 @@
"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",
"querying BigECommerce: SeveralMultiStageMeasures",

"SQL API: Simple Rollup",
"SQL API: Complex Rollup",
Expand Down
3 changes: 2 additions & 1 deletion packages/cubejs-testing-drivers/fixtures/snowflake.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@
"querying BigECommerce: multi-stage group by time dimension",
"querying SwitchSourceTest: simple cross join",
"querying SwitchSourceTest: full cross join",
"querying SwitchSourceTest: filter by switch dimensions"
"querying SwitchSourceTest: filter by switch dimensions",
"querying BigECommerce: SeveralMultiStageMeasures"
],
"tesseractSkip": [
"for the Customers.RollingExternal",
Expand Down
17 changes: 17 additions & 0 deletions packages/cubejs-testing-drivers/src/tests/testQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,23 @@ export function testQueries(type: string, { includeIncrementalSchemaSuite, exten
expect(response.rawData()).toMatchSnapshot();
});

execute('querying BigECommerce: SeveralMultiStageMeasures', async () => {
const response = await client.load({
measures: [
'BigECommerce.totalProfitYearAgo',
'BigECommerce.percentageOfTotalForStatus',
'BigECommerce.totalCountRetailMonthAgo',
'BigECommerce.count',
],
timeDimensions: [{
dimension: 'BigECommerce.orderDate',
granularity: 'month',
dateRange: ['2020-01-01', '2020-12-31'],
}],
});
expect(response.rawData()).toMatchSnapshot();
});

execute('querying BigECommerce: filtering with possible casts', async () => {
const response = await client.load({
measures: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15545,6 +15545,99 @@ Array [
]
`;

exports[`Queries with the @cubejs-backend/postgres-driver querying BigECommerce: SeveralMultiStageMeasures 1`] = `
Array [
Object {
"BigECommerce.count": "2",
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": null,
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "1",
"BigECommerce.orderDate": "2020-02-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-02-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "2",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "2",
"BigECommerce.orderDate": "2020-03-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-03-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "1",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "1",
"BigECommerce.orderDate": "2020-04-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-04-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "2",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "5",
"BigECommerce.orderDate": "2020-05-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-05-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "1",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "7",
"BigECommerce.orderDate": "2020-06-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-06-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "5",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": null,
"BigECommerce.orderDate": "2020-07-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-07-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": null,
"BigECommerce.totalCountRetailMonthAgo": "7",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "6",
"BigECommerce.orderDate": "2020-09-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-09-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": null,
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "4",
"BigECommerce.orderDate": "2020-10-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-10-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "6",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "9",
"BigECommerce.orderDate": "2020-11-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-11-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "4",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "7",
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "9",
"BigECommerce.totalProfitYearAgo": null,
},
]
`;

exports[`Queries with the @cubejs-backend/postgres-driver querying BigECommerce: filtering with possible casts 1`] = `
Array [
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15659,6 +15659,99 @@ Array [
]
`;

exports[`Queries with the @cubejs-backend/snowflake-driver querying BigECommerce: SeveralMultiStageMeasures 1`] = `
Array [
Object {
"BigECommerce.count": "2",
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": null,
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "1",
"BigECommerce.orderDate": "2020-02-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-02-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "2",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "2",
"BigECommerce.orderDate": "2020-03-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-03-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "1",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "1",
"BigECommerce.orderDate": "2020-04-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-04-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "2",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "5",
"BigECommerce.orderDate": "2020-05-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-05-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "1",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "7",
"BigECommerce.orderDate": "2020-06-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-06-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "5",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": null,
"BigECommerce.orderDate": "2020-07-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-07-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": null,
"BigECommerce.totalCountRetailMonthAgo": "7",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "6",
"BigECommerce.orderDate": "2020-09-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-09-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": null,
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "4",
"BigECommerce.orderDate": "2020-10-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-10-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "6",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "9",
"BigECommerce.orderDate": "2020-11-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-11-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "4",
"BigECommerce.totalProfitYearAgo": null,
},
Object {
"BigECommerce.count": "7",
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
"BigECommerce.percentageOfTotalForStatus": "100",
"BigECommerce.totalCountRetailMonthAgo": "9",
"BigECommerce.totalProfitYearAgo": null,
},
]
`;

exports[`Queries with the @cubejs-backend/snowflake-driver querying BigECommerce: filtering with possible casts 1`] = `
Array [
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::context::PushDownBuilderContext;
use super::{LogicalNodeProcessor, ProcessableNode};
use crate::logical_plan::*;
use crate::physical_plan_builder::context::MultiStageDimensionContext;
use crate::plan::join::JoinType;
use crate::plan::schema::QualifiedColumnName;
use crate::plan::*;
use crate::planner::query_properties::OrderByItem;
Expand Down Expand Up @@ -39,6 +40,10 @@ impl PhysicalPlanBuilder {
(&self.query_tools, &self.plan_sql_templates)
}

pub(super) fn templates(&self) -> &PlanSqlTemplates {
&self.plan_sql_templates
}

pub(super) fn process_node<T: ProcessableNode>(
&self,
logical_node: &T,
Expand Down Expand Up @@ -214,4 +219,59 @@ impl PhysicalPlanBuilder {
}
Ok(result)
}

pub(super) fn process_query_dimension(
&self,
dimension: &Rc<MemberSymbol>,
references_builder: &ReferencesBuilder,
select_builder: &mut SelectBuilder,
context_factory: &mut SqlNodesFactory,
context: &PushDownBuilderContext,
) -> Result<(), CubeError> {
if let Some(coalesce_ref) = self.dimension_coalesce_refs(dimension, select_builder.from()) {
select_builder.add_projection_coalesce_member(dimension, coalesce_ref, None)?;
} else {
references_builder.resolve_references_for_member(
dimension.clone(),
&None,
context_factory.render_references_mut(),
)?;
if context.measure_subquery {
select_builder.add_projection_member_without_schema(dimension, None);
} else {
select_builder.add_projection_member(dimension, None);
}
}
Ok(())
}

fn dimension_coalesce_refs(
&self,
dimension: &Rc<MemberSymbol>,
from: &Rc<From>,
) -> Option<Vec<QualifiedColumnName>> {
match &from.source {
FromSource::Join(join) => {
if join.joins.iter().any(|i| i.join_type == JoinType::Full) {
let mut result = vec![];
let dim_alias = join.root.source.schema().resolve_member_alias(dimension);
result.push(QualifiedColumnName::new(
Some(join.root.alias.clone()),
dim_alias,
));
for item in join.joins.iter() {
let dim_alias = item.from.source.schema().resolve_member_alias(dimension);
result.push(QualifiedColumnName::new(
Some(item.from.alias.clone()),
dim_alias,
));
}
Some(result)
} else {
None
}
}
_ => None,
}
}
}
Loading
Loading