You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues-all@impala.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2023/03/05 23:54:00 UTC

[jira] [Commented] (IMPALA-11960) Incorrect expression rewrites of date and timestamp conjuncts

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

ASF subversion and git services commented on IMPALA-11960:
----------------------------------------------------------

Commit 3573db68c83918126337c9267140b7fa36f153e4 in impala's branch refs/heads/master from Csaba Ringhofer
[ https://gitbox.apache.org/repos/asf?p=impala.git;h=3573db68c ]

IMPALA-11960: Fix constant propagation from TIMESTAMP to DATE

The constant propagation introduced in IMPALA-10064 handled conversion
of < and > predicates from timestamps to dates incorrectly.

Example:
select * from functional.alltypes_date_partition
  where date_col = cast(timestamp_col as date)
    and timestamp_col > '2009-01-01 01:00:00'
    and timestamp_col < '2009-02-01 01:00:00';

Before this change query rewrites added the following predicates:
date_col > DATE '2009-01-01' AND date_col < DATE '2009-02-01'
This incorrectly rejected all timestamps on the days of the
lower / upper bounds.

The fix is to rewrite < and > to <= and >= in the date predicates.

< could be kept if the upper bound is a constant with no time-of-day
part, e.g. timestamp_col < "2009-01-01" could be rewritten to
date_col < "2009-01-01", but this optimization is not added in this
patch to make it simpler.

Testing:
- added planner + EE regression tests

Change-Id: I1938bf5e91057b220daf8a1892940f674aac3d68
Reviewed-on: http://gerrit.cloudera.org:8080/19572
Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>


> Incorrect expression rewrites of date and timestamp conjuncts
> -------------------------------------------------------------
>
>                 Key: IMPALA-11960
>                 URL: https://issues.apache.org/jira/browse/IMPALA-11960
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Frontend
>            Reporter: Csaba Ringhofer
>            Priority: Major
>              Labels: correctness
>
> To reproduce:
> {code}
> create table t3 (b timestamp, ti date);
> insert into t3 values ("2023-01-01 09:00:00", "2023-01-01");
> enable_expr_rewrites=true;
> select * from t3 where ti = cast(b as date) and  b <'2023-01-01 15:00:00';
> -- returned 0 row
> enable_expr_rewrites=false;
> select * from t3 where ti = cast(b as date) and  b <'2023-01-01 15:00:00';
> -- returned 1 row
> {code}
> The cause seems to be that a conjunct like ti <cast(cast('2023-01-01 15:00:00' as timestamp) as date) is created during
> https://github.com/apache/impala/blob/23c265d12804c91c08a08a0be92c155424ea3d99/fe/src/main/java/org/apache/impala/planner/SingleNodePlanner.java#L1860
> Casting the right side to date leads to truncating the time part and rejecting values during the given day.
> The issue was probably introduced by IMPALA-10064:



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-all-unsubscribe@impala.apache.org
For additional commands, e-mail: issues-all-help@impala.apache.org