You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@impala.apache.org by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org> on 2016/12/28 23:17:18 UTC

[Impala-ASF-CR] IMPALA-1861: Simplify constant conditionals

Thomas Tauber-Marshall has uploaded a new change for review.

  http://gerrit.cloudera.org:8080/5585

Change subject: IMPALA-1861: Simplify constant conditionals
......................................................................

IMPALA-1861: Simplify constant conditionals

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch covers IF, ||, &&, CASE, and DECODE.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
M testdata/workloads/functional-planner/queries/PlannerTest/empty.test
4 files changed, 57 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/85/5585/1
-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 1
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Bharath Vissapragada (Code Review)" <ge...@cloudera.org>.
Bharath Vissapragada has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 10: Code-Review+1

(3 comments)

The patch looks good to me overall. Especially the logic in SimplifyConditionalsRule.simplifyCaseExpr() looks good to me as per ANSI SQL standard.

http://gerrit.cloudera.org:8080/#/c/5585/10/fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
File fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java:

Line 39: import org.apache.impala.rewrite.SimplifyConditionalsRule;
nit: Move below to maintain lexicographical order.


http://gerrit.cloudera.org:8080/#/c/5585/10/fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
File fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java:

Line 38:     if (!expr.isAnalyzed()) return expr;
nit: I think this can be rewritten as below to avoid nesting.

 if (!expr.isAnalyzed() || !(expr instanceof CompoundPredicate)) return expr;
 return normalizeCompoundPredicate((CompoundPredicate) expr);


Line 43: 
nit: Extraneous newline (here and elsewhere in this patch).


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 10
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

