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

In EXTRACT function, support MICROSECONDS, MILLISECONDS, EPOCH, ISODOW, ISOYEAR and DECADE time units

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.17.0, avatica-1.13.0
    • Component/s: core
    • Labels:
      None

      Description

      Here CALCITE-1177 were supported new units
      however such test

        @Test public void testDecadeFunction() throws Exception {
          ExpressionChecker checker = new ExpressionChecker()
                  .addExpr("EXTRACT(DECADE FROM ts)", 199L)
                  ;
          checker.buildRunAndCheck();
        }
      

      failed like
      Extract for time unit: DECADE not supported!

      SQL:>
      SELECT EXTRACT(DECADE FROM ts) FROM PCOLLECTION
      May 08, 2018 1:34:58 PM org.apache.beam.sdk.extensions.sql.impl.planner.BeamQueryPlanner validateAndConvert
      INFO: SQL:
      SELECT EXTRACT(DECADE FROM `PCOLLECTION`.`ts`)
      FROM `PCOLLECTION` AS `PCOLLECTION`
      May 08, 2018 1:34:58 PM org.apache.beam.sdk.extensions.sql.impl.planner.BeamQueryPlanner convertToBeamRel
      INFO: SQLPlan>
      LogicalProject(EXPR$0=[EXTRACT(FLAG(DECADE), $0)])
        BeamIOSourceRel(table=[[PCOLLECTION]])
      
      
      java.lang.RuntimeException: org.apache.beam.sdk.Pipeline$PipelineExecutionException: java.lang.UnsupportedOperationException: Extract for time unit: DECADE not supported!
      
      	at org.apache.beam.sdk.extensions.sql.integrationtest.BeamSqlBuiltinFunctionsIntegrationTestBase$ExpressionChecker.buildRunAndCheck(BeamSqlBuiltinFunctionsIntegrationTestBase.java:167)
      	at org.apache.beam.sdk.extensions.sql.integrationtest.BeamSqlDateFunctionsIntegrationTest.testDecadeFunction(BeamSqlDateFunctionsIntegrationTest.java:66)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.apache.beam.sdk.testing.TestPipeline$1.evaluate(TestPipeline.java:317)
      	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
      Caused by: org.apache.beam.sdk.Pipeline$PipelineExecutionException: java.lang.UnsupportedOperationException: Extract for time unit: DECADE not supported!
      	at org.apache.beam.runners.direct.DirectRunner$DirectPipelineResult.waitUntilFinish(DirectRunner.java:349)
      	at org.apache.beam.runners.direct.DirectRunner$DirectPipelineResult.waitUntilFinish(DirectRunner.java:319)
      	at org.apache.beam.runners.direct.DirectRunner.run(DirectRunner.java:210)
      	at org.apache.beam.runners.direct.DirectRunner.run(DirectRunner.java:66)
      	at org.apache.beam.sdk.Pipeline.run(Pipeline.java:311)
      	at org.apache.beam.sdk.testing.TestPipeline.run(TestPipeline.java:346)
      	at org.apache.beam.sdk.testing.TestPipeline.run(TestPipeline.java:328)
      	at org.apache.beam.sdk.extensions.sql.integrationtest.BeamSqlBuiltinFunctionsIntegrationTestBase$ExpressionChecker.buildRunAndCheck(BeamSqlBuiltinFunctionsIntegrationTestBase.java:165)
      	... 25 more
      Caused by: java.lang.UnsupportedOperationException: Extract for time unit: DECADE not supported!
      	at org.apache.beam.sdk.extensions.sql.impl.interpreter.operator.date.BeamSqlExtractExpression.evaluate(BeamSqlExtractExpression.java:92)
      	at org.apache.beam.sdk.extensions.sql.impl.interpreter.BeamSqlFnExecutor.execute(BeamSqlFnExecutor.java:505)
      	at org.apache.beam.sdk.extensions.sql.impl.transform.BeamSqlProjectFn.processElement(BeamSqlProjectFn.java:57)
      
      

      I guess here org.apache.calcite.avatica.util.DateTimeUtils#julianExtract
      should be added something like

      case DECADE:
      				return year > 0
      					? (year + 9) / 10
      					: (year - 9) / 10;
      

      or do I do something not right?

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                julianhyde Julian Hyde
                Reporter:
                Sergey Nuyanzin Sergey Nuyanzin
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: