[CALCITE-5987] SqlImplementor loses type information for literals - #5108
[CALCITE-5987] SqlImplementor loses type information for literals#5108mihaibudiu wants to merge 1 commit into
SqlImplementor loses type information for literals#5108Conversation
|
@mihaibudiu need fix conflict first |
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
|
I have fixed the conflicts. This is a "safe" change, since it adds a new configuration flag to SqlImplementer. If the flag is not set the behavior is unchanged. As discussed briefly in Jira (a long time ago) I think this is actually a very useful feature: it will allow you to use RelToSql and then SqlToRel and get back the same program (almost always, sometimes RelToSql does some weird rewrites). This is not happening today for many programs. |
|
| case NULL: | ||
| case ANY: | ||
| case UNKNOWN: | ||
| // No valid SQL syntax for casts to these types |
There was a problem hiding this comment.
for NULL/ANY/UNKNOWN we just return the literal as-is since there's no valid CAST syntax. Are these types actually reachable for a RexLiteral here, or is this purely defensive? Also, does the round-trip test suite cover a bare top-level NULL literal (not nested in a ROW) to confirm we're not silently losing type info on that path?
There was a problem hiding this comment.
I would expect the NULL case is reachable, e.g., in a query like SELECT NULL, which is legal.
There are actually about 500+ round-trip tests added: the subclass RelToSqlConverterRoundTripTest runs almost every test from RelToSqlConverterTest. There are several tests that contain a SELECT NULL pattern.



Jira Link
CALCITE-5987
Changes Proposed
Added an option to
SqlImplementorthat enables it to preserve types for literals. For example, today a literal emitted as5.0could be aDOUBLE,REAL,FLOAT, orDECIMAL. With this flag the output would beCAST(5.0 AS REAL), making the type explicit.There is a new subclass of
RelToSelConvertercalledRelToSqlConverterRoundTripwhich executes all the tests forRelToSqlfor the Calcite dialect by checking that with this change the produced SQL has enough information to reconstruct the "original" program.