Re: [Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by Marcel Kornacker <ma...@cloudera.com>.
+Greg

On Wed, Jan 11, 2017 at 3:22 PM, Tim Armstrong (Code Review)
<ge...@cloudera.org> wrote:
> Tim Armstrong has posted comments on this change.
>
> Change subject: IMPALA-1861: Simplify conditionals with constant conditions
> ......................................................................
>
>
> Patch Set 6:
>
> (1 comment)
>
> http://gerrit.cloudera.org:8080/#/c/5585/6/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
> File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:
>
> Line 175:       if (whenExpr instanceof BoolLiteral) {
>> Thanks Marcel for the explanation. I checked this in another DB engine, whi
> Given the complexity of some of the case/when clauses we see in practice I'm sure some or many users depend on the current evaluation order, particularly since this is the "obvious" behaviour. I think we should be careful doing this since my bet is that changing this will break someone's query that worked before.
>
> If we're going to change this it seems like at a minimum we should add a warning to the documentation about this and call it out clearly that this has changed in the commit message, release notes, etc (my personal preference is that we document the pre-existing behaviour and preserve it by only optimising this when all previous "WHEN" clauses were constant).
>
>
> --
> To view, visit http://gerrit.cloudera.org:8080/5585
> To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
>
> Gerrit-MessageType: comment
> Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
> Gerrit-PatchSet: 6
> Gerrit-Project: Impala-ASF
> Gerrit-Branch: master
> Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
> Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
> Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
> Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
> Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
> Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
> Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Tim Armstrong (Code Review)" <ge...@cloudera.org>.
Tim Armstrong has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 6:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/5585/6/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 175:       if (whenExpr instanceof BoolLiteral) {
> Thanks Marcel for the explanation. I checked this in another DB engine, whi
Given the complexity of some of the case/when clauses we see in practice I'm sure some or many users depend on the current evaluation order, particularly since this is the "obvious" behaviour. I think we should be careful doing this since my bet is that changing this will break someone's query that worked before.

If we're going to change this it seems like at a minimum we should add a warning to the documentation about this and call it out clearly that this has changed in the commit message, release notes, etc (my personal preference is that we document the pre-existing behaviour and preserve it by only optimising this when all previous "WHEN" clauses were constant).


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 6
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Thomas Tauber-Marshall has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 7:

(6 comments)

http://gerrit.cloudera.org:8080/#/c/5585/6/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 73:     if (fnName.getFunction().equals("if")) {
> May be add a Preconditions check on expr.getChildren().size() == 2?
Done


Line 127: 
> Unreachable? If yes add a Preconditions.checkState(false)?
No, it would reach this for "NOT" on a non-constant expression.


Line 155:     // CASE expr while removing any FALSE or NULL cases.
> Can't we merge this with the above loop? Is it written this way for readabi
This was done for performance, since these rules may be executed repeatedly, the above loop is cheaper than this one, and I'm assuming that CASEs that can't be simplified is the common case, though I don't think it makes a huge difference.


Line 157:     Expr elseExpr = null;
> single line
Done


Line 175: 
> Given the complexity of some of the case/when clauses we see in practice I'
Per Greg's comments on the mailing list, we're going to go with the ANSI SQL standard, which is to always return the left most TRUE case.


Line 179:             // This WHEN is always TRUE, and any cases preceding it are constant
> explain the implied 'else' case: that it's always false and therefore can b
Done


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 7
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 12:

Build started: http://jenkins.impala.io:8080/job/gerrit-verify-dryrun/205/

-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 12
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins
Gerrit-Reviewer: Jim Apple <jb...@apache.org>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Thomas Tauber-Marshall has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 5:

(6 comments)

http://gerrit.cloudera.org:8080/#/c/5585/4/fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
File fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java:

Line 50:     if (!(expr.getChild(0) instanceof BoolLiteral)
> why is isLiteral() not enough? (what other literal could it be?)
NullLiteral, so if we just called isLiteral() something like "NULL || TRUE" wouldn't get simplified to "TRUE", since it wouldn't be rewritten by this rule, and then SimplifyConstantConditionals wouldn't simplify it either since it doesn't have a BoolLiteral left child.


http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 65:   /**
> then spell this out in a todo
Done


Line 132:    * 'then' for the first one is returned. Otherwise, if any of the 'when's have constant
> i don't think it'll have any measurable impact on runtime, and the code won
It turned out to be pretty simple, so I went for it.


http://gerrit.cloudera.org:8080/#/c/5585/4/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 91:   /**
> spell out rule dependencies in the class comment (and also in analysisctx w
Done


Line 143:     boolean canSimplify = false;
> 'simplified' -> 'removed' (even more specific)
Done


Line 148:       }
> why don't you do
Done


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 5
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Thomas Tauber-Marshall has uploaded a new patch set (#3).

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................

IMPALA-1861: Simplify conditionals with constant conditions

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch introduces the SimplifyConditionalsRule with covers IF,
OR, AND, CASE, and DECODE.

It also introduces NormalizeExprsRule which normalizes AND and OR
such that if either child is a literal, then the left child is a
literal.

Testing:
- Added unit tests to ExprRewriteRulesTest.
- Ran FE planner tests and BE expr-test.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
A fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
A fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
5 files changed, 312 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/85/5585/3
-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 3
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Marcel Kornacker (Code Review)" <ge...@cloudera.org>.
Marcel Kornacker has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 6:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/5585/6/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 175:       if (whenExpr instanceof BoolLiteral) {
> I have a question around this. Lets say we have something like
our docs don't say anything about the order in which the where clauses are evaluated, or which particular one gets chosen when there are multiple that are true.


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 6
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Hello Marcel Kornacker,

I'd like you to reexamine a change.  Please visit

    http://gerrit.cloudera.org:8080/5585

to look at the new patch set (#9).

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................

IMPALA-1861: Simplify conditionals with constant conditions

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch introduces the SimplifyConditionalsRule with covers IF,
OR, AND, CASE, and DECODE.

It also introduces NormalizeExprsRule which normalizes AND and OR
such that if either child is a BoolLiteral, then the left child is a
BoolLiteral.

Testing:
- Added unit tests to ExprRewriteRulesTest.
- Added functional tests to expr.test
- Ran FE planner tests and BE expr-test.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseExpr.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
A fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
A fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
M testdata/workloads/functional-query/queries/QueryTest/exprs.test
7 files changed, 410 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/85/5585/9
-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 9
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has submitted this change and it was merged.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


IMPALA-1861: Simplify conditionals with constant conditions

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch introduces the SimplifyConditionalsRule with covers IF,
OR, AND, CASE, and DECODE.

It also introduces NormalizeExprsRule which normalizes AND and OR
such that if either child is a BoolLiteral, then the left child is a
BoolLiteral.

Testing:
- Added unit tests to ExprRewriteRulesTest.
- Added functional tests to expr.test
- Ran FE planner tests and BE expr-test.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Reviewed-on: http://gerrit.cloudera.org:8080/5585
Reviewed-by: Jim Apple <jb...@apache.org>
Tested-by: Impala Public Jenkins
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseExpr.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
A fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
A fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
M testdata/workloads/functional-query/queries/QueryTest/exprs.test
7 files changed, 406 insertions(+), 13 deletions(-)

Approvals:
  Impala Public Jenkins: Verified
  Jim Apple: Looks good to me, approved



-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 13
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins
Gerrit-Reviewer: Jim Apple <jb...@apache.org>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Thomas Tauber-Marshall has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 8:

(4 comments)

http://gerrit.cloudera.org:8080/#/c/5585/7/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 154:     // Contains all 'when' clauses with non-constant conditions, used to construct the new
> construct
Done


Line 157:     // Set to THEN of first constant TRUE clause, if any.
> comment: first constant true when clause
Done


Line 188:         } else {
> this can be misread to apply to the following else if
Done


Line 189:           // This WHEN is always FALSE, so it can be removed.
> can whenExpr be a null literal, given l160?
You're right - I was thinking of the hasCaseExpr case where whenExpr comes from the BinaryPredicate we construct and constant fold above, but I don't guess there's any expression of the form "non-null literal = non-null literal" that would constant fold down to NULL.


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 8
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Marcel Kornacker (Code Review)" <ge...@cloudera.org>.
Marcel Kornacker has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 7:

(4 comments)

http://gerrit.cloudera.org:8080/#/c/5585/7/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 154:     // Contains all 'when' clauses with non-constant conditions, used to contruct the new
construct


Line 157:     Expr elseExpr = null;
comment: first constant true when clause


Line 188:         // Otherwise, this WHEN is always FALSE, so it can be removed.
this can be misread to apply to the following else if


Line 189:       } else if (!(whenExpr instanceof NullLiteral)) {
can whenExpr be a null literal, given l160?


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 7
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Thomas Tauber-Marshall has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 11:

(2 comments)

http://gerrit.cloudera.org:8080/#/c/5585/10/fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
File fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java:

Line 38:     if (!expr.isAnalyzed()) return expr;
> nit: I think this can be rewritten as below to avoid nesting.
I don't think that's really an improvement, since this function is obviously going to extended to handle different expr types in the future, in which case it'll have to be changed back to how I have it now anyways.

I added a TOCO noting this.


Line 43:     }
> nit: Extraneous newline (here and elsewhere in this patch).
Done


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 11
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Hello Marcel Kornacker, Bharath Vissapragada,

I'd like you to reexamine a change.  Please visit

    http://gerrit.cloudera.org:8080/5585

to look at the new patch set (#11).

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................

IMPALA-1861: Simplify conditionals with constant conditions

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch introduces the SimplifyConditionalsRule with covers IF,
OR, AND, CASE, and DECODE.

It also introduces NormalizeExprsRule which normalizes AND and OR
such that if either child is a BoolLiteral, then the left child is a
BoolLiteral.

Testing:
- Added unit tests to ExprRewriteRulesTest.
- Added functional tests to expr.test
- Ran FE planner tests and BE expr-test.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseExpr.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
A fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
A fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
M testdata/workloads/functional-query/queries/QueryTest/exprs.test
7 files changed, 405 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/85/5585/11
-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 11
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 11: Code-Review+2

carry

-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 11
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@apache.org>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Thomas Tauber-Marshall has uploaded a new patch set (#5).

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................

IMPALA-1861: Simplify conditionals with constant conditions

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch introduces the SimplifyConditionalsRule with covers IF,
OR, AND, CASE, and DECODE.

It also introduces NormalizeExprsRule which normalizes AND and OR
such that if either child is a BoolLiteral, then the left child is a
BoolLiteral.

Testing:
- Added unit tests to ExprRewriteRulesTest.
- Ran FE planner tests and BE expr-test.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
A fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
A fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
5 files changed, 362 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/85/5585/5
-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 5
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Marcel Kornacker (Code Review)" <ge...@cloudera.org>.
Marcel Kornacker has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 10: Code-Review+2

(1 comment)

http://gerrit.cloudera.org:8080/#/c/5585/10/fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
File fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java:

Line 39: import org.apache.impala.rewrite.SimplifyConditionalsRule;
> nit: Move below to maintain lexicographical order.
just fyi, this is immaterial to functionality and readability and shouldn't be requested in a review.


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 10
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Bharath Vissapragada (Code Review)" <ge...@cloudera.org>.
Bharath Vissapragada has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 6:

(5 comments)

http://gerrit.cloudera.org:8080/#/c/5585/6/fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
File fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java:

Line 82:       rules.add(SimplifyConditionalsRule.INSTANCE);
Given these rules can get complex over time, I think we should track the dependencies as a DAG or something just to make sure we get the order right. Else there is a chance we can get nasty bugs. Its out of scope for this patch but thats my opinion for further changes.


http://gerrit.cloudera.org:8080/#/c/5585/6/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 73:     if (fnName.getFunction().equals("if")) {
May be add a Preconditions check on expr.getChildren().size() == 2?


Line 127:     return expr;
Unreachable? If yes add a Preconditions.checkState(false)?


Line 155:     for (int i = loopStart; i < numChildren - 1; i += 2) {
Can't we merge this with the above loop? Is it written this way for readability?


Line 175:       if (whenExpr instanceof BoolLiteral) {
I have a question around this. Lets say we have something like

CASE
WHEN a=1 return foo
WHEN TRUE return bar
...

Lets say we do have an 'a' which is 1. Aren't we supposed to evaluate those WHENs in the same order? If we apply this rule, we replace the whole thing with bar? Without this patch, we'd return foo. No? (same applies for FALSE)


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 6
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Hello Marcel Kornacker, Impala Public Jenkins, Bharath Vissapragada, Jim Apple,

I'd like you to reexamine a change.  Please visit

    http://gerrit.cloudera.org:8080/5585

to look at the new patch set (#12).

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................

IMPALA-1861: Simplify conditionals with constant conditions

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch introduces the SimplifyConditionalsRule with covers IF,
OR, AND, CASE, and DECODE.

It also introduces NormalizeExprsRule which normalizes AND and OR
such that if either child is a BoolLiteral, then the left child is a
BoolLiteral.

Testing:
- Added unit tests to ExprRewriteRulesTest.
- Added functional tests to expr.test
- Ran FE planner tests and BE expr-test.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseExpr.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
A fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
A fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
M testdata/workloads/functional-query/queries/QueryTest/exprs.test
7 files changed, 406 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/85/5585/12
-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 12
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins
Gerrit-Reviewer: Jim Apple <jb...@apache.org>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Hello Marcel Kornacker,

I'd like you to reexamine a change.  Please visit

    http://gerrit.cloudera.org:8080/5585

to look at the new patch set (#7).

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................

IMPALA-1861: Simplify conditionals with constant conditions

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch introduces the SimplifyConditionalsRule with covers IF,
OR, AND, CASE, and DECODE.

It also introduces NormalizeExprsRule which normalizes AND and OR
such that if either child is a BoolLiteral, then the left child is a
BoolLiteral.

Testing:
- Added unit tests to ExprRewriteRulesTest.
- Ran FE planner tests and BE expr-test.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseExpr.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
A fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
A fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
6 files changed, 381 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/85/5585/7
-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 7
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Marcel Kornacker (Code Review)" <ge...@cloudera.org>.
Marcel Kornacker has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 3:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
File fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java:

Line 262:     RewritesOk("case 3 when 0 then id when 1 then id + 1 end", rule, "NULL");
add 'case null'


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 3
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Thomas Tauber-Marshall has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 4:

(15 comments)

http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
File fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java:

Line 80:       rules.add(ExtractCommonConjunctRule.INSTANCE);
> why not do this normalization right after folding constants?
Done


http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
File fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java:

Line 40:     if (expr instanceof CompoundPredicate) {
> make this the class comment
Done


http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 65:   /**
> are there any other functions that are subject to this? otherwise call this
There will be a number of other functions in the future, eg. 'ifnull', 'isfalse', 'isnotfalse', etc., most of which will be quite short to simplify and giving them each their own 'simplify' function would be cluttered, so I would prefer to leave this and your next comment below as is.


Line 95:    * false OR 'expr' -> 'expr'
> is that standard sql? i thought 'null and <expr>' is always null.
I believe so. This is how impala behaves currently, and also see for example, Postgres's docs:
https://www.postgresql.org/docs/current/static/functions-logical.html


Line 99:    * 'expr' is false if 'expr' is false but null if 'expr' is true.
> if (!(getchild(0) instanceof BoolLiteral)) return expr;
Done


Line 101:    * NOT is covered by FoldConstantRule.
> state this dependency in the class comment, not here
Done


Line 129:    * Simpilfies CASE and DECODE. If any of the 'when's has a constant TRUE value, the
> explanatory comment missing
Done


Line 132:    * returned.
> explanatory comment
It occurs to me - we tried to do lazy creation here to minimize object creation since this rule may be invoked many times, but this list is still going to be created and populated with the created CaseWhenClause objects needlessly any time there is a CASE that can't be simplified and has at least one 'when', which I would guess would be the common case.

Do you think it would be worth having an initial step where we iterate over the children, check if any cases are constant without constructing 'newWhenClauses' and return immediately if no cases are constant, only going through the more complicated logic if we know that we will be able to simplify something?

This would speed up evaluation when we can't simplify anything at the cost of making it slower when we can, eg. because we would need to create and fold some of the BinaryPredicates for  the hasCaseExpr case twice.


Line 133:    */
> briefly explain why this is needed (indicates that case can be simplified)
Done


Line 140:     // Contains all 'when' clauses with non-constant conditions, used to contruct the new
> one more thing: for 'case [<expr>]' you can remove all 'when null' branches
Done


http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
File fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java:

Line 239:   public void TestSimplifyConditionalsRule() throws AnalysisException {
> for each conditional, also add a test case that doesn't allow any rewrites.
Done


Line 254:     RewritesOk("null && id = 0", rule, null);
> isn't this logically 'id = 0'?
No - see https://www.postgresql.org/docs/current/static/functions-logical.html


Line 262:     RewritesOk("case 1 when 0 then id when 1 then id + 1 when 2 then id + 2 end", rules,
> also add statement with multiple matches.
Done


Line 269:     // All FALSE, return implicit NULL ELSE.
> add 'case when true'
Done


Line 290:     RewritesOk("case when false then 0 end", rules, "NULL");
> ?
These cases are already normalized.


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Bharath Vissapragada (Code Review)" <ge...@cloudera.org>.
Bharath Vissapragada has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 6:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/5585/6/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 175:       if (whenExpr instanceof BoolLiteral) {
> our docs don't say anything about the order in which the where clauses are 
Thanks Marcel for the explanation. I checked this in another DB engine, which imposes the order [1]. I'm fine with either approach but just wanted to highlight this just in case any users are relying on this behavior.

"In the order specified, evaluates input_expression = when_expression for each WHEN clause."

[1] https://msdn.microsoft.com/en-gb/library/ms181765.aspx


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 6
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify constant conditionals

Posted by "Alex Behm (Code Review)" <ge...@cloudera.org>.
Alex Behm has posted comments on this change.

Change subject: IMPALA-1861: Simplify constant conditionals
......................................................................


Patch Set 2:

(23 comments)

Nice!

http://gerrit.cloudera.org:8080/#/c/5585/2//COMMIT_MSG
Commit Message:

Line 7: IMPALA-1861: Simplify constant conditionals
Simplify conditionals with constant conditions.


Line 13: 
What testing did you do? In particular, I'm curious if you ran the BE expr-test which will also exercise your new rule


http://gerrit.cloudera.org:8080/#/c/5585/2/fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
File fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java:

Line 31:     this.whenExpr_ = whenExpr;
remove 'this' while here


Line 35:   public Expr getWhenExpr() {
single lines while you are here


http://gerrit.cloudera.org:8080/#/c/5585/2/fe/src/main/java/org/apache/impala/rewrite/ConstantPredicateRule.java
File fe/src/main/java/org/apache/impala/rewrite/ConstantPredicateRule.java:

Line 37:  * This rule simplifies exprs with constant valued predicates. It relies on
This rule simplifies conditional functions with constant conditions.


Line 38:  * FoldConstantsRule to reduce the predicates to BoolLiteral or NullLiteral first.
.. to replace the constants condition with a BoolLiteral or NullLiteral first...


Line 42:  * id = 0 || false -> id = 0
add an example AND

let's use AND and OR instead of && and || to make it very clear  that these are SQL expressions and to be consistent with the ExtractCommonConjunctsRule


Line 45: public class ConstantPredicateRule implements ExprRewriteRule {
SimplifyConditionalsRule?

The name should describe what the rule does, and I'm not sure I understand what action a ConstantPredicateRule performs.


Line 50:     if (expr instanceof FunctionCallExpr) {
As a sanity check, check expr.isAnalyzed() and bail if it not analyzed. See the TODO in FoldConstantsRule.

Here's a query you can try to see what happens when this rule is called on an unanalyzed expression.

select bool_col a from functional.alltypes group by if(a, bigint_col, int_col)

The problematic group-by expr has a select-list alias and that causes issues with our rewrite framework.


Line 51:       FunctionName fnName = ((FunctionCallExpr) expr).getFnName();
let's put these into separate functions, i.e. simplifyFunctionCallExpr(), simplifyCompoundPredicate(), simplifyCaseExpr(), etc.


Line 56:             return expr.getChild(1).castTo(expr.getType());
These casts should not be necessary if the expr is analyzed


Line 61:         } else if (expr.getChild(0) instanceof NullLiteral) {
Might be useful to add helper functions LiteralExpr.isTrue() and LiteralExpr.isFalse(). Inside isFalse() you can check for a false bool literal or a null literal. That way we don't have to check both paths everywhere.


Line 68:       if (pred.getOp() == CompoundPredicate.Operator.AND) {
This would become simpler if we normalized binary predicates to always have constants/literals on one side. Another rule to consider if you are up for it :). Even just simple normalization could help a lot.


Line 71:           if (child instanceof BoolLiteral) {
What if child is a NullLiteral? Also add a test for this if you haven't already.


Line 73:               // TRUE && foo, so return foo.
let's say 'expr' instead of foo


Line 98:       List<CaseWhenClause> newWhenClauses = new ArrayList<CaseWhenClause>();
Avoid creating objects when no rewrite takes place, e.g., you can leave this null and create it lazily on demand.

As we expand our rule set, these rewrite rules may be executed many many times.


Line 105:         if (((CaseExpr) expr).hasCaseExpr()) {
little easier to read if you use a "CaseExpr caseExpr = (CaseExpr) expr" at the beginning


Line 106:           BinaryPredicate pred = new BinaryPredicate(
Avoid object creation if caseExpr or expr.getChild(i) are not literals and this branch can't be simplified, e.g., you can set whenExpr to null which will fail any subsequent instanceof check


Line 133:           if (elseExpr == null) return new NullLiteral();
use NullLiteral.create(expr.getType());


Line 137:         CaseExpr result = new CaseExpr(caseExpr, newWhenClauses, elseExpr);
return new CaseExpr(...)


http://gerrit.cloudera.org:8080/#/c/5585/2/fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
File fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java:

Line 43:     // Create a rewriter with only a single rule.
remove comment and simplify code below to:

return RewritesOk(expr, Lists.newArrayList(rule), expectedStr);


Line 253:     RewritesOk("true && id = 0", rule, "id = 0");
add tests with NULL


Line 260:     RewritesOk("case 2 when 0 then id when 1 then id * 2 else 0 end", rule, "0");
also test the implicit ELSE NULL when hasCaseExpr()


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 2
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Marcel Kornacker (Code Review)" <ge...@cloudera.org>.
Marcel Kornacker has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 3:

(5 comments)

http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 133:     boolean foundFalseExpr = false;
briefly explain why this is needed (indicates that case can be simplified)


Line 140:         if (caseExpr.isLiteral() && expr.getChild(i).isLiteral()) {
> it looks like expr.hasCaseExpr() && !caseExpr.isLiteral() means you'll neve
one more thing: for 'case [<expr>]' you can remove all 'when null' branches. this applies even to non-literal case exprs (which won't trigger l159).


Line 144:           whenExpr = analyzer.getConstantFolder().rewrite(pred, analyzer);
> this is a roundabout way to get a boolean value. use FeSupport.evalPredicat
never mind, you need this for the non-const case.


http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
File fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java:

Line 239:   public void TestSimplifyConditionalsRule() throws AnalysisException {
for each conditional, also add a test case that doesn't allow any rewrites.


Line 262:     RewritesOk("case 3 when 0 then id when 1 then id + 1 end", rule, "NULL");
> add 'case null'
also add statement with multiple matches.


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 3
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 11: Verified-1

Build failed: http://jenkins.impala.io:8080/job/gerrit-verify-dryrun/203/

-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 11
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins
Gerrit-Reviewer: Jim Apple <jb...@apache.org>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Thomas Tauber-Marshall has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 3:

(21 comments)

http://gerrit.cloudera.org:8080/#/c/5585/2//COMMIT_MSG
Commit Message:

Line 7: IMPALA-1861: Simplify conditionals with constant conditions
> Simplify conditionals with constant conditions.
Done


http://gerrit.cloudera.org:8080/#/c/5585/2/fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
File fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java:

Line 31:     whenExpr_ = whenExpr;
> remove 'this' while here
Done


Line 35:   public Expr getWhenExpr() { return whenExpr_; }
> single lines while you are here
Done


http://gerrit.cloudera.org:8080/#/c/5585/2/fe/src/main/java/org/apache/impala/rewrite/ConstantPredicateRule.java
File fe/src/main/java/org/apache/impala/rewrite/ConstantPredicateRule.java:

Line 37
> This rule simplifies conditional functions with constant conditions.
Done


Line 38
> .. to replace the constants condition with a BoolLiteral or NullLiteral fir
Done


Line 42
> add an example AND
Done


Line 45
> SimplifyConditionalsRule?
Done


Line 50
> As a sanity check, check expr.isAnalyzed() and bail if it not analyzed. See
I did this, but it causes problems with repeated application of rules, since a newly created expr resulting from a rewrite won't get reanalyzed until after rewriting is finished.

For example, the addition of NormalizeExprsRule reverted a change to the empty.test PlannerTest.


Line 51
> let's put these into separate functions, i.e. simplifyFunctionCallExpr(), s
Done


Line 56
> These casts should not be necessary if the expr is analyzed
Done


Line 61
> Might be useful to add helper functions LiteralExpr.isTrue() and LiteralExp
I think this would be misleading, since NULL is not always equal to FALSE, eg NULL && true != false && true.


Line 71
> What if child is a NullLiteral? Also add a test for this if you haven't alr
For CompoundPredicates, we can't simplify NullLiterals unless the other child is a BoolLiteral in which case these cases will cover it.

I added a comment explaining this.


Line 73
> let's say 'expr' instead of foo
Done


Line 98
> Avoid creating objects when no rewrite takes place, e.g., you can leave thi
Done


Line 105
> little easier to read if you use a "CaseExpr caseExpr = (CaseExpr) expr" at
Done


Line 106
> Avoid object creation if caseExpr or expr.getChild(i) are not literals and 
Done


Line 133
> use NullLiteral.create(expr.getType());
Done


Line 137
> return new CaseExpr(...)
Done


http://gerrit.cloudera.org:8080/#/c/5585/2/fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
File fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java:

Line 43:       throws AnalysisException {
> remove comment and simplify code below to:
Done


Line 253:     RewritesOk("null && id = 0", rule, null);
> add tests with NULL
Done


Line 260:         "CASE 0 WHEN id THEN id + 1 END");
> also test the implicit ELSE NULL when hasCaseExpr()
Done


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 3
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Marcel Kornacker (Code Review)" <ge...@cloudera.org>.
Marcel Kornacker has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 4:

(6 comments)

http://gerrit.cloudera.org:8080/#/c/5585/4/fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
File fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java:

Line 50:     if (!(expr.getChild(0) instanceof BoolLiteral)
why is isLiteral() not enough? (what other literal could it be?)


http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 65:   /**
> There will be a number of other functions in the future, eg. 'ifnull', 'isf
then spell this out in a todo


Line 132:    * returned.
> It occurs to me - we tried to do lazy creation here to minimize object crea
i don't think it'll have any measurable impact on runtime, and the code won't get much simpler (plus you need some additional code for the check), so maybe not. but try it out if you want and see what comes out.


http://gerrit.cloudera.org:8080/#/c/5585/4/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 91:    * NormalizeExprsRule ensures will be the left child,  according to the following rules:
spell out rule dependencies in the class comment (and also in analysisctx where you put the rules together in a particular order, otherwise it's easy to break inadvertently)


Line 143:     // True if this CASE has a FALSE or NULL condition that can be simplified.
'simplified' -> 'removed' (even more specific)


Line 148:       Expr child = expr.getChild(i);
why don't you do

if (child instanceof nullliteral) {
  foundFalseExpr = true;
  continue;
}

here and then you don't have to deal with it anymore, such as in l175


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Hello Marcel Kornacker,

I'd like you to reexamine a change.  Please visit

    http://gerrit.cloudera.org:8080/5585

to look at the new patch set (#8).

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................

IMPALA-1861: Simplify conditionals with constant conditions

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch introduces the SimplifyConditionalsRule with covers IF,
OR, AND, CASE, and DECODE.

It also introduces NormalizeExprsRule which normalizes AND and OR
such that if either child is a BoolLiteral, then the left child is a
BoolLiteral.

Testing:
- Added unit tests to ExprRewriteRulesTest.
- Ran FE planner tests and BE expr-test.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseExpr.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
A fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
A fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
6 files changed, 383 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/85/5585/8
-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 8
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Marcel Kornacker (Code Review)" <ge...@cloudera.org>.
Marcel Kornacker has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 3:

(14 comments)

http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
File fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java:

Line 80:       rules.add(NormalizeExprsRule.INSTANCE);
why not do this normalization right after folding constants?


http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
File fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java:

Line 40:    * Normalizes CompoundPredicates by ensuring that if either child of AND or OR is a
make this the class comment


http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 65:   private Expr simplifyFunctionCallExpr(FunctionCallExpr expr) {
are there any other functions that are subject to this? otherwise call this simplifyIf() or something like that?


Line 67:     if (fnName.getFunction().equals("if")) {
if (!..equals("if")) return expr;

to avoid one level of indentation


Line 95:    * 'expr' is false if 'expr' is false but null if 'expr' is true.
is that standard sql? i thought 'null and <expr>' is always null.


Line 99:   private Expr simplifyCompoundPredicate(CompoundPredicate expr) {
if (!(getchild(0) instanceof BoolLiteral)) return expr;

and then simplify the rest


Line 101:       // NormalizeExprsRule ensures that if either child is a literal, the first child
state this dependency in the class comment, not here


Line 129:   private Expr simplifyCaseExpr(CaseExpr expr, Analyzer analyzer)
explanatory comment missing


Line 132:     List<CaseWhenClause> newWhenClauses = null;
explanatory comment


Line 140:         if (caseExpr.isLiteral() && expr.getChild(i).isLiteral()) {
it looks like expr.hasCaseExpr() && !caseExpr.isLiteral() means you'll never do anything. check that at the beginning and then exit.


Line 144:           whenExpr = analyzer.getConstantFolder().rewrite(pred, analyzer);
this is a roundabout way to get a boolean value. use FeSupport.evalPredicate() instead and return immediately when appropriate.


http://gerrit.cloudera.org:8080/#/c/5585/3/fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
File fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java:

Line 254:     RewritesOk("null || id = 0", rule, null);
isn't this logically 'id = 0'?


Line 269:     RewritesOk("case when false then 0 end", rule, "NULL");
add 'case when true'

add 'case' with multiple logical 'when true' (such as 'when 1= 1', 'when 2 * 2 = 3 + 1', etc.)


Line 290:     RewritesOk("true and id = 0", rule, null);
?


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 3
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Bharath Vissapragada (Code Review)" <ge...@cloudera.org>.
Bharath Vissapragada has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 10:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/5585/10/fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
File fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java:

Line 39: import org.apache.impala.rewrite.SimplifyConditionalsRule;
> just fyi, this is immaterial to functionality and readability and shouldn't
Thanks Marcel. Understood.


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 10
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 12: Verified+1

-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 12
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins
Gerrit-Reviewer: Jim Apple <jb...@apache.org>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Thomas Tauber-Marshall has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 9:

Added functional tests.

-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 9
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Thomas Tauber-Marshall has uploaded a new patch set (#4).

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................

IMPALA-1861: Simplify conditionals with constant conditions

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch introduces the SimplifyConditionalsRule with covers IF,
OR, AND, CASE, and DECODE.

It also introduces NormalizeExprsRule which normalizes AND and OR
such that if either child is a BoolLiteral, then the left child is a
BoolLiteral.

Testing:
- Added unit tests to ExprRewriteRulesTest.
- Ran FE planner tests and BE expr-test.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
A fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
A fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
5 files changed, 367 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/85/5585/4
-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 12: Code-Review+2

carry

-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 12
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins
Gerrit-Reviewer: Jim Apple <jb...@apache.org>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Marcel Kornacker (Code Review)" <ge...@cloudera.org>.
Marcel Kornacker has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 6: Code-Review+2

(2 comments)

http://gerrit.cloudera.org:8080/#/c/5585/6/fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
File fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java:

Line 157:       if (child instanceof NullLiteral) {
single line


Line 179:         }
explain the implied 'else' case: that it's always false and therefore can be dropped


-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 6
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Hello Marcel Kornacker,

I'd like you to reexamine a change.  Please visit

    http://gerrit.cloudera.org:8080/5585

to look at the new patch set (#10).

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................

IMPALA-1861: Simplify conditionals with constant conditions

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch introduces the SimplifyConditionalsRule with covers IF,
OR, AND, CASE, and DECODE.

It also introduces NormalizeExprsRule which normalizes AND and OR
such that if either child is a BoolLiteral, then the left child is a
BoolLiteral.

Testing:
- Added unit tests to ExprRewriteRulesTest.
- Added functional tests to expr.test
- Ran FE planner tests and BE expr-test.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseExpr.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
A fe/src/main/java/org/apache/impala/rewrite/NormalizeExprsRule.java
A fe/src/main/java/org/apache/impala/rewrite/SimplifyConditionalsRule.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
M testdata/workloads/functional-query/queries/QueryTest/exprs.test
7 files changed, 409 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/85/5585/10
-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 10
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify constant conditionals

Posted by "Thomas Tauber-Marshall (Code Review)" <ge...@cloudera.org>.
Thomas Tauber-Marshall has uploaded a new patch set (#2).

Change subject: IMPALA-1861: Simplify constant conditionals
......................................................................

IMPALA-1861: Simplify constant conditionals

When there are conditionals with constant values of TRUE or
FALSE we can simplify them during analysis using the ExprRewriter.

This patch covers IF, ||, &&, CASE, and DECODE.

Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
---
M fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
M fe/src/main/java/org/apache/impala/analysis/CaseWhenClause.java
A fe/src/main/java/org/apache/impala/rewrite/ConstantPredicateRule.java
M fe/src/test/java/org/apache/impala/analysis/ExprRewriteRulesTest.java
M testdata/workloads/functional-planner/queries/PlannerTest/empty.test
5 files changed, 204 insertions(+), 12 deletions(-)


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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 2
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>

[Impala-ASF-CR] IMPALA-1861: Simplify conditionals with constant conditions

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change.

Change subject: IMPALA-1861: Simplify conditionals with constant conditions
......................................................................


Patch Set 11:

Build started: http://jenkins.impala.io:8080/job/gerrit-verify-dryrun/203/

-- 
To view, visit http://gerrit.cloudera.org:8080/5585
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Id70aaf9fd99f64bd98175b7e2dbba28f350e7d3b
Gerrit-PatchSet: 11
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Bharath Vissapragada <bh...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins
Gerrit-Reviewer: Jim Apple <jb...@apache.org>
Gerrit-Reviewer: Marcel Kornacker <ma...@cloudera.com>
Gerrit-Reviewer: Thomas Tauber-Marshall <tm...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No