Skip to content

Commit

Permalink
IMPALA-3537: Move useHiveColLabels out of GlobalState and into Analyzer.
Browse files Browse the repository at this point in the history
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 <alex.behm@cloudera.com>
Tested-by: Internal Jenkins
  • Loading branch information
Alex Behm authored and Internal Jenkins committed May 21, 2016
1 parent de02c6c commit a8ead31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
15 changes: 8 additions & 7 deletions fe/src/main/java/com/cloudera/impala/analysis/Analyzer.java
Expand Up @@ -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
Expand Down Expand Up @@ -181,9 +184,6 @@ private static class GlobalState {
// 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();

Expand Down Expand Up @@ -368,6 +368,7 @@ private Analyzer(Analyzer parentAnalyzer, GlobalState globalState) {
globalState_ = globalState;
missingTbls_ = parentAnalyzer.missingTbls_;
user_ = parentAnalyzer.getUser();
useHiveColLabels_ = parentAnalyzer.useHiveColLabels_;
authErrorMsg_ = parentAnalyzer.authErrorMsg_;
enablePrivChecks_ = parentAnalyzer.enablePrivChecks_;
isWithClause_ = parentAnalyzer.isWithClause_;
Expand Down Expand Up @@ -2419,9 +2420,9 @@ public void setEnablePrivChecks(boolean value) {
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;
Expand Down Expand Up @@ -2512,7 +2513,7 @@ private class ValueTransferGraph {

// 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_; }

Expand Down
Expand Up @@ -1063,6 +1063,13 @@ public void TestInlineView() throws AnalysisException {
"(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 " +
Expand Down

0 comments on commit a8ead31

Please sign in to comment.