Repository navigation
[BugFix] Accept single values in mvindex and date/time values in split (#5948) - #5955
Conversation
opensearch-project#5948) mvindex now treats a non-array first argument as a one-element array, as SPL does for single-value fields: indexes 0 and -1 return the value, any other index returns null, a range returns a one-element array when it covers the value, and a null value returns null. split now accepts DATE, TIME and TIMESTAMP input through an implicit cast to string, the same as split(cast(value as string), delimiter). Signed-off-by: Shubham <87247136+shuseng8@users.noreply.github.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
Hi @Swiddis, gentle ping on this when you have a moment. Could you approve the CI workflow runs and add the |
Swiddis
left a comment
There was a problem hiding this comment.
lgtm assuming actions pass (link checker ok) -- will check tomorrow that they did
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (76.09%) is below the target coverage (99.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #5955 +/- ##
============================================
+ Coverage 76.07% 76.09% +0.02%
- Complexity 10586 10594 +8
============================================
Files 972 972
Lines 41681 41716 +35
Branches 4799 4802 +3
============================================
+ Hits 31709 31744 +35
Misses 8614 8614
Partials 1358 1358
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Hi @Swiddis, thanks for the approval! The remaining red checks look unrelated to this change (analytics-engine security IT / async PPL lifecycle IT failures, and codecov/project). Could you re-run the failed jobs when you get a chance? Happy to look at anything that still fails. |
Description
mvindexrejected a plain (single-value) field withMVINDEX function expects {[ARRAY,INTEGER]|[ARRAY,INTEGER,INTEGER]}, but got [STRING,INTEGER], andsplitrejected date/time values withSPLIT function expects {[STRING,STRING]}, but got [TIMESTAMP,STRING]. SPL treats single-value and multi-value fields interchangeably, so these queries fail when migrated.This follows the fix proposed in the issue:
mvindexnow also accepts a non-array first argument and treats it as a one-element array (MVIndexFunctionImp, plus a secondANYsignature inPPLFuncImpTable; array arguments keep the existing path).mvindex(value, 0)andmvindex(value, -1)return the value; any other index returnsnull. The value keeps its own type (string, number, timestamp, ...).mvindex(value, start, end)wraps the value witharray(value)and slices it as before, so a covering range returns a one-element array.null, not a one-element array holding null, soisnull(mvindex(field, 0))keeps working.splitnow also acceptsDATE,TIMEandTIMESTAMPinput. The value is cast to its string form the same waycast(value as string)is, sosplit(ts, "-")returns the same result assplit(cast(ts as string), "-"). Other non-string types (for example numbers) are still rejected.The issue mentions the other
mv*functions may want the same treatment; I kept this PR to the two functions in the report and can follow up on the others if wanted.Docs for
mvindexandsplitindocs/user/ppl/functions/collection.mdare updated.Related Issues
Resolves #5948
Check List
CalcitePPLArrayFunctionTest(string, number, null and computed-index single values, ranges,spliton a date and the explicit-cast equivalent, and the existing type errors for non-integer indexes and numericsplitinput). 7 of them fail without the fix.CalciteArrayFunctionIT(also run throughCalciteNoPushdownIT).issues/5948.ymlusing the reproduction from the issue.--signoffor-s.Tested locally with
./gradlew spotlessCheck :core:test :ppl:test :opensearch:test :sql:test,./gradlew :integ-test:integTest -Dtests.class="*CalciteArrayFunctionIT"and./gradlew :integ-test:yamlRestTest -Dtests.method="test {yaml=issues/5948/*}".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.