Skip to content

[BugFix] Accept single values in mvindex and date/time values in split (#5948) - #5955

Merged
Swiddis merged 1 commit into
opensearch-project:mainfrom
shuseng8:fix/5948-mvindex-scalar-split-datetime
Nov 30, 2026
Merged

Swiddis merged 1 commit into
opensearch-project:mainfrom
shuseng8:fix/5948-mvindex-scalar-split-datetime

Conversation

@shuseng8

Copy link
Copy Markdown
Contributor

Description

mvindex rejected a plain (single-value) field with MVINDEX function expects {[ARRAY,INTEGER]|[ARRAY,INTEGER,INTEGER]}, but got [STRING,INTEGER], and split rejected date/time values with SPLIT 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:

  • mvindex now also accepts a non-array first argument and treats it as a one-element array (MVIndexFunctionImp, plus a second ANY signature in PPLFuncImpTable; array arguments keep the existing path).
    • mvindex(value, 0) and mvindex(value, -1) return the value; any other index returns null. The value keeps its own type (string, number, timestamp, ...).
    • mvindex(value, start, end) wraps the value with array(value) and slices it as before, so a covering range returns a one-element array.
    • A null value returns null, not a one-element array holding null, so isnull(mvindex(field, 0)) keeps working.
  • split now also accepts DATE, TIME and TIMESTAMP input. The value is cast to its string form the same way cast(value as string) is, so split(ts, "-") returns the same result as split(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 mvindex and split in docs/user/ppl/functions/collection.md are updated.

Related Issues

Resolves #5948

Check List

  • New functionality includes testing.
    • Unit tests in CalcitePPLArrayFunctionTest (string, number, null and computed-index single values, ranges, split on a date and the explicit-cast equivalent, and the existing type errors for non-integer indexes and numeric split input). 7 of them fail without the fix.
    • Integration tests in CalciteArrayFunctionIT (also run through CalciteNoPushdownIT).
    • YAML REST test issues/5948.yml using the reproduction from the issue.
  • New functionality has been documented.
    • New functionality has javadoc added.
    • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

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.

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>
@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Make CASE result type nullable

The CASE branch returns value with its original (possibly non-nullable) type while
the ELSE branch returns a null literal, which can lead to a type mismatch or an
inferred non-nullable result type when value is non-nullable. Ensure the CASE result
type is nullable so that returning null for out-of-range indexes is type-safe.

core/src/main/java/org/opensearch/sql/expression/function/CollectionUDF/MVIndexFunctionImp.java [90-98]

 RexNode isFirst =
     builder.makeCall(
         SqlStdOperatorTable.EQUALS, index, builder.makeExactLiteral(BigDecimal.ZERO));
 RexNode isLast =
     builder.makeCall(
         SqlStdOperatorTable.EQUALS, index, builder.makeExactLiteral(BigDecimal.ONE.negate()));
 RexNode coversValue = builder.makeCall(SqlStdOperatorTable.OR, isFirst, isLast);
+RelDataType nullableType =
+    builder.getTypeFactory().createTypeWithNullability(value.getType(), true);
 return builder.makeCall(
-    SqlStdOperatorTable.CASE, coversValue, value, builder.makeNullLiteral(value.getType()));
+    SqlStdOperatorTable.CASE,
+    coversValue,
+    builder.makeCast(nullableType, value),
+    builder.makeNullLiteral(nullableType));
Suggestion importance[1-10]: 4

__

Why: The suggestion raises a valid concern about type nullability in the CASE expression, but Calcite typically handles nullability inference in CASE by widening to the least restrictive type. The tests pass with the current implementation, so the impact is likely minor.

Low

@shuseng8

Copy link
Copy Markdown
Contributor Author

Hi @Swiddis, this PR fixes #5948 following the approach you described in the issue. Could you approve the CI workflow runs and add the bugFix label when you get a chance? Happy to address any feedback. Thanks!

@shuseng8

Copy link
Copy Markdown
Contributor Author

Hi @Swiddis, gentle ping on this when you have a moment. Could you approve the CI workflow runs and add the bugFix label? Happy to make any changes. Thanks!

@Swiddis Swiddis added the bugFix label Nov 29, 2026

@Swiddis Swiddis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm assuming actions pass (link checker ok) -- will check tomorrow that they did

@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.09%. Comparing base (b90d1d6) to head (303b93e).
⚠️ Report is 14 commits behind head on main.

❌ 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              
Flag Coverage Δ
sql-engine 76.09% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shuseng8

Copy link
Copy Markdown
Contributor Author

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.

@Swiddis
Swiddis merged commit f25997e into opensearch-project:main Nov 30, 2026
47 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] PPL mvindex rejects single-value fields, and split rejects timestamps

2 participants