Skip to content

Commit

Permalink
fix: Unexpected keyword WITH for rolling window measures in BigQuery
Browse files Browse the repository at this point in the history
Fixes #8193
  • Loading branch information
paveltiunov committed May 3, 2024
1 parent 617fd11 commit 9468f90
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ export class BaseQuery {
}

wrapInParenthesis(select) {
return select.trim().match(/^SELECT/ig) ? `(${select})` : select;
return select.trim().match(/^[a-zA-Z0-9_\-`".*]+$/i) ? select : `(${select})`;
}

withQueries(select, withQueries) {
Expand Down
5 changes: 1 addition & 4 deletions packages/cubejs-testing-drivers/fixtures/bigquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@
"querying BigECommerce: null boolean",
"--------------------",
"week granularity is not supported for intervals",
"--------------------",
"querying BigECommerce: rolling window by 2 day",
"querying BigECommerce: rolling window by 2 week",
"querying BigECommerce: rolling window by 2 month"
"--------------------"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,6 @@ Array [
]
`;

exports[`Queries with the @cubejs-backend/bigquery-driver querying BigECommerce: totalProfitYearAgo 1`] = `Array []`;

exports[`Queries with the @cubejs-backend/bigquery-driver filtering Customers: endsWith filter + dimensions, third 1`] = `Array []`;

exports[`Queries with the @cubejs-backend/bigquery-driver filtering Customers: notEndsWith filter + dimensions, first 1`] = `
Expand Down Expand Up @@ -2277,6 +2275,203 @@ Array [
]
`;

exports[`Queries with the @cubejs-backend/bigquery-driver querying BigECommerce: rolling window by 2 day 1`] = `
Array [
Object {
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": null,
},
Object {
"BigECommerce.orderDate": "2020-02-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-02-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": null,
},
Object {
"BigECommerce.orderDate": "2020-03-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-03-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": null,
},
Object {
"BigECommerce.orderDate": "2020-04-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-04-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": null,
},
Object {
"BigECommerce.orderDate": "2020-05-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-05-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": null,
},
Object {
"BigECommerce.orderDate": "2020-06-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-06-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": null,
},
Object {
"BigECommerce.orderDate": "2020-07-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-07-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": null,
},
Object {
"BigECommerce.orderDate": "2020-08-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-08-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": null,
},
Object {
"BigECommerce.orderDate": "2020-09-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-09-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": null,
},
Object {
"BigECommerce.orderDate": "2020-10-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-10-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": 1,
},
Object {
"BigECommerce.orderDate": "2020-11-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-11-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": null,
},
Object {
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
"BigECommerce.rollingCountBy2Day": null,
},
]
`;

exports[`Queries with the @cubejs-backend/bigquery-driver querying BigECommerce: rolling window by 2 month 1`] = `
Array [
Object {
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": 2,
},
Object {
"BigECommerce.orderDate": "2020-02-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-02-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": 3,
},
Object {
"BigECommerce.orderDate": "2020-03-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-03-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": 3,
},
Object {
"BigECommerce.orderDate": "2020-04-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-04-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": 3,
},
Object {
"BigECommerce.orderDate": "2020-05-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-05-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": 6,
},
Object {
"BigECommerce.orderDate": "2020-06-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-06-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": 12,
},
Object {
"BigECommerce.orderDate": "2020-07-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-07-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": 7,
},
Object {
"BigECommerce.orderDate": "2020-08-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-08-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": null,
},
Object {
"BigECommerce.orderDate": "2020-09-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-09-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": 6,
},
Object {
"BigECommerce.orderDate": "2020-10-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-10-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": 10,
},
Object {
"BigECommerce.orderDate": "2020-11-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-11-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": 13,
},
Object {
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
"BigECommerce.rollingCountBy2Month": 16,
},
]
`;

exports[`Queries with the @cubejs-backend/bigquery-driver querying BigECommerce: rolling window by 2 week 1`] = `
Array [
Object {
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": 1,
},
Object {
"BigECommerce.orderDate": "2020-02-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-02-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": 1,
},
Object {
"BigECommerce.orderDate": "2020-03-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-03-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": 1,
},
Object {
"BigECommerce.orderDate": "2020-04-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-04-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": null,
},
Object {
"BigECommerce.orderDate": "2020-05-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-05-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": 2,
},
Object {
"BigECommerce.orderDate": "2020-06-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-06-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": 3,
},
Object {
"BigECommerce.orderDate": "2020-07-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-07-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": null,
},
Object {
"BigECommerce.orderDate": "2020-08-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-08-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": null,
},
Object {
"BigECommerce.orderDate": "2020-09-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-09-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": 3,
},
Object {
"BigECommerce.orderDate": "2020-10-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-10-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": 3,
},
Object {
"BigECommerce.orderDate": "2020-11-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-11-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": 2,
},
Object {
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
"BigECommerce.rollingCountBy2Week": 2,
},
]
`;

exports[`Queries with the @cubejs-backend/bigquery-driver querying BigECommerce: totalProfitYearAgo 1`] = `Array []`;

exports[`Queries with the @cubejs-backend/bigquery-driver querying Customers: dimensions 1`] = `
Array [
Object {
Expand Down

0 comments on commit 9468f90

Please sign in to comment.