You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues-all@impala.apache.org by "Paul Rogers (JIRA)" <ji...@apache.org> on 2018/11/13 18:55:00 UTC

[jira] [Created] (IMPALA-7844) Analysis code incorrectly attempts to support ordinals in HAVING clause

Paul Rogers created IMPALA-7844:
-----------------------------------

             Summary: Analysis code incorrectly attempts to support ordinals in HAVING clause
                 Key: IMPALA-7844
                 URL: https://issues.apache.org/jira/browse/IMPALA-7844
             Project: IMPALA
          Issue Type: Bug
          Components: Frontend
    Affects Versions: Impala 3.0
            Reporter: Paul Rogers
            Assignee: Paul Rogers


SQL defines the idea of ordinals, which is, apparently, an old way to specify columns in the {{ORDER BY}} and {{GROUP BY}} clauses:

{code:sql}
SELECT int_col, id
FROM functional.alltypestiny
GROUP BY 1
ORDER BY 2
{code}

The use of an ordinal is semi-ambiguous (is it an ordinal or a literal), but DBs (including Impala) usually interpret a single integer as an ordinal, but interpret any expression as a constant. (For example, {{1}} is an ordinal, but {{2 - 1}} is the constant value 1.)

The use of ordinals works because {{ORDER BY}} and {{GROUP BY}} are lists: it is clear when an integer stands alone as an ordinal.

The {{HAVING}} (and {{WHERE}}) clauses are expressions. For this reason, DB's do not support ordinals in these clauses. For example, what is the meaning below:

{code:sql}
SELECT int_col, id
FROM functional.alltypestiny
WHERE 1 = 2
{code}

Does this mean that the first column equals 2? That the second column equals 1? The first and second columns are equal? That the constant 1 equals the constant 2?

To avoid such ambiguity, neither the SQL standard nor any implementations support ordinals in the {{HAVING}} (or {{WHERE}}) clauses.

Yet, [Impala attempts to do so|https://github.com/apache/impala/blob/master/fe/src/main/java/org/apache/impala/analysis/SelectStmt.java#L549]:

{code:java}
        havingPred_ = substituteOrdinalOrAlias(havingClause_, "HAVING", analyzer_);
{code}

This ticket proposes to remove this code to make it clear that the {{HAVING}} clause cannot contain an ordinal.

References:

* [Redshift HAVING clause|https://docs.aws.amazon.com/redshift/latest/dg/r_HAVING_clause.html]
* [Impala docs|https://impala.apache.org/docs/build3x/html/topics/impala_having.html] are silent on this question.
* [SQL Standard BNF for HAVING|https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#_7_10_having_clause]



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

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-all-unsubscribe@impala.apache.org
For additional commands, e-mail: issues-all-help@impala.apache.org