Skip to content

Support mvindex eval function#4794

Merged
Swiddis merged 1 commit into
opensearch-project:mainfrom
ahkcs:feat/eval_mvindex
Nov 13, 2025
Merged

Support mvindex eval function#4794
Swiddis merged 1 commit into
opensearch-project:mainfrom
ahkcs:feat/eval_mvindex

Conversation

@ahkcs

@ahkcs ahkcs commented Nov 12, 2025

Copy link
Copy Markdown
Collaborator

Description

The mvindex function returns a subset of a multivalue array using start and optional end index values.
It supports two modes of operation:

  1. Single element access:
    mvindex(array, index) — Returns the element at the specified index
  2. Range access:
    mvindex(array, start, end) — Returns an array slice from start to end (inclusive)

Key Features

  • 0-based indexing: First element is at index 0 (PPL convention)
  • Negative indexing: -1 refers to the last element, -2 to the second-to-last, etc.
  • Inclusive end index: Range mvindex(array, 1, 3) returns elements at indices 1, 2, and 3

Usage Examples

Single Element Access

source=people | eval array = array('a', 'b', 'c', 'd', 'e'), result = mvindex(array, 1) | fields result
# Returns: b
source=people | eval array = array('a', 'b', 'c', 'd', 'e'), result = mvindex(array, -1) | fields result
# Returns: e

Range Access

source=people | eval array = array(1, 2, 3, 4, 5), result = mvindex(array, 1, 3) | fields result
# Returns: [2, 3, 4]
source=people | eval array = array(1, 2, 3, 4, 5), result = mvindex(array, -3, -1) | fields result
# Returns: [3, 4, 5]

Check List

  • New functionality includes testing.
  • 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.

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.

Signed-off-by: Kai Huang <ahkcs@amazon.com>

@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

if (args.length == 2) {
// Single element access using ITEM (1-based indexing)
return resolveSingleElement(builder, array, startIdx, arrayLen);
} else {

@Swiddis Swiddis Nov 12, 2025

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.

Is the args.length < 2 case worth handling?

@ahkcs ahkcs Nov 12, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The minimum number of arguments is 2, which is when we use mvindex(<mv>,<start>)

@ykmr1224 ykmr1224 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

@Swiddis Swiddis merged commit dd52196 into opensearch-project:main Nov 13, 2025
38 of 46 checks passed
opensearch-trigger-bot Bot pushed a commit that referenced this pull request Nov 13, 2025
(cherry picked from commit dd52196)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Swiddis pushed a commit that referenced this pull request Nov 14, 2025
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
asifabashar pushed a commit to asifabashar/sql that referenced this pull request Dec 10, 2025
@github-project-automation github-project-automation Bot moved this from Todo to Done in PPL 2026 Roadmap Jan 27, 2026
@ahkcs ahkcs self-assigned this Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.19-dev enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants