Skip to content

bug(trino): casting a struct to string compiles to CAST(ROW(...) AS VARCHAR), which Trino rejects #12106

Description

@Ramin314

What happened?

Casting a struct (or map) value to string on the Trino / Athena backend compiles to a plain varchar cast of a ROW, which Trino rejects with Cannot cast row(...) to varchar. Trino's way to render a row as text is json_format(CAST(x AS JSON)), which is what DuckDB's to_json corresponds to on that backend.

import ibis
t = ibis.table({"k": "string"}, name="t")
print(ibis.to_sql(t.select(a=ibis.struct({"k": t.k}).cast("string")), dialect="trino"))
SELECT CAST(TRY_CAST(ROW("t0"."k") AS ROW("k" VARCHAR)) AS VARCHAR) AS "a" FROM "t" AS "t0"

Note also that the JSON route CAST(CAST(row AS JSON) AS VARCHAR) is not a fix: Trino only allows JSON→varchar for JSON strings and raises INVALID_CAST_ARGUMENT: Cannot cast '{...}' to varchar at run time for objects. json_format(CAST(row AS JSON)) is the serialisation Trino runs.

Either visit_Cast should spell struct/map/array → string as json_format(cast(arg as json)) on Trino, or the cast should be declared unsupported so it fails at compile time rather than at the engine.

What version of ibis are you using?

12.0.0

What backend(s) are you using, if any?

Trino, Athena

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