You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importibisimportsqlglotsqlglot.__version__# '25.20.2's1=ibis.struct({"i": 1, "s": "foo"})
s2=ibis.struct({"i": ibis.literal(1), "s": ibis.literal("foo")})
e1=s1.cast("struct<s: string, i: int32>").name("x")
e2=s2.cast("struct<s: string, i: int32>").name("x")
e1.execute() # Workss1.op() # Literalprint(ibis.to_sql(e1))
# SELECT CAST(CAST(ROW(1, 'foo') AS STRUCT("i" TINYINT, "s" TEXT)) AS STRUCT("s" TEXT, "i" INT)) AS "x"e2.execute() # ConversionException: Conversion Error: Could not convert string 'foo' to INT32s1.op() # StructColumnprint(ibis.to_sql(e2))
# SELECT CAST(ROW(1, 'foo') AS STRUCT("s" TEXT, "i" INT)) AS "x"
I think the solution would be to add the explicit CAST to the StructColumn compilation, to match how the Literal is compiled? It obviously isn't always needed, based on how all tests are currently passing, but it appears to be context-dependent on where the val is getting used, and I think I would like to just remove any possibility of bugs, even if it sometimes more verbose than needed.
It also could be considered a bug in sqlglot, because in the sqlglot IR, there is enough info to see what the correct thing to do is:
What happened?
I think the solution would be to add the explicit CAST to the StructColumn compilation, to match how the Literal is compiled? It obviously isn't always needed, based on how all tests are currently passing, but it appears to be context-dependent on where the val is getting used, and I think I would like to just remove any possibility of bugs, even if it sometimes more verbose than needed.
It also could be considered a bug in sqlglot, because in the sqlglot IR, there is enough info to see what the correct thing to do is:
eg is sqlglot's implementation for compiling Cast was really clever, they would see this reordering and fix it.
What version of ibis are you using?
main
What backend(s) are you using, if any?
duckdb, IDK if it is present in others.
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: