Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bigquery)!: Support FORMAT_TIMESTAMP #4383

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

VaggelisD
Copy link
Collaborator

This PR adds support for BQ's FORMAT_TIMESTAMP through exp.TimeToStr:

bigquery> SELECT FORMAT_TIMESTAMP("%b-%d-%Y", TIMESTAMP "2050-12-25 15:30:55+00");
Dec-25-2050

snowflake> SELECT TO_CHAR(CAST(CAST('2050-12-25 15:30:55+00' AS TIMESTAMPTZ) AS TIMESTAMP), 'mon-DD-yyyy');
Dec-25-2050

duckdb> SELECT STRFTIME(CAST('2050-12-25 15:30:55+00' AS TIMESTAMP), '%b-%d-%Y');
┌───────────────────────────────────────────────────────────────────┐
│ strftime(CAST('2050-12-25 15:30:55+00' AS TIMESTAMP), '%b-%d-%Y') │
│                              varchar                              │
├───────────────────────────────────────────────────────────────────┤
│ Dec-25-2050                                                       │
└───────────────────────────────────────────────────────────────────┘

Regarding the changes in this PR:

  1. For BQ, FORMAT_DATETIME was deduplicated from FORMAT_TIMESTAMP by introducing exp.TsOrDsToDatetime
  2. For exp.cast(...), a bug was solved regarding the types_are_equivalent check; Note how get will either retrieve a str or a DataType.Type (the default value), so the comparison might be incorrect as stringifying DataTypes will prepend them with the Type.<type> enum prefix (e.g comparing Type.TIMESTAMP with DATETIME for DuckDB). To fix this we must retrieve either the TYPE_MAPPING or stringify the value of the enum type
  3. For DuckDB, Type.DATETIME now maps to TIMESTAMP as these are aliases (this enables redundant cast eliminations from bullet 2)

Docs

BQ FORMAT_TIMESTAMP | DuckDB TIMESTAMP type | Snowflake TO_CHAR

@georgesittas georgesittas merged commit 9ec61de into main Nov 13, 2024
6 checks passed
@georgesittas georgesittas deleted the vaggelisd/bq_format_timestamp branch November 13, 2024 15:26
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