Repository navigation
Reprint Trino/Presto TIMESTAMP(x) as CAST(x AS TIMESTAMP) - #16
Merged
Merged
Conversation
Neither engine has a timestamp() function; sqlglot's Presto/Trino generators write TIMESTAMP(x) as CAST(x AS TIMESTAMP) and TIMESTAMP(x, 'zone') as AT_TIMEZONE(CAST(x AS TIMESTAMP), 'zone'). Match them, so a query that runs after a sqlglot reprint also runs after a polyglot one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017CxHoCFbTWJA9bcZWC9ydu
…t does sqlglot's no_timestamp_sql emits AT_TIMEZONE only when the zone literal is in its time-zone list; TIMESTAMP(x, '12:00:00') stays as written. Use the same list (crate::time::is_valid_timezone). Fixes sqlglot_transpilation's Presto TIMESTAMP(x, '12:00:00') fixtures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017CxHoCFbTWJA9bcZWC9ydu
TIMESTAMP(x, zone) checks the zone with time::is_valid_timezone, so a Trino-only build (default-features = false) needs the time module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017CxHoCFbTWJA9bcZWC9ydu
Member
Author
|
Just double checking but vanilla sqlglot does this casting? |
Member
Author
|
Yes, this is vanilla sqlglot behaviour, not something OSO-specific:
Generated by Claude Code |
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.
Neither Trino nor Presto has a
timestamp()function, soTIMESTAMP('2025-09-16 13:51:30.000')fails there (FUNCTION_NOT_FOUND). sqlglot's Presto/Trino generators reprint it (no_timestamp_sql), so a query using it runs after a sqlglot round trip but not after a polyglot one. polyglot treated it as an anonymous function and passed it through.This matches sqlglot:
TIMESTAMP(x)CAST(x AS TIMESTAMP)TIMESTAMP(x, 'zone'),zonea known time-zone nameAT_TIMEZONE(CAST(x AS TIMESTAMP), 'zone')TIMESTAMP(x, '12:00:00'),TIMESTAMP(x, z)and other arities"Known time-zone name" is sqlglot's own test: polyglot's port of its list,
time::is_valid_timezone. That keeps upstream'ssqlglot_transpilationfixtureTIMESTAMP(x, '12:00:00')(Presto → Presto/DuckDB) as written.dialects/presto_family.rs, compiled when eitherdialect-prestoordialect-trinois enabled.time, which has no dependencies, so a Trino-only build withdefault-features = false(as kuma uses) gets the zone list.Tests
tests/trino_timestamp_function.rs(new): one-argument, known-zone, unknown-zone and computed-zone calls, and timestamp casts left unchanged, for both dialects.make extract-fixtures):sqlglot_transpilationpasses 6045/6045, and the identity, dialect-identity, parser and transpile suites all pass.cargo test --lib: 1343 passed.query-rewritersuite (Trino-only features) passes againstmainwith this PR, Keep Presto/Trino two-argument MAX(x, n)/MIN(x, n) as aggregates #17 and Keep a set operation after an unaliased derived table outside it #18 combined.🤖 Generated with Claude Code
https://claude.ai/code/session_017CxHoCFbTWJA9bcZWC9ydu