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+
`;

packages/cubejs-testing-drivers/test/__snapshots__/databricks-jdbc-export-bucket-s3-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-s3 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-s3-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-s3-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-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 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__/mssql-full.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,6 +2336,21 @@ Array [
23362336
]
23372337
`;
23382338

2339+
exports[`Queries with the @cubejs-backend/mssql-driver querying BigECommerce: filtering with possible casts 1`] = `
2340+
Array [
2341+
Object {
2342+
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
2343+
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
2344+
"BigECommerce.totalSales": "488960",
2345+
},
2346+
Object {
2347+
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
2348+
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
2349+
"BigECommerce.totalSales": "2328800",
2350+
},
2351+
]
2352+
`;
2353+
23392354
exports[`Queries with the @cubejs-backend/mssql-driver querying BigECommerce: partitioned pre-agg 1`] = `
23402355
Array [
23412356
Object {

packages/cubejs-testing-drivers/test/__snapshots__/mysql-full.test.ts.snap

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,61 @@ Array [
25662566
]
25672567
`;
25682568

2569+
exports[`Queries with the @cubejs-backend/mysql-driver querying BigECommerce: filtering with possible casts 1`] = `
2570+
Array [
2571+
Object {
2572+
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
2573+
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
2574+
"BigECommerce.totalSales": 210.98,
2575+
},
2576+
Object {
2577+
"BigECommerce.orderDate": "2020-02-01T00:00:00.000",
2578+
"BigECommerce.orderDate.month": "2020-02-01T00:00:00.000",
2579+
"BigECommerce.totalSales": 18.368,
2580+
},
2581+
Object {
2582+
"BigECommerce.orderDate": "2020-03-01T00:00:00.000",
2583+
"BigECommerce.orderDate.month": "2020-03-01T00:00:00.000",
2584+
"BigECommerce.totalSales": 2471.56,
2585+
},
2586+
Object {
2587+
"BigECommerce.orderDate": "2020-04-01T00:00:00.000",
2588+
"BigECommerce.orderDate.month": "2020-04-01T00:00:00.000",
2589+
"BigECommerce.totalSales": 36.672,
2590+
},
2591+
Object {
2592+
"BigECommerce.orderDate": "2020-05-01T00:00:00.000",
2593+
"BigECommerce.orderDate.month": "2020-05-01T00:00:00.000",
2594+
"BigECommerce.totalSales": 1284.45,
2595+
},
2596+
Object {
2597+
"BigECommerce.orderDate": "2020-06-01T00:00:00.000",
2598+
"BigECommerce.orderDate.month": "2020-06-01T00:00:00.000",
2599+
"BigECommerce.totalSales": 724.974,
2600+
},
2601+
Object {
2602+
"BigECommerce.orderDate": "2020-09-01T00:00:00.000",
2603+
"BigECommerce.orderDate.month": "2020-09-01T00:00:00.000",
2604+
"BigECommerce.totalSales": 2451.472,
2605+
},
2606+
Object {
2607+
"BigECommerce.orderDate": "2020-10-01T00:00:00.000",
2608+
"BigECommerce.orderDate.month": "2020-10-01T00:00:00.000",
2609+
"BigECommerce.totalSales": 2209.828,
2610+
},
2611+
Object {
2612+
"BigECommerce.orderDate": "2020-11-01T00:00:00.000",
2613+
"BigECommerce.orderDate.month": "2020-11-01T00:00:00.000",
2614+
"BigECommerce.totalSales": 5573.922,
2615+
},
2616+
Object {
2617+
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
2618+
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
2619+
"BigECommerce.totalSales": 2073.63,
2620+
},
2621+
]
2622+
`;
2623+
25692624
exports[`Queries with the @cubejs-backend/mysql-driver querying BigECommerce: partitioned pre-agg with multi time dimension 1`] = `
25702625
Array [
25712626
Object {

packages/cubejs-testing-drivers/test/__snapshots__/postgres-full.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11116,6 +11116,21 @@ Array [
1111611116
]
1111711117
`;
1111811118

11119+
exports[`Queries with the @cubejs-backend/postgres-driver querying BigECommerce: filtering with possible casts 1`] = `
11120+
Array [
11121+
Object {
11122+
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
11123+
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
11124+
"BigECommerce.totalSales": "48.89600",
11125+
},
11126+
Object {
11127+
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
11128+
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
11129+
"BigECommerce.totalSales": "232.88000",
11130+
},
11131+
]
11132+
`;
11133+
1111911134
exports[`Queries with the @cubejs-backend/postgres-driver querying BigECommerce: null boolean 1`] = `
1112011135
Array [
1112111136
Object {

packages/cubejs-testing-drivers/test/__snapshots__/redshift-export-bucket-s3-full.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11108,6 +11108,21 @@ Array [
1110811108
]
1110911109
`;
1111011110

11111+
exports[`Queries with the @cubejs-backend/redshift-driver export-bucket-s3 querying BigECommerce: filtering with possible casts 1`] = `
11112+
Array [
11113+
Object {
11114+
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
11115+
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
11116+
"BigECommerce.totalSales": "48.89600",
11117+
},
11118+
Object {
11119+
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
11120+
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
11121+
"BigECommerce.totalSales": "232.88000",
11122+
},
11123+
]
11124+
`;
11125+
1111111126
exports[`Queries with the @cubejs-backend/redshift-driver export-bucket-s3 querying BigECommerce: null boolean 1`] = `
1111211127
Array [
1111311128
Object {

0 commit comments

Comments
 (0)