IMPALA-4614: Set eval cost of timestamp literals.

The main issue was that the eval cost was not set for
timestamp literals, so a preconditions check was hit
when trying to order a list of conjuncts by cost.

Another subtle issue made the bug only reproducible by
a specific query against a Kudu table in our tests,
although the bug is not Kudu specific: The eval cost
of Exprs was not recomputed in analyze(), even after
resetting an Expr, e.g., during a substitution. As a
result, the bug was only reproducible for a list
of conjuncts that contained an inferred predicate
with a timestamp literal.
This patch does not contain a fix for that issue due
to its complexity/risk. It is tracked in IMPALA-4620.

Testing: Ran planner tests locally. Ran query_test.py
locally. A private core/hdfs run passed.

Change-Id: Ife30420bafbd1c64a5e3385e5755909110b4b354
Reviewed-on: http://gerrit.cloudera.org:8080/5404
Reviewed-by: Alex Behm <[email protected]>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/eaa14f27
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/eaa14f27
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/eaa14f27

Branch: refs/heads/hadoop-next
Commit: eaa14f275066a5f29a9c286316f43deb9803feea
Parents: 5ec0eed
Author: Alex Behm <[email protected]>
Authored: Wed Dec 7 10:52:17 2016 -0800
Committer: Impala Public Jenkins <[email protected]>
Committed: Thu Dec 8 04:31:12 2016 +0000

----------------------------------------------------------------------
 .../impala/analysis/TimestampLiteral.java       |  1 +
 .../queries/PlannerTest/conjunct-ordering.test  | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/eaa14f27/fe/src/main/java/org/apache/impala/analysis/TimestampLiteral.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/TimestampLiteral.java 
b/fe/src/main/java/org/apache/impala/analysis/TimestampLiteral.java
index 8f07082..6365b10 100644
--- a/fe/src/main/java/org/apache/impala/analysis/TimestampLiteral.java
+++ b/fe/src/main/java/org/apache/impala/analysis/TimestampLiteral.java
@@ -45,6 +45,7 @@ public class TimestampLiteral extends LiteralExpr {
     value_ = value;
     strValue_ = strValue;
     type_ = Type.TIMESTAMP;
+    evalCost_ = Expr.LITERAL_COST;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/eaa14f27/testdata/workloads/functional-planner/queries/PlannerTest/conjunct-ordering.test
----------------------------------------------------------------------
diff --git 
a/testdata/workloads/functional-planner/queries/PlannerTest/conjunct-ordering.test
 
b/testdata/workloads/functional-planner/queries/PlannerTest/conjunct-ordering.test
index af45129..9b998c6 100644
--- 
a/testdata/workloads/functional-planner/queries/PlannerTest/conjunct-ordering.test
+++ 
b/testdata/workloads/functional-planner/queries/PlannerTest/conjunct-ordering.test
@@ -175,3 +175,23 @@ PLAN-ROOT SINK
    partitions=24/24 files=24 size=478.45KB
    predicates: a.id = 0, a.int_col = 0
 ====
+# IMPALA-4614: Tests that the eval cost of timestamp literals is set.
+# The HAVING predicate is assigned to the scan and tests that it has
+# an eval cost set after being substituted and re-analyzed.
+select count(*) from functional.alltypes
+where int_col < 10 and
+  timestamp_col < cast('2010-01-02 01:05:20' as timestamp)
+  and timestamp_col != cast(date_string_col as timestamp)
+group by timestamp_col
+having timestamp_col < cast('2010-01-01 01:05:20' as timestamp)
+---- PLAN
+PLAN-ROOT SINK
+|
+01:AGGREGATE [FINALIZE]
+|  output: count(*)
+|  group by: timestamp_col
+|
+00:SCAN HDFS [functional.alltypes]
+   partitions=24/24 files=24 size=478.45KB
+   predicates: functional.alltypes.timestamp_col < TIMESTAMP '2010-01-01 
01:05:20', int_col < 10, timestamp_col < TIMESTAMP '2010-01-02 01:05:20', 
timestamp_col != CAST(date_string_col AS TIMESTAMP)
+====

Reply via email to