Skip to content

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

Open

Description

@Swiddis

What is the bug?
mvindex fails with a type error on a plain string or number field, where SPL treats a single-value field as a one-element list.

How can one reproduce the bug?
Steps to reproduce the behavior:

  1. Create an index with a keyword, an integer and a date field, and index one doc.
curl -s -X PUT localhost:9200/mvdemo -H 'Content-Type: application/json' \
  -d '{"mappings":{"properties":{"s":{"type":"keyword"},"n":{"type":"integer"},"ts":{"type":"date"}}}}' | jq .acknowledged
curl -s -X POST 'localhost:9200/mvdemo/_doc?refresh=true' -H 'Content-Type: application/json' \
  -d '{"s":"abc","n":7,"ts":"2026-01-02T03:04:05Z"}' | jq .result
  1. Call mvindex on the string field. It fails instead of returning abc. A number field fails the same way with [INTEGER,INTEGER].
curl -s -X POST localhost:9200/_plugins/_ppl -H 'Content-Type: application/json' \
  -d '{"query":"source=mvdemo | eval r = mvindex(s, 0) | fields r"}' | jq -c '{status, error: .error.details}'
# {"status":400,"error":"MVINDEX function expects {[ARRAY,INTEGER]|[ARRAY,INTEGER,INTEGER]}, but got [STRING,INTEGER]"}
  1. Call split on the date field. It fails the same way.
curl -s -X POST localhost:9200/_plugins/_ppl -H 'Content-Type: application/json' \
  -d '{"query":"source=mvdemo | eval p = split(ts, \"-\") | fields p"}' | jq -c '{status, error: .error.details}'
# {"status":400,"error":"SPLIT function expects {[STRING,STRING]}, but got [TIMESTAMP,STRING]"}

What is the expected behavior?
Same as SPL: mvindex(s, 0) returns abc, mvindex(s, 1) returns null, and mvindex(n, 0) returns 7. split(ts, "-") splits the timestamp's string form, as split(cast(ts as string), "-") already does.

What is your host/environment?

  • mainline (3.10.0-SNAPSHOT), single node

Do you have any screenshots?
N/A

Do you have any additional context?

  • This is documented behavior, not a doc contradiction: the docs define mvindex's first argument as an array, and every example builds one with array(...). It's a fidelity gap for queries migrated from SPL, where single-value and multi-value fields are interchangeable.
  • In a sample of ~680 PPL queries using mvindex from a migration workload, 5 failed with the [STRING,INTEGER] error. Across the same workload's logs, 19 queries failed with the SPLIT ... [TIMESTAMP,STRING] error.
  • The workaround mvindex(array(s), 0) only works when the field is always single-valued. On a doc with "s":["x","y"], it returns the whole list [x, y] as element 0, not x.
  • Mechanism: MVINDEX is registered with an operand checker of ARRAY, INTEGER [, INTEGER] only (core/src/main/java/org/opensearch/sql/expression/function/PPLFuncImpTable.java:1282-1292), and MVIndexFunctionImp.resolve assumes args[0] is an array (core/.../CollectionUDF/MVIndexFunctionImp.java:48-63). SPLIT is registered with CHARACTER, CHARACTER only (PPLFuncImpTable.java:1256-1279).
  • Possible fix: let mvindex accept a non-array first argument and wrap it as a one-element array before resolving, so index 0 and -1 return the value and any other index returns null. A null scalar should return null, not a one-element array holding null, which matches SPL and keeps isnull(mvindex(...)) checks working. The other mv* functions likely want the same treatment. For split, accept TIMESTAMP/DATE/TIME through an implicit cast to string.
  • Not fixed by fix: [bug] PPL query with mvindex() fails when plugins.calcite.pushdown.enabled=true (#5660) #5689 or fix: [bug] narrow BIGINT to INTEGER for int-domain function arguments (#5660) #5728. fix: [bug] PPL query with mvindex() fails when plugins.calcite.pushdown.enabled=true (#5660) #5689 (merged) fixes a pushdown CompileException on mvindex index arithmetic. fix: [bug] narrow BIGINT to INTEGER for int-domain function arguments (#5660) #5728 (open) narrows BIGINT to INTEGER for int-domain arguments. Both assume the first argument is already an array.

Activity

  1. added
    bug
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions