[
https://issues.apache.org/jira/browse/CALCITE-2303?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16480420#comment-16480420
]
Sergey Nuyanzin edited comment on CALCITE-2303 at 5/18/18 11:46 AM:
--------------------------------------------------------------------
I guess I found the answer for the question related to epoch in class
_org.apache.calcite.adapter.enumerable.RexImpTable.ExtractImplementor_
the main 3 questions:
# should DOW be aligned with Postgres doc or not?
# should DECADE be the same as for postgresql i.e. just year divided by 10?
# should WEEK be fixed in the same way as ISO 8601 and Postgresql e.g. testcase
{code:sql}SELECT EXTRACT(WEEK FROM DATE '2012-12-31');
Result 53{code} while based on Postgres doc and
http://myweb.ecu.edu/mccartyr/isowdcal.html it should be 1?
[~julianhyde] could you please clarify it?
here are some more discrepancies after going through the docs
[https://www.postgresql.org/docs/9.1/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT]
(timezone is not considered at the moment)
if you do not mind I could cover it within this ticket
||Extract field name||Postgresql doc||Calcite||
|DOW|In Postgres docs it is declared as The day of the week as Sunday (0) to
Saturday (6) e.g. {code:sql}SELECT EXTRACT(DOW FROM TIMESTAMP '2001-02-16
20:38:40');
Result: 5{code}| In Calcite it is implemented like // sun=1, sat=7
{code:sql}SELECT EXTRACT(DOW FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 6{code} |
|DECADE|The year field divided by 10| I implemented with the same approach as
for century which is wrong. I will fix it like in Postgresq|
|WEEK| Based on spec 2012-12-31 is part of the first week of 2013| Does not
work properly for 2012-12-31 where it is a part of the first week of 2013|
|ISODOW|The day of the week as Monday (1) to Sunday (7) e.g. {code:sql}SELECT
EXTRACT(ISODOW FROM TIMESTAMP '2001-02-18 20:38:40');
Result: 7{code}|not supported |
|ISOYEAR|The ISO 8601 week-numbering year that the date falls in (not
applicable to intervals) e.g. {code:sql}SELECT EXTRACT(ISOYEAR FROM DATE
'2006-01-01');
Result: 2005
SELECT EXTRACT(ISOYEAR FROM DATE '2006-01-02');
Result: 2006{code}| not supported|
|MICROSECONDS|e.g. {code:sql}SELECT EXTRACT(MICROSECONDS FROM TIME
'17:12:28.5');
{code}| not supported|
|MILLISECONDS|e.g. {code:sql}SELECT EXTRACT(MILLISECONDS FROM TIME
'17:12:28.5');
{code}| not supported|
was (Author: sergey nuyanzin):
I guess I found the answer for the question related to epoch in class
_org.apache.calcite.adapter.enumerable.RexImpTable.ExtractImplementor_
the main 3 questions:
# should DOW be aligned with Postgres doc or not?
# should DECADE be the same as for postgresql i.e. just year divided by 10?
# should WEEK be fixed in the same way as ISO 8601 and Postgresql e.g. testcase
{code:sql}SELECT EXTRACT(WEEK FROM DATE '2012-12-31');{code}?
[~julianhyde] could you please clarify it?
here are some more discrepancies after going through the docs
[https://www.postgresql.org/docs/9.1/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT]
(timezone is not considered at the moment)
if you do not mind I could cover it within this ticket
||Extract field name||Postgresql doc||Calcite||
|DOW|In Postgres docs it is declared as The day of the week as Sunday (0) to
Saturday (6) e.g. {code:sql}SELECT EXTRACT(DOW FROM TIMESTAMP '2001-02-16
20:38:40');
Result: 5{code}| In Calcite it is implemented like // sun=1, sat=7
{code:sql}SELECT EXTRACT(DOW FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 6{code} |
|DECADE|The year field divided by 10| I implemented with the same approach as
for century which is wrong. I will fix it like in Postgresq|
|WEEK| Based on spec 2012-12-31 is part of the first week of 2013| Does not
work properly for 2012-12-31 where it is a part of the first week of 2013|
|ISODOW|The day of the week as Monday (1) to Sunday (7) e.g. {code:sql}SELECT
EXTRACT(ISODOW FROM TIMESTAMP '2001-02-18 20:38:40');
Result: 7{code}|not supported |
|ISOYEAR|The ISO 8601 week-numbering year that the date falls in (not
applicable to intervals) e.g. {code:sql}SELECT EXTRACT(ISOYEAR FROM DATE
'2006-01-01');
Result: 2005
SELECT EXTRACT(ISOYEAR FROM DATE '2006-01-02');
Result: 2006{code}| not supported|
|MICROSECONDS|e.g. {code:sql}SELECT EXTRACT(MICROSECONDS FROM TIME
'17:12:28.5');
{code}| not supported|
|MILLISECONDS|e.g. {code:sql}SELECT EXTRACT(MILLISECONDS FROM TIME
'17:12:28.5');
{code}| not supported|
> Extract for time unit: DECADE not supported!
> --------------------------------------------
>
> Key: CALCITE-2303
> URL: https://issues.apache.org/jira/browse/CALCITE-2303
> Project: Calcite
> Issue Type: Bug
> Reporter: Sergey Nuyanzin
> Assignee: Julian Hyde
> Priority: Major
>
> 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)