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
What happened?
Casting a struct (or map) value to
stringon the Trino / Athena backend compiles to a plain varchar cast of aROW, which Trino rejects withCannot cast row(...) to varchar. Trino's way to render a row as text isjson_format(CAST(x AS JSON)), which is what DuckDB'sto_jsoncorresponds to on that backend.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 raisesINVALID_CAST_ARGUMENT: Cannot cast '{...}' to varcharat run time for objects.json_format(CAST(row AS JSON))is the serialisation Trino runs.Either
visit_Castshould spell struct/map/array → string asjson_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