[
https://issues.apache.org/jira/browse/CALCITE-4265?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17260200#comment-17260200
]
Louis Kuang commented on CALCITE-4265:
--------------------------------------
I see. I misunderstood this Jira ticket then. I see three cases of input to the
`CAST(value AS type)` function:
# `type` is not a valid type in Calcite - this is the "the error should be
simply "{{Invalid type 'SIGNED'}}". Nothing to do with CAST." case you mentioned
# `type` is a recognized type in Calcite but `type` is not a valid LHS as
defined in
[https://calcite.apache.org/docs/reference.html#explicit-type-conversion] -
this is a parse error and should be tied to CAST
# `type` is a valid LHS but `value` --> `type` is an invalid cast - there is
`canotCastValue` for this case
[https://github.com/apache/calcite/blob/4d413bb21fb0a18882c5066f1d75a02d5b021bac/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java#L141]
>From what you are saying, it seems that 2 & 3 are not differentiated. If
>that's the case, then this Jira ticket is really only about case #1. It
>suffices to replace the current `UnsupportedOperationException` exception with
>a more informative exception like `SqlValidatorException` with a better error
>message like "{{Invalid type 'SIGNED'}}". Is my understanding correct?
> Improve error message when CAST to unknown type
> -----------------------------------------------
>
> Key: CALCITE-4265
> URL: https://issues.apache.org/jira/browse/CALCITE-4265
> Project: Calcite
> Issue Type: Bug
> Reporter: Julian Hyde
> Priority: Major
> Labels: pull-request-available
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> Improve error message when {{CAST}} to unknown type. If you add the following
> test case to {{RelToSqlConverterTest}}, you get an
> {{UnsupportedOperationException}} during validation due to the unknown
> datatype {{SIGNED}}:
> {code}
> @Test void testSelectFromUnionGrouping() {
> String query = "SELECT CASE WHEN \"t3\".\"groupingVal\" IN (0, 1) THEN
> \"t\".\"fname\" ELSE NULL END AS name, "
> + "CASE WHEN \"t3\".\"groupingVal\" = 0 THEN \"t\".\"birthdate\" ELSE
> NULL END AS birthdate, AVG(\"t\".\"__f2\") AS "
> + "\"__f2\", CAST(CASE WHEN \"t3\".\"groupingVal\" = 0 THEN 0 ELSE 1 END
> AS SIGNED) AS \"__f3\", CAST(CASE WHEN"
> + " \"t3\".\"groupingVal\" IN (0, 1) THEN 0 ELSE 1 END + CASE WHEN
> \"t3\".\"groupingVal\" = 0 THEN 0 ELSE 2 "
> + "END AS SIGNED) AS \"__f4\"\n"
> + "FROM (SELECT \"fname\", \"birthdate\", \"total_children\" + 2 AS
> \"__f2\"\n"
> + "FROM \"foodmart\".\"customer\") AS \"t\",\n"
> + "(SELECT 0 AS \"groupingVal\"\n"
> + "UNION ALL\n"
> + "SELECT 1 AS \"groupingVal\"\n"
> + "UNION ALL\n"
> + "SELECT 2 AS \"groupingVal\") AS \"t3\"\n"
> + "GROUP BY CASE WHEN \"t3\".\"groupingVal\" IN (0, 1) THEN
> \"t\".\"fname\" ELSE NULL END, CASE WHEN \"t3\""
> + ".\"groupingVal\" = 0 THEN \"t\".\"birthdate\" ELSE NULL END,
> \"t3\".\"groupingVal\"";
> sql(query).ok("--");
> }{code} throws
> {noformat}
> java.lang.UnsupportedOperationException: class
> org.apache.calcite.sql.SqlIdentifier: SIGNED
> at org.apache.calcite.util.Util.needToImplement(Util.java:1074)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeType(SqlValidatorImpl.java:1655)
> at
> org.apache.calcite.sql.SqlUserDefinedTypeNameSpec.deriveType(SqlUserDefinedTypeNameSpec.java:49)
> at
> org.apache.calcite.sql.SqlDataTypeSpec.deriveType(SqlDataTypeSpec.java:222)
> at
> org.apache.calcite.sql.SqlDataTypeSpec.deriveType(SqlDataTypeSpec.java:209)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5868)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5753)
> at
> org.apache.calcite.sql.SqlDataTypeSpec.accept(SqlDataTypeSpec.java:186)
> {noformat}
> If you change {{SIGNED}} to {{INTEGER}} the exception goes away.
> Clearly this test case is not minimal. There could probably be a 1 line test
> case for {{SqlValidatorTest}}.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)