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

sql->rel->sql bug with unparsing timestampdiff

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • None
    • None
    • jdbc-adapter
    • None

    Description

      e.g. the following test in RelToSqlConverter.java demonstrates the end-to-end problem:

       

      @Test void testTimestampDiff() {
       final String query = "select timestampdiff(day, a.\"hire_date\", b.\"hire_date\") "
       + "from \"employee\" a join \"employee\" b using (\"employee_id\")";
       final String expected = "TBD, can't get it to generate right now";
       sql(query).ok(expected);
      }

      throws, top of stack:

      class org.apache.calcite.sql.SqlSyntax$7: SPECIAL
      java.lang.UnsupportedOperationException: class org.apache.calcite.sql.SqlSyntax$7: SPECIAL
      	at org.apache.calcite.util.Util.needToImplement(Util.java:1101)
      	at org.apache.calcite.sql.SqlSyntax$7.unparse(SqlSyntax.java:129)
      	at org.apache.calcite.sql.SqlOperator.unparse(SqlOperator.java:383)
      	at org.apache.calcite.sql.SqlDialect.unparseCall(SqlDialect.java:455)
      	at org.apache.calcite.sql.SqlCall.unparse(SqlCall.java:123)
      	at org.apache.calcite.sql.SqlUtil.unparseBinarySyntax(SqlUtil.java:425)
      	at org.apache.calcite.sql.SqlSyntax$4.unparse(SqlSyntax.java:78)
      	at org.apache.calcite.sql.SqlOperator.unparse(SqlOperator.java:383)
      	at org.apache.calcite.sql.SqlDialect.unparseCall(SqlDialect.java:455)
      	at org.apache.calcite.sql.SqlCall.unparse(SqlCall.java:126)
      	at org.apache.calcite.sql.fun.SqlCastFunction.unparse(SqlCastFunction.java:181)
      	at org.apache.calcite.sql.SqlDialect.unparseCall(SqlDialect.java:455)
      	at org.apache.calcite.sql.SqlCall.unparse(SqlCall.java:126)
      	at org.apache.calcite.sql.pretty.SqlPrettyWriter$FrameImpl.list2(SqlPrettyWriter.java:1304)
      	at org.apache.calcite.sql.pretty.SqlPrettyWriter$FrameImpl.list(SqlPrettyWriter.java:1284)
      	at org.apache.calcite.sql.pretty.SqlPrettyWriter.list(SqlPrettyWriter.java:1081)
      	at org.apache.calcite.sql.SqlSelectOperator.unparse(SqlSelectOperator.java:154)
      	at org.apache.calcite.sql.SqlDialect.unparseCall(SqlDialect.java:455)
      	at org.apache.calcite.sql.SqlSelect.unparse(SqlSelect.java:261)
      	at org.apache.calcite.sql.SqlNode.toSqlString(SqlNode.java:156)
      	at org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.toSql(RelToSqlConverterTest.java:216)

      From the debugger, it looks like a SqlKind.REINTERPRET operator gets generated by the SqlToRelConverter, and nothing knows how to handle that unparsing to SQL.

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              swtalbot Steven Talbot
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: