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

Time expression causes IllegalStateException

    XMLWordPrintableJSON

Details

    Description

      The following SqlOperatorTest causes an exception:

          final SqlOperatorFixture f = fixture();
          f.checkScalar("time '12:03:01' + interval '25' day",
              "12:03:01", "TIME(0) NOT NULL");
      

      The exception is:

      Caused by: java.lang.IllegalStateException: Unable to implement EnumerableCalc(expr#0=[{inputs}], expr#1=[12:03:01], expr#2=[2160000000:INTERVAL DAY], expr#3=[+($t1, $t2)], EXPR$0=[$t3]): rowcount = 1.0, cumulative cost = {2.0 rows, 6.0 cpu, 0.0 io}, id = 20
        EnumerableValues(tuples=[[{ 0 }]]): rowcount = 1.0, cumulative cost = {1.0 rows, 1.0 cpu, 0.0 io}, id = 13
      
      	at org.apache.calcite.adapter.enumerable.EnumerableRelImplementor.implementRoot(EnumerableRelImplementor.java:117)
      	at org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:112)
      	at org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1171)
      	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:326)
      	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:220)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:666)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:519)
      ...
      	Suppressed: java.lang.ArithmeticException: Value 2160000000 out of range
      		at org.apache.calcite.linq4j.tree.Primitive.checkRoundedRange(Primitive.java:383)
      		at org.apache.calcite.linq4j.tree.Primitive.numberValue(Primitive.java:412)
      		at org.apache.calcite.linq4j.tree.Expressions.constant(Expressions.java:575)
      		at org.apache.calcite.linq4j.tree.OptimizeShuttle.visit(OptimizeShuttle.java:305)
      		at org.apache.calcite.linq4j.tree.UnaryExpression.accept(UnaryExpression.java:39)
      		at org.apache.calcite.linq4j.tree.BinaryExpression.accept(BinaryExpression.java:47)
      

      This seems to happen because the implementation insists in evaluating the expression by converting the 25 days interval to milliseconds, which overflows. However, adding a days interval to a time should be a noop. Replacing 'days' with 'months', for example, works fine.

      Attachments

        Issue Links

          Activity

            People

              mbudiu Mihai Budiu
              mbudiu Mihai Budiu
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: