fix(bigquery): align DATE() function output to TIMESTAMP for SQL API compatibility#10660
Open
tlangton3 wants to merge 3 commits intocube-js:masterfrom
Open
fix(bigquery): align DATE() function output to TIMESTAMP for SQL API compatibility#10660tlangton3 wants to merge 3 commits intocube-js:masterfrom
tlangton3 wants to merge 3 commits intocube-js:masterfrom
Conversation
…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#10643
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.
The COUNT+GROUP BY test exercised the same push_to_cube=true (JS) path as the MEASURE() test. Since templates are shared across paths, one canonical test per bug shape is sufficient and matches the existing test pattern (e.g. "Date/time comparison with SQL push down" and "Date/time comparison with date_trunc with SQL push down" which each cover a single shape).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #10643. When querying via the SQL API (Postgres wire protocol),
CAST(x AS DATE) = DATE('2024-01-08')generatesTIMESTAMP = DATEon BigQuery, which BigQuery rejects. This pattern originates from Tableau connecting via the SQL API.Changes
functions/DATEtemplate for BigQuery to produceTIMESTAMP(args)instead ofDATE(args), aligning the SQL output with thedateUDF's declaredTimestampreturn type in CubeSQLCAST(? AS TIMESTAMP)for time dimension filter parameters inBigqueryFilter.castParameter()(defence-in-depth for the standard filter code path)MEASURE()query shape withCAST(x AS DATE) = DATE('...')DATE()builtin)Implementation Details
The CubeSQL
dateUDF declares its return type asTimestampfor compatibility with the egg rewrite engine's time dimension filter patterns. However, thefunctions/DATESQL template inBaseQuery.jsrenders asDATE(args)which produces aDATEtype in BigQuery. Whenplan_normalizecoerces the other side of a comparison to match theTimestampreturn type, the generated SQL becomesTIMESTAMP = DATE— which BigQuery rejects.The fix overrides the
DATEfunction template for BigQuery to produceTIMESTAMP(args). This is safe because the hardcodedDATE()calls in time series templates (e.g.GENERATE_DATE_ARRAY(DATE(...))) are inline strings within those templates, not calls to thefunctions/DATEtemplate. Templates are shared between the JS Cube server and Rustwrapper.rs, so a single override covers both SQL generation paths.The
castParameterchange is an additional safety net for cases where time dimension filter parameters reachBaseFilter.equalsWhere()directly.Testing
Notes for reviewers
Linear Ticket
N/A