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

UDF Error of Calcite 1.6

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.6.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      UDF Error In Calcite 1.6, may be Regression bugs?

      schema:Table:hr, A String, B String, C String, D Timestamp

      UDF: DATE_TRUNC(Timestamp D, String X) returns a timestamp value

      there a several regression bugs. 1.5 is ok, but 1.6 will throw exception:

      1. UDF in Group_by clause,
      sql:select min(m0), max(m0) from (select DATE_TRUNC(D, 'month') as d1, COUNT(A) as m0 from \"hr\" group by DATE_TRUNC(D, 'month'))

      Error Stack:
      Caused by: java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.lang.Long
      at Baz$2.apply(Unknown Source)
      at Baz$2.apply(Unknown Source)
      at org.apache.calcite.linq4j.EnumerableDefaults.groupBy_(EnumerableDefaults.java:821)
      at org.apache.calcite.linq4j.EnumerableDefaults.groupBy(EnumerableDefaults.java:754)
      at org.apache.calcite.linq4j.DefaultEnumerable.groupBy(DefaultEnumerable.java:302)
      at Baz.bind(Unknown Source)
      at org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:326)
      at org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:281)
      at org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:545)
      at org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:536)
      at org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:187)
      at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:65)
      at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:44)
      at org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:566)
      at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:578)
      at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:571)
      at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:135)
      ... 2 more

      2. select UDF

      sql: select D, DATE_TRUNC(D, 'month') from \"hr\" group by D

      throw exception when call resultSet.getTimestamp(1)
      Error stack:

      Exception in thread "main" java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.lang.Number
      at org.apache.calcite.avatica.util.AbstractCursor$NumberAccessor.getNumber(AbstractCursor.java:696)
      at org.apache.calcite.avatica.util.AbstractCursor$TimestampFromNumberAccessor.getTimestamp(AbstractCursor.java:958)
      at org.apache.calcite.avatica.AvaticaResultSet.getTimestamp(AvaticaResultSet.java:285)
      at testPs.TestPs.main(TestPs.java:150)

      3. UDFs with same name and different arg types

      UDF: DATE_TRUNC(Timestamp D, String x) returns a timestamp value
      DATE_TRUNC(Date D, String x) returns a date value

      sql: select D, DATE_TRUNC(D, 'month') from \"hr\" group by D

      Error stack:

      Caused by: org.apache.calcite.runtime.CalciteContextException: From line 1, column 11 to line 1, column 32: Cannot apply 'DATE_TRUNC' to arguments of type 'DATE_TRUNC(<TIMESTAMP(0)>, <CHAR(5)>)'. Supported form(s): 'DATE_TRUNC(<DATE>, <CHARACTER>)'
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
      at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:405)
      at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:715)
      at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:703)
      at org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:3932)
      at org.apache.calcite.sql.SqlCallBinding.newValidationSignatureError(SqlCallBinding.java:275)
      at org.apache.calcite.sql.type.FamilyOperandTypeChecker.checkSingleOperandType(FamilyOperandTypeChecker.java:92)
      at org.apache.calcite.sql.type.FamilyOperandTypeChecker.checkOperandTypes(FamilyOperandTypeChecker.java:109)
      at org.apache.calcite.sql.SqlOperator.checkOperandTypes(SqlOperator.java:564)
      at org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:421)
      at org.apache.calcite.sql.SqlDATE_TRUNCtion.deriveType(SqlDATE_TRUNCtion.java:342)
      at org.apache.calcite.sql.SqlDATE_TRUNCtion.deriveType(SqlDATE_TRUNCtion.java:230)
      at org.apache.calcite.sql.validate.SqlValidatorImpl
      ...

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                Droopyhu Wei Hu
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: