impala-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sail...@apache.org
Subject [1/6] incubator-impala git commit: IMPALA-5145: Do not constant fold null in CastExprs
Date Fri, 21 Apr 2017 00:40:44 GMT
Repository: incubator-impala
Updated Branches:
  refs/heads/master a2805ca6f -> baba8960b


IMPALA-5145: Do not constant fold null in CastExprs

Constant folding null values in CastExprs causes CTAS statements
to fail. This regresses the observed behavior before constant folding
was introduced. This change does not constant fold null in CastExprs.

Change-Id: Ia7aa1ab7f53a9dcc7560ded321a9d1e1ee2d18e3
Reviewed-on: http://gerrit.cloudera.org:8080/6663
Reviewed-by: Alex Behm <alex.behm@cloudera.com>
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/8660c404
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/8660c404
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/8660c404

Branch: refs/heads/master
Commit: 8660c404c93673559c639cf7306c0a6f7ab9001f
Parents: a2805ca
Author: aphadke <aphadke@cloudera.com>
Authored: Mon Apr 17 17:52:18 2017 -0700
Committer: Impala Public Jenkins <impala-public-jenkins@gerrit.cloudera.org>
Committed: Thu Apr 20 19:39:17 2017 +0000

----------------------------------------------------------------------
 .../org/apache/impala/rewrite/FoldConstantsRule.java    | 12 ++++++++++++
 .../queries/PlannerTest/aggregation.test                |  2 +-
 .../queries/QueryTest/create-table-as-select.test       |  6 ++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/8660c404/fe/src/main/java/org/apache/impala/rewrite/FoldConstantsRule.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/rewrite/FoldConstantsRule.java b/fe/src/main/java/org/apache/impala/rewrite/FoldConstantsRule.java
index 146dd83..3437531 100644
--- a/fe/src/main/java/org/apache/impala/rewrite/FoldConstantsRule.java
+++ b/fe/src/main/java/org/apache/impala/rewrite/FoldConstantsRule.java
@@ -20,6 +20,9 @@ package org.apache.impala.rewrite;
 import org.apache.impala.analysis.Analyzer;
 import org.apache.impala.analysis.Expr;
 import org.apache.impala.analysis.LiteralExpr;
+import org.apache.impala.analysis.NullLiteral;
+import org.apache.impala.analysis.CastExpr;
+
 import org.apache.impala.common.AnalysisException;
 
 /**
@@ -47,6 +50,15 @@ public class FoldConstantsRule implements ExprRewriteRule {
     // children should have been folded at this point.
     for (Expr child: expr.getChildren()) if (!child.isLiteral()) return expr;
     if (expr.isLiteral() || !expr.isConstant()) return expr;
+
+    // Do not constant fold cast(null as dataType) because we cannot preserve the
+    // cast-to-types and that can lead to query failures, e.g., CTAS
+    if (expr instanceof CastExpr) {
+      CastExpr castExpr = (CastExpr) expr;
+      if (castExpr.getChild(0) instanceof NullLiteral) {
+        return expr;
+      }
+    }
     // Analyze constant exprs, if necessary. Note that the 'expr' may become non-constant
     // after analysis (e.g., aggregate functions).
     if (!expr.isAnalyzed()) {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/8660c404/testdata/workloads/functional-planner/queries/PlannerTest/aggregation.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-planner/queries/PlannerTest/aggregation.test b/testdata/workloads/functional-planner/queries/PlannerTest/aggregation.test
index a92cee3..a1177b0 100644
--- a/testdata/workloads/functional-planner/queries/PlannerTest/aggregation.test
+++ b/testdata/workloads/functional-planner/queries/PlannerTest/aggregation.test
@@ -725,7 +725,7 @@ PLAN-ROOT SINK
 |
 01:AGGREGATE [FINALIZE]
 |  output: count(*)
-|  group by: bool_col, NULL
+|  group by: bool_col, CAST(NULL AS INT)
 |
 00:SCAN HDFS [functional.alltypestiny]
    partitions=4/4 files=4 size=460B

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/8660c404/testdata/workloads/functional-query/queries/QueryTest/create-table-as-select.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/create-table-as-select.test
b/testdata/workloads/functional-query/queries/QueryTest/create-table-as-select.test
index 2178589..9090d61 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/create-table-as-select.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/create-table-as-select.test
@@ -183,3 +183,9 @@ create table $DATABASE.rand_ctas as select rand() from functional.alltypes;
 'Inserted 7300 row(s)'
 ---- ERRORS
 ====
+---- QUERY
+# IMPALA-5145: Do not constant fold null in CastExprs
+create table if not exists cast_null_as_int as (select cast(null as int) c);
+---- RESULTS
+'Inserted 1 row(s)'
+====


Mime
View raw message