[ https://issues.apache.org/jira/browse/IMPALA-11462?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17626391#comment-17626391 ]
ASF subversion and git services commented on IMPALA-11462: ---------------------------------------------------------- Commit b71bdce5ebf8667ae0129ec5fb1d350492d09a46 in impala's branch refs/heads/dependabot/maven/fe/org.eclipse.jetty-jetty-server-9.4.41.v20210516 from Daniel Becker [ https://gitbox.apache.org/repos/asf?p=impala.git;h=b71bdce5e ] IMPALA-11462: Constant folding causes cast on int literals to be lost The following query returns -128 instead of 128 and the return type is TINYINT instead of BIGINT: select shiftleft(cast(1 as bigint), z) c from (select 7 z ) x; However, if we disable expression rewrites, the result is correct. The expression rewrite rule 'FoldConstantsRule' folds the the cast to bigint into the literal during expression rewrite. This modifies the expression, so re-analysis is needed. Re-analysis resets the literal expression (a NumericLiteral), which loses its type and becomes TINYINT again. 'NumericLiteral's have three kinds of type: - natural type: the smallest type that can hold its value - explicit type: starts as the natural type and can be widened by explicit casts - implicit type: the result of casts the analyzer uses to adjust input types for functions and arithmetic operations See NumericLiteral.java for more. The problem is that when 'FoldConstantsRule' folds the cast into the literal, it doesn't set its explicit type (only its implicit type becomes BIGINT). When the expression is reset during re-analysis, the type is reverted to the incorrect explicit type. (In the case where expression rewrites are disabled, no re-analysis takes place so the literal and its type are not reset.) This patch fixes the error by setting the explicit type of 'NumericLiteral' when folding an explicit cast into it. Testing: - Added test tests/query_test/test_queries.py::TestConstantFoldingNoTypeLoss::test_shiftleft that tests 'shiftleft' with all integer types. Change-Id: Ie7f27b204792ef7c59dec5ead363d44ed0c3bc79 Reviewed-on: http://gerrit.cloudera.org:8080/19124 Reviewed-by: Impala Public Jenkins <impala-public-jenk...@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenk...@cloudera.com> > shiftleft problem > ----------------- > > Key: IMPALA-11462 > URL: https://issues.apache.org/jira/browse/IMPALA-11462 > Project: IMPALA > Issue Type: Bug > Components: Clients > Affects Versions: Impala 3.4.1 > Reporter: jack sun > Assignee: Daniel Becker > Priority: Minor > Fix For: Impala 4.2.0 > > Attachments: screenshot-1.png > > > if change the second param of function 'shiftleft' as a dynamic value , it > will change the first param as tinnyint > !screenshot-1.png! -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-all-unsubscr...@impala.apache.org For additional commands, e-mail: issues-all-h...@impala.apache.org