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 "Quanlong Huang (Jira)" <ji...@apache.org> on 2023/04/02 01:33:00 UTC

[jira] [Updated] (IMPALA-7951) Rewrites change meaning when converted to SQL

     [ https://issues.apache.org/jira/browse/IMPALA-7951?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Quanlong Huang updated IMPALA-7951:
-----------------------------------
    Labels: ramp-up  (was: )

> Rewrites change meaning when converted to SQL
> ---------------------------------------------
>
>                 Key: IMPALA-7951
>                 URL: https://issues.apache.org/jira/browse/IMPALA-7951
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Frontend
>    Affects Versions: Impala 3.1.0
>            Reporter: Paul Rogers
>            Priority: Minor
>              Labels: ramp-up
>
> Consider this query:
> {code:sql}
> SELECT int_col not between 1 and 10 and int_col <> -1
> FROM functional.alltypestiny
> {code}
> Then, render the query using toSql() after rewrites
> {code:sql}
> SELECT int_col < 1 OR int_col > 10 AND int_col != -1
> FROM functional.alltypestiny
> Notice the meaning has changed. Correct grouping:
> {code:sql}
> (int_col < 1 OR int_col > 10) AND int_col != -1
> {code}
> This means to accept all values {{(-infinity, -2), 0 (1, 10)}}.
> Actual grouping based on precedence rules:
> {code:sql}
> int_col < 1 OR (int_col > 10 AND int_col != -1)
> {code}
> This means to accept all values {{(-infinity, 0)}}.
> The rewrites must insert parens if the rewrite would render a tree that is incorrect when interpreted using default precedence rules. (That is, if a parent node has lower precedence than a child node.)
> The quick fix is to set the “print sql in parens” flag, but this is less than idea as it adds parens where they are not required. Better would be to compute the parens based on precedence at toSql time, but that is out of scope of this fix.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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