Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4265

Improve error message when CAST to unknown type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.27.0
    • None

    Description

      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:

      @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("--");
        }

      throws

      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)
      

      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.

      Attachments

        Activity

          People

            danny0405 Danny Chen
            julianhyde Julian Hyde
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 3h 40m
                3h 40m