Paul Rogers created IMPALA-7781:
-----------------------------------

             Summary: Clean up ad-hoc instance of, casts to use predicates in 
expr rewriter
                 Key: IMPALA-7781
                 URL: https://issues.apache.org/jira/browse/IMPALA-7781
             Project: IMPALA
          Issue Type: Bug
          Components: Frontend
    Affects Versions: Impala 3.0
            Reporter: Paul Rogers


The expression rewriter rules have evolved over time, it seems. When originally 
written, it seem that the standard way to check if an expression is a null 
literal is to do an {{instance of}} as in {{SimplifyConditionalsRule}}:

{code:java}
  private Expr simplifyCaseExpr(CaseExpr expr, Analyzer analyzer)
      throws AnalysisException {
    ...
      if (child instanceof NullLiteral) continue;
{code}

Since this was written, we added {{Expr.isNullLiteral()}} which not only checks 
if the expression is null, it also tests for the {{CAST(NULL AS <type>)}} form 
created by the constant folding rule.

The result is that rewrites miss optimization cases for expressions such as 
{{NULL + 1}} which are rewritten to {{CASE(NULL AS INT)}}. (IMPALA-7769).

Code also does manual casts to Boolean literals in the same function:

{code:java}
      if (whenExpr instanceof BoolLiteral) {
        if (((BoolLiteral) whenExpr).getValue()) {
{code}

Which can be replaced with the {{Expr.IS_TRUE_LITERAL}} predicate. Same is true 
for the {{FALSE}} check.

Finally, there are places in the rewriter that check {{isLiteral()}} when it 
wants to know a more generic "is near literal". Consider the {{CAST(NULL...)}} 
issue above. The {{CAST}} is not a literal, but it acts like one in some cases 
(such as in the constant folding rule itself, IMPALA-7769.)

In short, a number of minor, obscure errors could be avoided if we made 
consistent use of the higher-level predicates already available.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to