Skip to content

fix(plugin-snowflake): decode the wire encodings the query-request endpoint sends - #2466

Merged
datlechin merged 6 commits into
TableProApp:mainfrom
yankewei:fix/snowflake-date-epoch-days
Aug 26, 2026
Merged

fix(plugin-snowflake): decode the wire encodings the query-request endpoint sends#2466
datlechin merged 6 commits into
TableProApp:mainfrom
yankewei:fix/snowflake-date-epoch-days

Conversation

@yankewei

@yankewei yankewei commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Snowflake driver fixes, five commits, each reviewed and merged on its own before landing here: #2467, #2468, #2469, #2470, plus the original decoding change.

The reported bug

SnowflakeConnection.box is type blind. The legacy /queries/v1/query-request endpoint sends every cell as a JSON string in Snowflake's own internal encoding, and the driver never consulted the rowtype metadata it had already parsed, so a DATE reached the app as 20682 rather than 2026-08-17.

That one boxing produced all three reported symptoms, because display, the picker seed and the UPDATE / DELETE WHERE anchor all read the same PluginCellValue.

Two corrections to the original approach

DATE_OUTPUT_FORMAT cannot work, so it is dropped. Its default is already YYYY-MM-DD and the wire still carries 20682. Snowflake's own converter_snowsql.py reads the parameter and still calls time.gmtime(int(value) * 86400) first; gosnowflake and snowflake-jdbc decode epoch days unconditionally. It is a display parameter for text casts, not a wire format switch.

Foundation is the wrong calendar. Snowflake documents that it does not adjust dates before 1582 to match the Julian calendar. Measured on this toolchain, Calendar(identifier: .gregorian), Calendar(identifier: .iso8601), ISO8601DateFormatter, Date.FormatStyle.iso8601 and a POSIX DateFormatter all render epoch day -719162 as 0001-01-03 where Snowflake means 0001-01-01, and gregorianStartDate does not exist in the macOS SDK. The conversion is integer arithmetic, and testProlepticGregorian fails the moment anyone reimplements it on Foundation.

What is in here

Type Wire Was Now
DATE days since epoch 20682 2026-08-17
TIME seconds since midnight 3600.000000000 01:00:00
TIMESTAMP_NTZ seconds since epoch 1755388800.000000000 2025-08-17 00:00:00
TIMESTAMP_LTZ seconds since epoch 1755388800.000000000 2025-08-17 00:00:00Z
TIMESTAMP_TZ seconds, offset + 1440 1616173619.000000000 1500 2021-03-19 18:06:59+01:00
BINARY hex string 0x34383635364336433646 the bytes themselves

Plus, from the stacked reviews:

A value that cannot be decoded is never invented

Every arm returns the raw text unchanged when the encoding does not explain the value: a non-integer, an out of range epoch day, a malformed offset, an odd-length hex string. Decoding is keyed on the column, never on the value, so an integer sitting in a VARCHAR is left alone.

The picker

A date control cannot say "I could not read this": NSDatePicker.dateValue and every SwiftUI DatePicker binding are a non-optional Date. A date cell whose text is non-empty and does not parse now opens the existing text editor instead of a picker seeded with today.

Tests

63 cases across SnowflakeValueDecoderTests, SnowflakeSQLTests, SnowflakeStatementTypeTests, SnowflakeSessionKeyTests and SnowflakeTypeMapperTests. Decoder expectations were computed independently in Python's proleptic Gregorian calendar rather than from the implementation.

Verified on the merged branch: build PASS, SwiftLint 0 violations, AllPlugins compiles SnowflakeDriverPlugin clean, docs checks PASS.

Not fixed here

Version 0 TIMESTAMP_TZ payloads pack the zone into the low bits of a single number instead of the "<epoch> <offset>" pair. Decoding it needs Snowflake's timezone index table, which cannot be verified without an account, so those values fall through to raw text, which is the behaviour before this change.

Fixes #2454

@datlechin
datlechin force-pushed the fix/snowflake-date-epoch-days branch from cddfc74 to 3fae388 Compare August 26, 2026 15:51
@datlechin datlechin changed the title fix(plugin-snowflake): normalize DATE epoch days fix(plugin-snowflake): decode the wire encodings the query-request endpoint sends Aug 26, 2026
@datlechin
datlechin marked this pull request as ready for review August 26, 2026 17:47
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@datlechin
datlechin merged commit d45948e into TableProApp:main Aug 26, 2026
1 check 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.

Snowflake DATE columns render epoch-day values and open on today's date

2 participants