Skip to content

Commit

Permalink
fix(cubesql): ungrouped query can be routed to Cube Store (#7810)
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov authored Feb 25, 2024
1 parent 754a0df commit b122837
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ export class BaseQuery {
}

externalPreAggregationQuery() {
if (!this.options.preAggregationQuery && !this.options.disableExternalPreAggregations && this.externalQueryClass) {
if (!this.options.preAggregationQuery && !this.options.disableExternalPreAggregations && !this.ungrouped && this.externalQueryClass) {
const preAggregationForQuery = this.preAggregations.findPreAggregationForQuery();
if (preAggregationForQuery && preAggregationForQuery.preAggregation.external) {
return true;
Expand All @@ -558,7 +558,7 @@ export class BaseQuery {
* @returns {Array<string>}
*/
buildSqlAndParams(exportAnnotatedSql) {
if (!this.options.preAggregationQuery && !this.options.disableExternalPreAggregations && this.externalQueryClass) {
if (!this.options.preAggregationQuery && !this.options.disableExternalPreAggregations && !this.ungrouped && this.externalQueryClass) {
if (this.externalPreAggregationQuery()) { // TODO performance
return this.externalQuery().buildSqlAndParams(exportAnnotatedSql);
}
Expand Down
22 changes: 22 additions & 0 deletions packages/cubejs-testing-drivers/src/tests/testQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1500,5 +1500,27 @@ from
`);
expect(res.rows).toMatchSnapshot('powerbi_min_max_push_down');
});

executePg('SQL API: powerbi min max ungrouped flag', async () => {
const res = await connection.query(`
select
count(distinct("rows"."totalSales")) + max(
case
when "rows"."totalSales" is null then 1
else 0
end
) as "a0",
min("rows"."totalSales") as "a1",
max("rows"."totalSales") as "a2"
from
(
select
"totalSales"
from
"public"."ECommerce" "$Table"
) "rows"
`);
expect(res.rows).toMatchSnapshot('powerbi_min_max_ungrouped_flag');
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ Array [
]
`;

exports[`Queries with the @cubejs-backend/postgres-driver SQL API: powerbi min max ungrouped flag: powerbi_min_max_ungrouped_flag 1`] = `
Array [
Object {
"a0": "39",
"a1": 3.76,
"a2": 2399.96,
},
]
`;

exports[`Queries with the @cubejs-backend/postgres-driver filtering Customers: contains + dimensions, first 1`] = `
Array [
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ Array [
]
`;

exports[`Queries with the @cubejs-backend/snowflake-driver SQL API: powerbi min max ungrouped flag: powerbi_min_max_ungrouped_flag 1`] = `
Array [
Object {
"a0": "39",
"a1": 3.76,
"a2": 2399.96,
},
]
`;

exports[`Queries with the @cubejs-backend/snowflake-driver filtering Customers: contains + dimensions, first 1`] = `
Array [
Object {
Expand Down

0 comments on commit b122837

Please sign in to comment.