[ 
https://issues.apache.org/jira/browse/CALCITE-2303?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16494583#comment-16494583
 ] 

Laurent Goujon edited comment on CALCITE-2303 at 5/30/18 2:02 AM:
------------------------------------------------------------------

Also, for DOW, note that current Calcite behavior matches ODBC spec 
(https://docs.microsoft.com/en-us/sql/odbc/reference/appendixes/time-date-and-interval-functions?view=sql-server-2017)
{quote}
Returns the day of the week based on the week field in date_exp as an integer 
value in the range of 1–7, where 1 represents Sunday.
{quote}

Changing it to Postgres definition might break tools following that standard 
(note that the query {{SELECT EXTRACT(DOW FROM CAST('05-27-2018' AS DATE)), {fn 
DAYOFWEEK(CAST('05-27-2018' AS DATE))}} returns 0|1 in postgres...)


was (Author: laurentgo):
Also, for DOW, note that current Calcite behavior matches ODBC spec 
(https://docs.microsoft.com/en-us/sql/odbc/reference/appendixes/time-date-and-interval-functions?view=sql-server-2017)
>>>
Returns the day of the week based on the week field in date_exp as an integer 
value in the range of 1–7, where 1 represents Sunday.

Changing it to Postgres definition might break tools following that standard 
(note that the query {{SELECT EXTRACT(DOW FROM CAST('05-27-2018' AS DATE)), {fn 
DAYOFWEEK(CAST('05-27-2018' AS DATE))}} returns 0|1 in postgres...)

> Support DECADE time unit in EXTRACT function
> --------------------------------------------
>
>                 Key: CALCITE-2303
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2303
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Sergey Nuyanzin
>            Assignee: Julian Hyde
>            Priority: Major
>             Fix For: 1.17.0
>
>
> Here CALCITE-1177 were supported new units
>  however such test
> {code:java}
>   @Test public void testDecadeFunction() throws Exception {
>     ExpressionChecker checker = new ExpressionChecker()
>             .addExpr("EXTRACT(DECADE FROM ts)", 199L)
>             ;
>     checker.buildRunAndCheck();
>   }
> {code}
> failed like
>  Extract for time unit: DECADE not supported!
> {noformat}
> 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)
> {noformat}
> I guess here _org.apache.calcite.avatica.util.DateTimeUtils#julianExtract_
>  should be added something like
> {code:java}
> case DECADE:
>                               return year > 0
>                                       ? (year + 9) / 10
>                                       : (year - 9) / 10;
> {code}
> or do I do something not right?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to