From b5b0404a07d5c69a2f66eab9646f2edab59e0398 Mon Sep 17 00:00:00 2001 From: Thomas Langton <155970791+tlangton3@users.noreply.github.com> Date: Thu, 9 Apr 2026 12:25:10 +0100 Subject: [PATCH 1/2] fix(bigquery): align DATE() function output to TIMESTAMP for SQL API compatibility The CubeSQL date UDF declares Timestamp return type but the BigQuery DATE function template renders DATE(), producing a DATE value. When plan_normalize coerces the other side of a comparison to match the Timestamp return type, BigQuery receives TIMESTAMP = DATE which it rejects. Override the DATE function template for BigQuery to produce TIMESTAMP(args), matching the UDF's declared return type. Also add TIMESTAMP cast for time dimension filter parameters in castParameter(). Fixes cube-js/cube#10643 --- .../src/adapter/BigqueryQuery.ts | 3 +++ .../src/tests/testQueries.ts | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/cubejs-schema-compiler/src/adapter/BigqueryQuery.ts b/packages/cubejs-schema-compiler/src/adapter/BigqueryQuery.ts index df71822d98cc0..6e7ae2d2524f5 100644 --- a/packages/cubejs-schema-compiler/src/adapter/BigqueryQuery.ts +++ b/packages/cubejs-schema-compiler/src/adapter/BigqueryQuery.ts @@ -24,6 +24,8 @@ class BigqueryFilter extends BaseFilter { public castParameter() { if (this.definition().type === 'boolean') { return 'CAST(? AS BOOL)'; + } else if (this.definition().type === 'time') { + return 'CAST(? AS TIMESTAMP)'; } else if (this.measure || this.definition().type === 'number') { // TODO here can be measure type of string actually return 'CAST(? AS FLOAT64)'; @@ -347,6 +349,7 @@ export class BigqueryQuery extends BaseQuery { // DATEADD is being rewritten to DATE_ADD templates.functions.DATE_ADD = 'DATETIME_ADD(DATETIME({{ args[0] }}), INTERVAL {{ interval }} {{ date_part }})'; templates.functions.CURRENTDATE = 'CURRENT_DATE'; + templates.functions.DATE = 'TIMESTAMP({{ args_concat }})'; delete templates.functions.TO_CHAR; delete templates.functions.PERCENTILECONT; templates.expressions.binary = '{% if op == \'%\' %}MOD({{ left }}, {{ right }}){% else %}({{ left }} {{ op }} {{ right }}){% endif %}'; diff --git a/packages/cubejs-testing-drivers/src/tests/testQueries.ts b/packages/cubejs-testing-drivers/src/tests/testQueries.ts index 8a97514618b96..a95b052c6f6ba 100644 --- a/packages/cubejs-testing-drivers/src/tests/testQueries.ts +++ b/packages/cubejs-testing-drivers/src/tests/testQueries.ts @@ -2610,5 +2610,26 @@ from `); expect(res.rows).toMatchSnapshot(); }); + + executePg('SQL API: Date/time comparison with DATE() function in SQL push down', async (connection) => { + const res = await connection.query(` + SELECT MEASURE(BigECommerce.totalQuantity) as qty + FROM BigECommerce + WHERE CAST(BigECommerce.orderDate AS DATE) = DATE('2020-01-01') + `); + expect(res.rows).toMatchSnapshot(); + }); + + executePg('SQL API: Date/time comparison with DATE() function using COUNT push down', async (connection) => { + const res = await connection.query(` + SELECT + CAST(BigECommerce.orderDate AS DATE) as order_day, + COUNT(1) as cnt + FROM BigECommerce + WHERE CAST(BigECommerce.orderDate AS DATE) = DATE('2020-01-01') + GROUP BY 1 + `); + expect(res.rows).toMatchSnapshot(); + }); }); } From 13c17cb6212fae0b856de26e011db1675a97d786 Mon Sep 17 00:00:00 2001 From: Thomas Langton <155970791+tlangton3@users.noreply.github.com> Date: Fri, 10 Apr 2026 17:36:15 +0100 Subject: [PATCH 2/2] test(mssql): skip DATE() function tests unsupported on MSSQL MSSQL does not have a DATE() built-in function. Skip the new Date/time comparison tests that use DATE() syntax, matching the existing skips for other Date/time comparison tests. --- packages/cubejs-testing-drivers/fixtures/mssql.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/cubejs-testing-drivers/fixtures/mssql.json b/packages/cubejs-testing-drivers/fixtures/mssql.json index ace65c8dc3910..7afd45fe890f7 100644 --- a/packages/cubejs-testing-drivers/fixtures/mssql.json +++ b/packages/cubejs-testing-drivers/fixtures/mssql.json @@ -177,6 +177,8 @@ "SQL API: SQL push down push to cube quoted alias", "SQL API: Date/time comparison with SQL push down", "SQL API: Date/time comparison with date_trunc with SQL push down", + "SQL API: Date/time comparison with DATE() function in SQL push down", + "SQL API: Date/time comparison with DATE() function using COUNT push down", "---------------------------------------", "Error during rewrite: Can't detect Cube query and it may be not supported yet.", @@ -228,6 +230,8 @@ "SQL API: SQL push down push to cube quoted alias", "SQL API: Date/time comparison with SQL push down", "SQL API: Date/time comparison with date_trunc with SQL push down", + "SQL API: Date/time comparison with DATE() function in SQL push down", + "SQL API: Date/time comparison with DATE() function using COUNT push down", "---------------------------------------", "Error during rewrite: Can't detect Cube query and it may be not supported yet.",