You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (JIRA)" <ji...@apache.org> on 2018/06/12 20:40:00 UTC

[jira] [Updated] (CALCITE-2324) EXTRACT function: HOUR, MINUTE and SECOND parts of a DATE must be zero

     [ https://issues.apache.org/jira/browse/CALCITE-2324?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julian Hyde updated CALCITE-2324:
---------------------------------
    Summary: EXTRACT function: HOUR, MINUTE and SECOND parts of a DATE must be zero  (was: Extract seconds, minutes from date works not correct in some cases)

> EXTRACT function: HOUR, MINUTE and SECOND parts of a DATE must be zero
> ----------------------------------------------------------------------
>
>                 Key: CALCITE-2324
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2324
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.16.0
>            Reporter: Sergey Nuyanzin
>            Assignee: Julian Hyde
>            Priority: Major
>             Fix For: 1.17.0
>
>
> While working on tests for CALCITE-2303 faced with the next issue (do not fix within 2303 as the fix does not need avatica update while 2303 does)
> {code:sql}select extract(second from date '2008-02-23');{code} returns 13
> I guess the issue is known because of the test is present in _org.apache.calcite.sql.test.SqlOperatorBaseTest#testExtractDate_ within _TODO_ block and with the comment {code:java}  if (TODO) {
>       // Looks like there is a bug in current execution code which returns 13
>       // instead of 0
>       tester.checkScalar(
>           "extract(second from date '2008-2-23')",
>           "0",
>           "BIGINT NOT NULL");
>     }{code}
> I deep dive into it and realized that the problem is that in case of DATE extract works with days + in case of seconds, minute, hours there will be used _org.apache.calcite.adapter.enumerable.RexImpTable#getFactor_. And finally the result is 
> {noformat}number_of_days % 60000 / 1000L //for extract seconds{noformat}
> {noformat}number_of_days % 360000 / 1000L //for extract minutes{noformat}
> and yes {code}select extract(minute from date '1700-01-01');{code} returns -1



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