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 2019/03/01 17:54:00 UTC

[jira] [Resolved] (IMPALA-7892) Explicit cast state lost for numeric literals on rewrite

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

Paul Rogers resolved IMPALA-7892.
---------------------------------
    Resolution: Fixed

> Explicit cast state lost for numeric literals on rewrite
> --------------------------------------------------------
>
>                 Key: IMPALA-7892
>                 URL: https://issues.apache.org/jira/browse/IMPALA-7892
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Frontend
>    Affects Versions: Impala 3.0
>            Reporter: Paul Rogers
>            Assignee: Paul Rogers
>            Priority: Minor
>
> Consider the following SQL:
> {code:sql}
> SELECT CAST(1 AS INT) as C FROM alltypestiny
> {code}
> The expression contains an explicit cast that cannot be optimized away during rewrites. The cast tells us that the user wants the value 1 as an {{INT}}, not as its “natural” type as {{TINYINT}}.
> The NumericLiteral type has an “explicit cast” flag that is set sometimes. However, the expression rewriter does not set it:
> {code:java}
>       String query = "SELECT CAST(1 AS INT) AS c" +
>           " from functional.alltypestiny";
>       AnalysisContext ctx = createAnalysisCtx();
>       ctx.getQueryOptions().setEnable_expr_rewrites(true);
>       SelectStmt select = (SelectStmt) AnalyzesOk(query, ctx);
>       Expr expr = select.getSelectList().getItems().get(0).getExpr();
>       assertEquals(ScalarType.INT, expr.getType());
>       assertTrue(expr instanceof NumericLiteral);
>       assertTrue(((NumericLiteral) expr).isExplicitCast());
> {code}
> The last test fails because the NumericLiteral is not marked as explicitly cast.
> If the analyzer were to "reset" analysis for the node, we would lose the fact that the user wanted an {{INT}}, and the type would revert to {{TINYINT}}, causing instability, a small change in the analyzer can produce a different query result.



--
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