Repository navigation
Open
Labels
bugSomething isn't working
Description
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:
- 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- Call
mvindexon the string field. It fails instead of returningabc. 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]"}- Call
spliton 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 witharray(...). 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
mvindexfrom a migration workload, 5 failed with the[STRING,INTEGER]error. Across the same workload's logs, 19 queries failed with theSPLIT ... [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, notx. - Mechanism:
MVINDEXis registered with an operand checker ofARRAY, INTEGER [, INTEGER]only (core/src/main/java/org/opensearch/sql/expression/function/PPLFuncImpTable.java:1282-1292), andMVIndexFunctionImp.resolveassumesargs[0]is an array (core/.../CollectionUDF/MVIndexFunctionImp.java:48-63).SPLITis registered withCHARACTER, CHARACTERonly (PPLFuncImpTable.java:1256-1279). - Possible fix: let
mvindexaccept 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 keepsisnull(mvindex(...))checks working. The othermv*functions likely want the same treatment. Forsplit, accept TIMESTAMP/DATE/TIME through an implicit cast to string. - Not fixed by fix: [bug] PPL query with
mvindex()fails whenplugins.calcite.pushdown.enabled=true(#5660) #5689 or fix: [bug] narrow BIGINT to INTEGER for int-domain function arguments (#5660) #5728. fix: [bug] PPL query withmvindex()fails whenplugins.calcite.pushdown.enabled=true(#5660) #5689 (merged) fixes a pushdownCompileExceptiononmvindexindex 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.
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity