Skip to content

Commit 7b48c27

Browse files
authored
fix(tesseracrt): Fix filter params casting for BigQuery dialect (#9720)
* Add param casts templates * implement params casting for filter in tesseract * add tests
1 parent ba6eecd commit 7b48c27

30 files changed

+616
-80
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4133,11 +4133,14 @@ export class BaseQuery {
41334133
like_escape: '{{ like_expr }} ESCAPE {{ escape_char }}',
41344134
within_group: '{{ fun_sql }} WITHIN GROUP (ORDER BY {{ within_group_concat }})',
41354135
concat_strings: '{{ strings | join(\' || \' ) }}',
4136-
rolling_window_expr_timestamp_cast: '{{ value }}'
4136+
rolling_window_expr_timestamp_cast: '{{ value }}',
4137+
timestamp_literal: '{{ value }}'
41374138
},
41384139
tesseract: {
41394140
ilike: '{{ expr }} {% if negated %}NOT {% endif %}ILIKE {{ pattern }}', // May require different overloads in Tesseract than the ilike from expressions used in SQLAPI.
4140-
series_bounds_cast: '{{ expr }}'
4141+
series_bounds_cast: '{{ expr }}',
4142+
bool_param_cast: '{{ expr }}',
4143+
number_param_cast: '{{ expr }}',
41414144
},
41424145
filters: {
41434146
equals: '{{ column }} = {{ value }}{{ is_null_check }}',

packages/cubejs-schema-compiler/src/adapter/BigqueryQuery.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ export class BigqueryQuery extends BaseQuery {
335335
templates.filters.like_pattern = 'CONCAT({% if start_wild %}\'%\'{% else %}\'\'{% endif %}, LOWER({{ value }}), {% if end_wild %}\'%\'{% else %}\'\'{% endif %})';
336336
templates.tesseract.ilike = 'LOWER({{ expr }}) {% if negated %}NOT {% endif %} LIKE {{ pattern }}';
337337
templates.tesseract.series_bounds_cast = 'TIMESTAMP({{ expr }})';
338+
templates.tesseract.bool_param_cast = 'CAST({{ expr }} AS BOOL)';
339+
templates.tesseract.number_param_cast = 'CAST({{ expr }} AS FLOAT64)';
338340
templates.types.boolean = 'BOOL';
339341
templates.types.float = 'FLOAT64';
340342
templates.types.double = 'FLOAT64';

packages/cubejs-testing-drivers/fixtures/athena.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@
129129
"for the ECommerce.TimeAnalysisExternal",
130130
"for the ECommerce.TimeAnalysisInternal",
131131

132-
"---------------------------------------",
133-
"Full tests ",
134-
"---------------------------------------",
135-
136132
"---------------------------------------",
137133
"SKIPPED FOR ALL ",
138134
"---------------------------------------",
@@ -143,18 +139,15 @@
143139
"querying BigECommerce: partitioned pre-agg",
144140
"querying BigECommerce: null sum",
145141
"querying BigECommerce: null boolean",
146-
"--------------------",
142+
"querying BigECommerce: filtering with possible casts",
147143

148144
"---------------------------------------",
149145
"Requires Tesseract. ",
150146
"---------------------------------------",
151147
"querying BigECommerce: rolling window by 2 day without date range",
152148
"querying BigECommerce: rolling window by 2 month without date range",
153149
"querying BigECommerce: rolling window YTD without date range",
154-
155-
"--------------------",
156150
"week granularity is not supported for intervals",
157-
"--------------------",
158151
"querying BigECommerce: rolling window by 2 week",
159152

160153
"---------------------------------------",
@@ -185,8 +178,7 @@
185178
"querying BigECommerce: partitioned pre-agg",
186179
"querying BigECommerce: null sum",
187180
"querying BigECommerce: null boolean",
188-
"--------------------",
189-
181+
"querying BigECommerce: filtering with possible casts",
190182

191183
"querying BigECommerce: rolling window by 2 week",
192184
"querying custom granularities ECommerce: count by three_months_by_march + no dimension",

packages/cubejs-testing-drivers/fixtures/clickhouse.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
"querying BigECommerce: partitioned pre-agg",
180180
"querying BigECommerce: null sum",
181181
"querying BigECommerce: null boolean",
182+
"querying BigECommerce: filtering with possible casts",
182183

183184
"---------------------------------------",
184185
"Unsupported JOIN ON conditions. Unexpected 'big_e_commerce__order_date_month > subtractWeeks(date_to, 2)'",

packages/cubejs-testing-drivers/src/tests/testQueries.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,35 @@ export function testQueries(type: string, { includeIncrementalSchemaSuite, exten
18041804
expect(response.rawData()).toMatchSnapshot();
18051805
});
18061806

1807+
execute('querying BigECommerce: filtering with possible casts', async () => {
1808+
const response = await client.load({
1809+
measures: [
1810+
'BigECommerce.totalSales',
1811+
],
1812+
filters: [
1813+
{
1814+
values: ['10'],
1815+
member: 'BigECommerce.sales',
1816+
operator: 'gte'
1817+
},
1818+
{
1819+
values: ['true'],
1820+
member: 'BigECommerce.returning',
1821+
operator: 'equals'
1822+
}
1823+
],
1824+
timeDimensions: [{
1825+
dimension: 'BigECommerce.orderDate',
1826+
granularity: 'month',
1827+
dateRange: ['2020-01-01', '2020-12-31'],
1828+
}],
1829+
order: {
1830+
'BigECommerce.orderDate': 'asc',
1831+
}
1832+
});
1833+
expect(response.rawData()).toMatchSnapshot();
1834+
});
1835+
18071836
execute('querying custom granularities ECommerce: count by half_year + no dimension', async () => {
18081837
const response = await client.load({
18091838
measures: [

packages/cubejs-testing-drivers/test/__snapshots__/bigquery-export-bucket-gcs-full.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6260,6 +6260,21 @@ Array [
62606260
]
62616261
`;
62626262

6263+
exports[`Queries with the @cubejs-backend/bigquery-driver querying BigECommerce: filtering with possible casts 1`] = `
6264+
Array [
6265+
Object {
6266+
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
6267+
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
6268+
"BigECommerce.totalSales": 48.896,
6269+
},
6270+
Object {
6271+
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
6272+
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
6273+
"BigECommerce.totalSales": 232.88,
6274+
},
6275+
]
6276+
`;
6277+
62636278
exports[`Queries with the @cubejs-backend/bigquery-driver querying BigECommerce: partitioned pre-agg 1`] = `
62646279
Array [
62656280
Object {

packages/cubejs-testing-drivers/test/__snapshots__/databricks-jdbc-export-bucket-azure-full.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15980,3 +15980,18 @@ Array [
1598015980
},
1598115981
]
1598215982
`;
15983+
15984+
exports[`Queries with the @cubejs-backend/databricks-jdbc-driver export-bucket-azure querying BigECommerce: filtering with possible casts 1`] = `
15985+
Array [
15986+
Object {
15987+
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
15988+
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
15989+
"BigECommerce.totalSales": 48.896,
15990+
},
15991+
Object {
15992+
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
15993+
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
15994+
"BigECommerce.totalSales": 232.88,
15995+
},
15996+
]
15997+
`;

packages/cubejs-testing-drivers/test/__snapshots__/databricks-jdbc-export-bucket-azure-prefix-full.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15785,3 +15785,18 @@ Array [
1578515785
},
1578615786
]
1578715787
`;
15788+
15789+
exports[`Queries with the @cubejs-backend/databricks-jdbc-driver export-bucket-azure-prefix querying BigECommerce: filtering with possible casts 1`] = `
15790+
Array [
15791+
Object {
15792+
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
15793+
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
15794+
"BigECommerce.totalSales": 48.896,
15795+
},
15796+
Object {
15797+
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
15798+
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
15799+
"BigECommerce.totalSales": 232.88,
15800+
},
15801+
]
15802+
`;

packages/cubejs-testing-drivers/test/__snapshots__/databricks-jdbc-export-bucket-gcs-full.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15980,3 +15980,18 @@ Array [
1598015980
},
1598115981
]
1598215982
`;
15983+
15984+
exports[`Queries with the @cubejs-backend/databricks-jdbc-driver export-bucket-gcs querying BigECommerce: filtering with possible casts 1`] = `
15985+
Array [
15986+
Object {
15987+
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
15988+
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
15989+
"BigECommerce.totalSales": 48.896,
15990+
},
15991+
Object {
15992+
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
15993+
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
15994+
"BigECommerce.totalSales": 232.88,
15995+
},
15996+
]
15997+
`;

packages/cubejs-testing-drivers/test/__snapshots__/databricks-jdbc-export-bucket-gcs-prefix-full.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15785,3 +15785,18 @@ Array [
1578515785
},
1578615786
]
1578715787
`;
15788+
15789+
exports[`Queries with the @cubejs-backend/databricks-jdbc-driver export-bucket-gcs-prefix querying BigECommerce: filtering with possible casts 1`] = `
15790+
Array [
15791+
Object {
15792+
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
15793+
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
15794+
"BigECommerce.totalSales": 48.896,
15795+
},
15796+
Object {
15797+
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
15798+
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
15799+
"BigECommerce.totalSales": 232.88,
15800+
},
15801+
]
15802+
`;

0 commit comments

Comments
 (0)