Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
Impala 3.1.0
-
None
-
None
-
ghx-label-3
Description
The FE implements "constant folding" the conversion of constant expressions into constant literals. For example, 1 + 1 is constant-folded to 2.
Subtle cases occur when the BE cannot evaluate the expression. For example:
- DECIMAL-value overflow or underflow e.g. CAST(10 AS DECIMAL(1,0))
- Illegal casts e.g. CAST('foo' AS TIMESTAMP)
- Result strings that contain non-ASCII characters e.g. hex('D3')
In this case, the FE does not fail the query, it just leaves the original SQL and let's the BE fail the query at runtime. (Doing so seems more of a bug than a feature, but let's set that issue aside at present.)
There are cases in which the error is benign. Consider this case from ExprRewriteRulesTest.TestFoldConstantsRule():
Note that a side rule is that the result of constant folding should be the result of the BE executing the entire expression. From ExprRewriteRulesTest.TestFoldConstantsRule():
// Tests correct handling of strings with chars > 127. Should not be folded. verifyRewrite("hex(unhex(hex(unhex('D3'))))", null);
This test says that the following SQL expression cannot be evaluated on the BE:
hex(unhex(hex(unhex('D3'))))
But, the BE can happily evaluate the whole thing, and produce a result of 'D3'. What fails is:
unhex('D3')
But not:
hex(unhex('D3'))
Similar reasoning applies to:
FALSE AND CAST(20 AS DECIMAL(1,0))
In the present code, the entire test expression fails. But, under the, "let the BE decide" rule, the expression:
hex(unhex(hex(unhex('D3'))))
Can be rewritten to:
hex('D3')
The inner three functions are evaluated properly on the BE. Only the outer function fails and is preserved in the AST.