Repository navigation
fix(core): BigQuery date filters work on TIMESTAMP / DATETIME columns - #3381
Open
HusnainMaroof wants to merge 1 commit into
Open
HusnainMaroof wants to merge 1 commit into
HusnainMaroof wants to merge 1 commit into
Conversation
BigQuery rejects `TIMESTAMP >= DATE`, so date filters pointed at a TIMESTAMP column (`range_calendar` with `value_column`, `date_range`, period filters, table measures, sparklines) broke every bound component with "No matching signature for operator >=". Add an optional `dateRangePredicate` hook to `SqlDialect`, used by `processDateRange` when present. BigQuery emits untyped string bounds, which are coerced to the column's type, with an exclusive next-day upper bound so TIMESTAMP/DATETIME columns keep the whole last day. The column stays bare so partition pruning still applies. Other dialects are unchanged. Fixes evidence-dev#3333 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@HusnainMaroof is attempting to deploy a commit to the Evidence Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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.
Fixes #3333
Problem
On BigQuery, a date filter pointed at a
TIMESTAMPcolumn fails at query time:processDateRangeemitscol >= DATE '…' AND col <= DATE '…', and BigQuery won't compareDATEwithTIMESTAMP(orDATETIME). Every component bound to the filter breaks at once.Fix
dateRangePredicate(column, startIso?, endIso?)hook toSqlDialect.processDateRangeuses it when a dialect implements it and keeps the existing>= dateLiteral … <= dateLiteralpredicate otherwise.BigQueryDialectimplements it ascol >= 'YYYY-MM-DD' AND col < '<day after end>':DATE,DATETIMEorTIMESTAMP), so the comparison type-checks for all three.TIMESTAMP/DATETIMEcolumns keep the whole last day (ts <= '2020-01-31'would stop at midnight). ForDATEcolumns it selects the same rows as before.DATE(col)), so partition pruning still applies.Since
processDateRangebuilds the predicate forrange_calendarwithvalue_column/filters=[...],date_range, period filters, sparklines, table measures and the current period of comparisons, all of those are covered.Other dialects produce exactly the same SQL as before.
Tests
sql-dialect.test.ts:dateRangePredicatecovering closed and open ranges, month/leap-day/year rollover, and quoted identifiers.date-options.spec.ts: BigQueryprocessDateRange. OnlywhereClausechanges;startDateSql/endDateSql/betweenFragmentkeep their typedDATEliterals.DATE '…' <= DATE '…'→'…' < '<next day>'change. Other dialects' snapshots didn't move.Locally (Node 22, pnpm 9.15.0): core
pnpm testpasses (4,733 tests), clipnpm testpasses, andpnpm --filter @evidence/core checkreports 0 errors.Not covered (follow-ups)
delta,big_valuecomparison):build-comparisons.tsbuilds its own bounds ascol >= DATE_ADD(DATE '…', INTERVAL …), which still fails onTIMESTAMPcolumns. It was already broken before this change. Those bounds are SQL expressions, not ISO dates, so they need a different approach, and that code overlaps with fix(core): use the range_calendar period for prior-period comparisons in filters=[] #3351, so I've left it out of this PR.{{id.between}}templates still emitBETWEEN DATE '…' AND DATE '…', because the column is outside the fragment.value_column+filters=[...]is the fixed path.TIMESTAMPcolumns are UTC (BigQuery's default when coercing a date string), the same asDATE(ts)would give.🤖 Generated with Claude Code