fix: [bug] PPL query with mvindex() fails when plugins.calcite.pushdown.enabled=true (#5660) - #5689
Conversation
PR Reviewer Guide 🔍(Review updated until commit 83b60f2)Here are some key observations to aid the review process:
|
065908a to
ee33606
Compare
|
Persistent review updated to latest commit ee33606 |
PR Code Suggestions ✨Latest suggestions up to 83b60f2 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit a114262
Suggestions up to commit 3cca658
Suggestions up to commit ee33606
|
dai-chen
left a comment
There was a problem hiding this comment.
Any unit or integration test to cover?
| Pair<SqlOperator, List<RexNode>> normalized = RexNormalize.normalize(call.op, call.operands); | ||
| List<RexNode> standardizedOperands = visitList(normalized.right, helper, update); | ||
| return helper.rexBuilder.makeCall(call.getType(), normalized.left, standardizedOperands); | ||
| RexNode result = |
There was a problem hiding this comment.
+1 to Chen's comment - lets add more testing coverage on the change
ee33606 to
3cca658
Compare
|
Persistent review updated to latest commit 3cca658 |
3cca658 to
a114262
Compare
|
Persistent review updated to latest commit a114262 |
| RexNode result = | ||
| helper.rexBuilder.makeCall(call.getType(), normalized.left, standardizedOperands); | ||
|
|
||
| if (allowNumericTypeWiden |
There was a problem hiding this comment.
- The changes in this
visitCallmay have broader impact. Just wonder is it possible to narrow down and only apply the fix for mvindex (ITEM)? Or we confirm this bug happens for any function? - Also please add test in
CalciteArrayFunctionITto verify.
There was a problem hiding this comment.
To narrow down the fix for just mvindex or (ITEM) would not work, it has been tried in #5670 where the fix is done in the plan-layer where it the CAST added in the MVIndexFunctionImp does nothing during serialzation. This fix only wraps in CAST when the call is BINARY_ARITHMETIC, exact-numeric, and narrower than BIGINT. Comparisons (return BOOLEAN) and already-BIGINT arithmetic are unaffected. Added integration tests in CalciteArrayFunctionIT to verify.
a114262 to
60b50e1
Compare
…hdown.enabled=true` (opensearch-project#5660) * Add Tests * Add tests in CalciteArrayFunctionIT Signed-off-by: Ajimelec Gonzalez <ajimelec@amazon.com>
|
Persistent review updated to latest commit 60b50e1 |
60b50e1 to
83b60f2
Compare
|
Persistent review updated to latest commit 83b60f2 |
Description
Fix Calcite pushdown
CompileExceptionwhere arithmetic in array index expressions (e.g.,mvindex(entity, 1)) produceslonginstead ofintat runtime.RexStandardizerwidens arithmetic operands toBIGINTfor doc-value compatibility, butPLUSnodes do not have their type serialized inJSON(unlikeCAST/MINUS). On deserialization the type is re-derived fromBIGINToperands, breaking operators likeITEMthat expectint.Fix: Wrap arithmetic results in an explicit
CAST(INTEGER)inRexStandardizer.visitCall()when the original type is narrower thanBIGINT.CASTnodes always serialize their type, soINTEGERis preserved through serialization and deserialization.Test Added:
testArithmeticInItemIndexPreservesIntegerType:PLUS(int, int)preservesINTEGERtype through serialization round-trip (the main bug fix)testArithmeticBigintNotWrappedInCast:PLUS(bigint, bigint)staysBIGINTwithout unnecessaryCAST(no regression)testArithmeticWithFieldPreservesIntegerType:field_ref + 1where field isINTEGERpreservesINTEGER(field-based index scenario)testMvindexWithNonZeroIndexPushdown:mvindex(arr, 2)works, non-zero literal index with pushdowntestMvindexWithStatsAggregationPushdown:mvindex(arr, 1)inside stats count() by eRelated Issues
Resolves #5660
See also: #5670 (alternative plan-layer fix that is ineffective because the serialization layer overrides it)
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.