Paul Rogers has uploaded this change for review. ( 
http://gerrit.cloudera.org:8080/11952


Change subject: IMPALA-7865: Repeated type widening of arithmetic expressions
......................................................................

IMPALA-7865: Repeated type widening of arithmetic expressions

In its present form, the analyser will analyze some expressions multiple
times: during analysis, after substututing references, again after
performing rewrites.

The analyzer implements a set of type propagation rules that generates a
resulting type for arithmetic expressions that is wider than the types
of the arguments. For example for a + 1, a and 1 are TINYINT, but the
result of the expression is promoted to SMALLINT.  The planner then sets
the type of the constant (1 here) to SMALLINT.

Now, repeat the process on the next cycle. a is TINYINT, 1 is a
SMALLINT. Now the result of the expression is INT and 1 is retyped to be
an INT. Repeat again and the expression (and constant) are promoted to
BIGINT.

Meanwhile, analysis has taken a clone of the expression with the old
types. As a result, the types of columns in the result list for a SELECT
statement can differ from the same columns recorded in the SELECT list.

This patch applies a number of partial fixes:

* When analyzing a numeric expression, the type of any constant argument
  is reset back to the default. (TINYINT in the example above.)
* When performing substitution, expressions are re-analyzed only if that
  expression itself changed, or one of its children changed.

A full fix is to enhance the analyzer to do a bottom-up, one pass
analysis, which is beyond the scope of this change.

Tests:

* Reran all FE tests, adjusting one Planner test.
* Added a new test case that demonstrates that types are widened only
  statically (for a + 1 + 1, say), but not dynamically (due to repeated
  re-analysis.)

Change-Id: I3a8f6d1c508a289083b5e026f33581bc44117ca2
---
M fe/src/main/java/org/apache/impala/analysis/ArithmeticExpr.java
M fe/src/main/java/org/apache/impala/analysis/Expr.java
M fe/src/main/java/org/apache/impala/analysis/NumericLiteral.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriterTest.java
M 
testdata/workloads/functional-planner/queries/PlannerTest/predicate-propagation.test
6 files changed, 112 insertions(+), 32 deletions(-)



  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/52/11952/2
--
To view, visit http://gerrit.cloudera.org:8080/11952
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3a8f6d1c508a289083b5e026f33581bc44117ca2
Gerrit-Change-Number: 11952
Gerrit-PatchSet: 2
Gerrit-Owner: Paul Rogers <[email protected]>

Reply via email to