Skip to content

feat(trino): string→timestamp cast should read ISO 8601 with a T separator #12107

Description

@Ramin314

Is your feature request related to a problem?

string_value.cast("timestamp") compiles to CAST(x AS TIMESTAMP) on every backend. On Trino / Athena that cast reads only the space-separated form 2018-05-02 15:00:00; the ISO 8601 form 2018-05-02T15:00:00, which is what most upstream systems emit, fails at run time with INVALID_CAST_ARGUMENT: Value cannot be cast to timestamp: 2018-05-02T15:00:00. DuckDB, Postgres, BigQuery and others read both forms, so the same ibis expression is portable everywhere except Trino.

import ibis
t = ibis.table({"s": "string"}, name="t")
print(ibis.to_sql(t.select(ts=t.s.cast("timestamp")), dialect="trino"))
# SELECT CAST("t0"."s" AS TIMESTAMP) AS "ts" FROM "t" AS "t0"

What is the motivation behind your request?

Trino has from_iso8601_timestamp, which reads every ISO 8601 form (date, date-time, offsets). Spelling the string→timestamp cast on Trino as CAST(from_iso8601_timestamp(x) AS TIMESTAMP) (or normalising the separator) would make .cast("timestamp") behave like it does on the other SQL backends. TryCast would wrap it in TRY(...).

Describe the solution you'd like

TrinoCompiler.visit_Cast / visit_TryCast: when from_.is_string() and to.is_timestamp(), emit from_iso8601_timestamp rather than a bare cast.

What version of ibis are you using?

12.0.0

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions