You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2016/05/23 15:40:40 UTC

[14/17] incubator-impala git commit: IMPALA-3537: Move useHiveColLabels out of GlobalState and into Analyzer.

IMPALA-3537: Move useHiveColLabels out of GlobalState and into Analyzer.

The bug: The useHiveColLabels flag was set in the Analyzer's global
state, so changes to the labelling scheme incorrectly leaked into
other query blocks, e.g., ancestor blocks. This could affect the colunm
labels of the final query results.

The flag really is a property of a specific query block, and not all
query blocks, so the fix is to make the flag a member of Analyzer.

Change-Id: Ie1e446474e1862c78dffd5192a175e043a1d0e90
Reviewed-on: http://gerrit.cloudera.org:8080/3133
Reviewed-by: Alex Behm <al...@cloudera.com>
Tested-by: Internal 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/ca8ac350
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/ca8ac350
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/ca8ac350

Branch: refs/heads/master
Commit: ca8ac3505554fd3c1bd5fbb18f2c49897a8b9c01
Parents: bd6b16f
Author: Alex Behm <al...@cloudera.com>
Authored: Wed May 18 19:59:52 2016 -0700
Committer: Tim Armstrong <ta...@cloudera.com>
Committed: Mon May 23 08:40:20 2016 -0700

----------------------------------------------------------------------
 .../java/com/cloudera/impala/analysis/Analyzer.java  | 15 ++++++++-------
 .../cloudera/impala/analysis/AnalyzeStmtsTest.java   |  7 +++++++
 2 files changed, 15 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/ca8ac350/fe/src/main/java/com/cloudera/impala/analysis/Analyzer.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/com/cloudera/impala/analysis/Analyzer.java b/fe/src/main/java/com/cloudera/impala/analysis/Analyzer.java
index 7c77351..f96b3c5 100644
--- a/fe/src/main/java/com/cloudera/impala/analysis/Analyzer.java
+++ b/fe/src/main/java/com/cloudera/impala/analysis/Analyzer.java
@@ -118,7 +118,10 @@ public class Analyzer {
 
   private final User user_;
 
-  // true if the corresponding select block has a limit and/or offset clause
+  // Whether to use Hive's auto-generated column labels.
+  private boolean useHiveColLabels_ = false;
+
+  // True if the corresponding select block has a limit and/or offset clause.
   private boolean hasLimitOffsetClause_ = false;
 
   // Current depth of nested analyze() calls. Used for enforcing a
@@ -181,9 +184,6 @@ public class Analyzer {
     // True if at least one of the analyzers belongs to a subquery.
     public boolean containsSubquery = false;
 
-    // whether to use Hive's auto-generated column labels
-    public boolean useHiveColLabels = false;
-
     // all registered conjuncts (map from expr id to conjunct)
     public final Map<ExprId, Expr> conjuncts = Maps.newHashMap();
 
@@ -368,6 +368,7 @@ public class Analyzer {
     globalState_ = globalState;
     missingTbls_ = parentAnalyzer.missingTbls_;
     user_ = parentAnalyzer.getUser();
+    useHiveColLabels_ = parentAnalyzer.useHiveColLabels_;
     authErrorMsg_ = parentAnalyzer.authErrorMsg_;
     enablePrivChecks_ = parentAnalyzer.enablePrivChecks_;
     isWithClause_ = parentAnalyzer.isWithClause_;
@@ -2419,9 +2420,9 @@ public class Analyzer {
   public void setIsExplain() { globalState_.isExplain = true; }
   public boolean isExplain() { return globalState_.isExplain; }
   public void setUseHiveColLabels(boolean useHiveColLabels) {
-    globalState_.useHiveColLabels = useHiveColLabels;
+    useHiveColLabels_ = useHiveColLabels;
   }
-  public boolean useHiveColLabels() { return globalState_.useHiveColLabels; }
+  public boolean useHiveColLabels() { return useHiveColLabels_; }
 
   public void setHasLimitOffsetClause(boolean hasLimitOffset) {
     this.hasLimitOffsetClause_ = hasLimitOffset;
@@ -2512,7 +2513,7 @@ public class Analyzer {
 
     // Number of slots registered at the time when the value transfer graph was
     // computed.
-    private int numSlots_ = globalState_.descTbl.getMaxSlotId().asInt() + 1;
+    private final int numSlots_ = globalState_.descTbl.getMaxSlotId().asInt() + 1;
 
     public int getNumSlots() { return numSlots_; }
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/ca8ac350/fe/src/test/java/com/cloudera/impala/analysis/AnalyzeStmtsTest.java
----------------------------------------------------------------------
diff --git a/fe/src/test/java/com/cloudera/impala/analysis/AnalyzeStmtsTest.java b/fe/src/test/java/com/cloudera/impala/analysis/AnalyzeStmtsTest.java
index 80120b9..faa1834 100644
--- a/fe/src/test/java/com/cloudera/impala/analysis/AnalyzeStmtsTest.java
+++ b/fe/src/test/java/com/cloudera/impala/analysis/AnalyzeStmtsTest.java
@@ -1063,6 +1063,13 @@ public class AnalyzeStmtsTest extends AnalyzerTest {
         "(select int_col * 10, int_col as back, int_col + 2 from " +
         "functional.alltypestiny) y) x",
         createAnalyzerUsingHiveColLabels());
+    // IMPALA-3537: Test that auto-generated column labels are only applied in
+    // the appropriate child query blocks.
+    SelectStmt colLabelsStmt =
+        (SelectStmt) AnalyzesOk("select avg(int_col) from functional.alltypes_view");
+    assertEquals("avg(int_col)", colLabelsStmt.getColLabels().get(0));
+    AnalyzesOk("select `max(int_col)` from " +
+        "(select max(int_col) from functional.alltypes_view) v");
 
     // ambiguous reference to an auto-generated column
     AnalysisError("select _c0 from " +