You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by "Chinmay Kulkarni (Jira)" <ji...@apache.org> on 2019/12/21 00:55:06 UTC

[jira] [Closed] (PHOENIX-5388) Incorrect current_date()/now() when query involves subquery

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

Chinmay Kulkarni closed PHOENIX-5388.
-------------------------------------

Bulk closing Jiras for the 4.15.0 release.

> Incorrect current_date()/now() when query involves subquery
> -----------------------------------------------------------
>
>                 Key: PHOENIX-5388
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-5388
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Ankit Singhal
>            Assignee: Ankit Singhal
>            Priority: Major
>             Fix For: 4.15.0, 5.1.0
>
>         Attachments: PHOENIX-5388.patch, PHOENIX-5388_v2.patch
>
>
> Following query fails in the month of December:-
> {code}
> select  NOW(),  MONTH(NOW()) m, 
> CASE 
>  WHEN MONTH(NOW()) = 12 THEN TO_TIME(YEAR(NOW()) || '-12-31 23:59:59.999') 
>  ELSE TO_TIME(YEAR(NOW()) || '-' || ( MONTH(NOW()) + 1  ) || '-01 23:59:59.999') - 1 
> END  AS this_month_end
> {code}
> It is due to an optimization we have during compilation where we evaluate the expression if they result in to constant so that we don't need to do it for every row. 
> Currently parsing stack evaluates every expression if possible without considering any condition, resulting in evaluation of all three expression for CASE node, MONTH(NOW()) = 12 , TO_TIME(YEAR(NOW()) || '-12-31 23:59:59.999') ,TO_TIME(YEAR(NOW()) || '-' || ( MONTH(NOW()) + 1  ) || '-01 23:59:59.999') - 1) but evaluation of 3rd one will fail because of invalid month. 
> Workaround: For the particular use-case , Following query though help in preventing the expressions of WHEN CASE to be evaluated to a constant at compile time. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)