fix(bigquery): align DATE() function output to TIMESTAMP for SQL API compatibility#10660
Open
tlangton3 wants to merge 1 commit intocube-js:masterfrom
Open
fix(bigquery): align DATE() function output to TIMESTAMP for SQL API compatibility#10660tlangton3 wants to merge 1 commit intocube-js:masterfrom
tlangton3 wants to merge 1 commit 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
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 CubeSQLBigqueryFilter.castParameter()MEASURE()(Cube REST API) andCOUNT()(SQL push-down) code pathsImplementation 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.The
castParameterfix is an additional safety net ensuring time dimension filter parameters are explicitly cast toTIMESTAMPwhen using the standard filter code path.Testing
MEASURE()andCOUNT()paths withCAST(x AS DATE) = DATE('...')Linear Ticket
N/A