Skip to content

A Snowflake date or timestamp reads as a date, so 18262 is 2020-01-01 - #1412

Merged
WaylandYang merged 3 commits into
deeplethe:devfrom
rudycelekli:snowflake-temporal
Oct 27, 2026
Merged

WaylandYang merged 3 commits into
deeplethe:devfrom
rudycelekli:snowflake-temporal

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Why

The Snowflake SQL API returns each value as a string, and temporal types are encoded as epoch numbers (SQL API: getting the results):

  • DATE is the number of days since the epoch: "18262".
  • TIME, TIMESTAMP_NTZ and TIMESTAMP_LTZ are seconds with nine decimals: "1616173619.000000000".
  • TIMESTAMP_TZ is seconds, a space, then 1440 plus the zone offset in minutes: "1616173619.000000000 1500".

The engine passed these strings through coerce, which only restores numbers and booleans. A query such as SELECT order_date, SUM(amount) … GROUP BY 1 gave the model "18262" where the warehouse holds 2020-01-01. The model has no way to read that as a date, so date questions against Snowflake were answered from opaque numbers.

What changes

A Snowflake-only cell runs before coerce. It writes:

  • date as 2020-01-01;
  • time as 23:01:59;
  • timestamp_ntz as 2021-03-19 17:06:59;
  • timestamp_ltz as RFC 3339 UTC, 2021-03-19T17:06:59Z;
  • timestamp_tz as RFC 3339 with its own offset, 2021-03-19T18:06:59+01:00.

Fractions are kept, for example .500. Times before 1970 floor correctly, so -1.5 seconds is 1969-12-31 23:59:58.500. A value that does not parse is left as it came. Every other type still goes through coerce, and both the first partition and later partitions use the new function.

How it was checked

  • A new wiremock test, dates_and_times_read_as_dates_and_times, returns two rows typed date, time, timestamp_ntz, timestamp_ltz and timestamp_tz. They cover a pre-1970 instant, a null, and offsets of +01:00 and -06:00.
  • cargo test -p utopia-server --bins query_engine::snowflake: 10 passed.
  • With the fix reverted, the test fails with left: ["{\"D\":\"18262\",\"T\":\"82919.000000000\",\"NTZ\":\"1616173619.000000000\",….
  • cargo fmt --all --check and cargo clippy -p utopia-server --all-targets -- -D warnings pass.

Before review

  • Every commit is signed off (git commit -s)
  • cargo fmt --all --check, cargo clippy and cargo test pass for the touched crate

Requested ADR follow-up

Updated ADR 0018 as requested in review. This appended revision changes documentation only; Rust and Cargo files are byte-for-byte unchanged from the prior public head. cargo fmt --all --check and git diff --check pass. No new Rust test run or live-cluster acceptance is claimed for this revision. Final-head CI remains required.

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>

@WaylandYang WaylandYang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Like the other Snowflake tests, this checks our reading of the documented protocol, not a real cluster (#241). Please add a sentence to ADR 0018's fourth-gate paragraph saying dates and timestamps are now restored.

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>

@WaylandYang WaylandYang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the ADR sentence is exactly what was needed. Approving and merging.

@WaylandYang
WaylandYang merged commit 3fc15f7 into deeplethe:dev Oct 27, 2026
6 checks passed
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.

2 participants