Skip to content

fix(core): BigQuery date filters work on TIMESTAMP / DATETIME columns - #3381

Open
HusnainMaroof wants to merge 1 commit into
evidence-dev:mainfrom
HusnainMaroof:fix/bigquery-timestamp-date-filter
Open

HusnainMaroof wants to merge 1 commit into
evidence-dev:mainfrom
HusnainMaroof:fix/bigquery-timestamp-date-filter

Conversation

@HusnainMaroof

Copy link
Copy Markdown

Fixes #3333

Problem

On BigQuery, a date filter pointed at a TIMESTAMP column fails at query time:

No matching signature for operator >= for argument types: TIMESTAMP, DATE

processDateRange emits col >= DATE '…' AND col <= DATE '…', and BigQuery won't compare DATE with TIMESTAMP (or DATETIME). Every component bound to the filter breaks at once.

Fix

  • Adds an optional dateRangePredicate(column, startIso?, endIso?) hook to SqlDialect. processDateRange uses it when a dialect implements it and keeps the existing >= dateLiteral … <= dateLiteral predicate otherwise.
  • BigQueryDialect implements it as col >= 'YYYY-MM-DD' AND col < '<day after end>':
    • Untyped string literals are coerced to the column's type (DATE, DATETIME or TIMESTAMP), so the comparison type-checks for all three.
    • The upper bound is exclusive on the next day, so TIMESTAMP / DATETIME columns keep the whole last day (ts <= '2020-01-31' would stop at midnight). For DATE columns it selects the same rows as before.
    • The column is left bare (no DATE(col)), so partition pruning still applies.

Since processDateRange builds the predicate for range_calendar with value_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: dateRangePredicate covering closed and open ranges, month/leap-day/year rollover, and quoted identifiers.
  • date-options.spec.ts: BigQuery processDateRange. Only whereClause changes; startDateSql / endDateSql / betweenFragment keep their typed DATE literals.
  • Updated snapshots: every changed line is in a BigQuery section and is the same DATE '…' <= DATE '…' → '…' < '<next day>' change. Other dialects' snapshots didn't move.

Locally (Node 22, pnpm 9.15.0): core pnpm test passes (4,733 tests), cli pnpm test passes, and pnpm --filter @evidence/core check reports 0 errors.

Not covered (follow-ups)

  • Prior-period half of comparisons (delta, big_value comparison): build-comparisons.ts builds its own bounds as col >= DATE_ADD(DATE '…', INTERVAL …), which still fails on TIMESTAMP columns. 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.
  • Hand-written {{id.between}} templates still emit BETWEEN DATE '…' AND DATE '…', because the column is outside the fragment. value_column + filters=[...] is the fixed path.
  • Day boundaries for TIMESTAMP columns are UTC (BigQuery's default when coercing a date string), the same as DATE(ts) would give.

🤖 Generated with Claude Code

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]>
@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

@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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

range_calendar / date filters cannot filter a TIMESTAMP column on BigQuery (DATE vs TIMESTAMP)

1 participant