mirror of
https://github.com/apache/impala.git
synced 2026-01-07 00:02:28 -05:00
Adds a new ExprRewriteRule for replacing constant expressions with their literal equivalent via BE evaluation. Applies the new rule together with the existing ones on the parse tree, after analysis. Limitations - Constant folding is applied on the unresolved expressions. As a result, it only works for expressions that are constant within a single query block, as opposed to expressions that may become constant after fully substituting inline-view exprs. - Exprs are not normalized, so some opportunities for constant folding are missed for certain expr-tree shapes. This patch includes the following interesting changes: - Introduces a timestamp literal that can only be produced by constant folding (not expressible directly via SQL). - To make sure that rewrites have no user-visible effect, the original result types and column labels of the top-level statement are restored after the rewrites are performed. - Does not fold exprs if their evaluation resulted in a warning or error, or if the resulting value is not representable by corresponding FE LiteralExpr. - Fixes an existing issue with converting strings between the FE/BE. String produced in the BE that have characters with a value > 127 are not correctly deserialized into a Java String via thrift. We detect this case during constant folding and abandon folding of such exprs. - Fixes several issues with detecting/reporting errors in NativeEvalConstExprs(). - Cleans up ExprContext::GetValue() into ExprContext::GetConstantValue() which clarifies its only use of evaluating exprs from the FE. Testing: - Modifies expr-test.cc to run all tests through the constant folding path. - Adds basic planner and rewrite rule tests. - Exhaustive test run passed Change-Id: If672b703db1ba0bfc26e5b9130161798b40a69e9 Reviewed-on: http://gerrit.cloudera.org:8080/5109 Reviewed-by: Alex Behm <alex.behm@cloudera.com> Tested-by: Internal Jenkins
61 lines
916 B
Plaintext
61 lines
916 B
Plaintext
values(1+1, 2, 5.0, 'a')
|
|
---- PLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
00:UNION
|
|
constant-operands=1
|
|
---- DISTRIBUTEDPLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
00:UNION
|
|
constant-operands=1
|
|
====
|
|
values(1+1, 2, 5.0, 'a') order by 1 limit 10
|
|
---- PLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
01:TOP-N [LIMIT=10]
|
|
| order by: 2 ASC
|
|
|
|
|
00:UNION
|
|
constant-operands=1
|
|
---- DISTRIBUTEDPLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
01:TOP-N [LIMIT=10]
|
|
| order by: 2 ASC
|
|
|
|
|
00:UNION
|
|
constant-operands=1
|
|
====
|
|
values((1+1, 2, 5.0, 'a'), (2, 3, 6.0, 'b'), (3, 4, 7.0, 'c'))
|
|
---- PLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
00:UNION
|
|
constant-operands=3
|
|
---- DISTRIBUTEDPLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
00:UNION
|
|
constant-operands=3
|
|
====
|
|
values((1+1, 2, 5.0, 'a'), (2, 3, 6.0, 'b'), (3, 4, 7.0, 'c')) order by 1 limit 10
|
|
---- PLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
01:TOP-N [LIMIT=10]
|
|
| order by: 2 ASC
|
|
|
|
|
00:UNION
|
|
constant-operands=3
|
|
---- DISTRIBUTEDPLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
01:TOP-N [LIMIT=10]
|
|
| order by: 2 ASC
|
|
|
|
|
00:UNION
|
|
constant-operands=3
|
|
====
|