[ 
https://issues.apache.org/jira/browse/CALCITE-4265?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17261702#comment-17261702
 ] 

Julian Hyde commented on CALCITE-4265:
--------------------------------------

{quote}It suffices to replace the current `UnsupportedOperationException` 
exception with a more informative exception 
{quote}
Yes and no. Yes, the user should receive a more informative exception. But that 
exception would not necessarily be thrown from the same code location.

> 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: 1.5h
>  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)

Reply via email to