A predicate on a multi-valued field matches only when it is pushed down
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 42/100
Research direction
Start by reproducing the four queries at the /_plugins/_ppl endpoint and comparing their _explain output, including with pushdown and Calcite fallback disabled. Trace how scalar comparisons receive multi-valued fields in the v2 and Calcite paths, then compare the existing pushdown behavior. Done means predicates such as =, !=, in, and like have consistent multi-value semantics regardless of pipeline position, without silent row loss or type errors.
Written by the indexing model from the issue text.
Description
What is wrong
An OpenSearch field can hold several values; PPL types it as a scalar. A term query on a multi-valued field has ANY semantics in the index — it matches when any value equals the term — but the in-engine comparison compares the whole list against the literal, so it matches nothing.
Whether a predicate is evaluated in the index or in the engine depends on whether it can be pushed down, which depends on where it sits in the pipeline. So the same predicate over the same data returns different rows depending on what precedes it.
Reproduce
Default settings. Nothing unusual in the mapping.
PUT /arr
{"settings":{"number_of_shards":1},
"mappings":{"properties":{"s":{"type":"keyword"},
"k":{"type":"keyword"},
"n":{"type":"integer"}}}}
POST /arr/_bulk?refresh=true
{"index":{"_id":"1"}}
{"s":"multi","k":["a","b"],"n":[80,443]}
{"index":{"_id":"2"}}
{"s":"single","k":"c","n":22}
POST /_plugins/_ppl {"query": "source=arr | where k = 'a'"}
POST /_plugins/_ppl {"query": "source=arr | head 2 | where k = 'a'"}
| query | rows returned | filter reached the DSL |
|---|---|---|
source=arr | where k = 'a' |
1 | yes |
source=arr | head 2 | where k = 'a' |
0 | no |
source=arr | where n = 80 |
1 | yes |
source=arr | head 2 | where n = 80 |
0 | no |
Document 1 satisfies the predicate in all four. A head in front of the filter changes the answer. The last column is from _explain: FILTER-> is present in the scan's pushdown context for the first and third, absent for the second and fourth.
plugins.calcite.pushdown.enabled=false reaches the same gap without a head.
Both engines
plugins.calcite.enabled=false (v2) gives the same answers, so this is not a Calcite regression — it is long-standing behaviour in both engines.
The mechanism
With plugins.calcite.fallback.allowed=false, the numeric case stops being silent:
POST /_plugins/_ppl {"query":"source=arr | head 2 | where n = 80"}
HTTP 500, code UNKNOWN
java.sql.SQLException: exception while executing query:
class java.util.ArrayList cannot be cast to class java.lang.Integer
The type the engine works with is a scalar while the value it receives is a list:
describe arr -> n: int, k: string
source=arr | eval t=typeof(n) | fields t -> INT
source=arr | fields k, n -> [["a","b"], [80,443]]
Generated code casts the value to the declared scalar type and fails. One array value anywhere in the column is enough: head 2 | where n = 22 fails the same way, even though the document it should match holds a scalar 22.
With fallback allowed the failure is swallowed and the query is answered by the v2 engine instead, which is why the default configuration shows a missing row rather than an error. A keyword column does not throw at all — it just does not match.
Why it matters
- The wrong answer is silent in the default configuration: fewer rows, no warning.
- It applies to every multi-valued field, not to a particular mapping type.
head,sortand any other operator that blocks pushdown moves a predicate from one semantics to the other without the query saying anything about it.
Directions
- Represent a multi-valued field as an
ARRAYin the type system and lower=on one to a quantified comparison (= SOME (...)), which Calcite supports natively. Correct, but it touches the declared type of every field that can hold several values. - Keep the scalar type and give the comparison a multi-value-aware form that the pushdown recognizer and the in-engine path agree on. Narrower, and it can be introduced per operator (
=,!=,in,like).
Either way the fix belongs to the comparison, not to any one field type, and every field benefits.
Context
Found while reviewing #5830, which adds flat_object support. A flat_object leaf holding several values behaves the same way, since it is just another multi-valued column; that PR inherits this rather than introducing it, and says so.
Environment
OpenSearch 3.9.0-SNAPSHOT, opensearch-sql 3.9.0.0-SNAPSHOT. Reproduced on 3.10.0-SNAPSHOT as well.
- Dominant language
- Java
- Stars
- 176
- Forks
- 237
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 34
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from opensearch-project/sql
-
bug untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
opensearch-project/sql#5990 ·
Maintainers usually reply within 1 day
-
bug untriaged
Difficulty 1/5 Under an hour Newbie friendliness 85/100
opensearch-project/sql#5983 ·
Maintainers usually reply within 1 day
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"Possibly taken @nagendramohan claimed this 107 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
opensearch-project/sql#5684 · 4 comments ·
Maintainers usually reply within 1 day
-
[DOC] Calcite settings documentation missing examplesPossibly taken @AzazelSensei claimed this 64 days ago. Opendocumentation PPL
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
opensearch-project/sql#4806 · 1 comment ·
Maintainers usually reply within 1 day
-
calcite enhancement Meta performance PPL untriaged
Difficulty 5/5 Over a week Newbie friendliness 8/100
opensearch-project/sql#5991 ·
Maintainers usually reply within 1 day
All issues in opensearch-project/sql
Similar issues
-
chore
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
lugassawan/swe-workbench#841 ·
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
EndlessPixel-Studio/FakePlayer-CE#155 ·
Maintainers usually reply within 1 day
-
Document the isv:HDFGroup Linux package repositories and signing keyPossibly taken @brtnfld claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
checkstyle/checkstyle#23174 ·
Maintainers usually reply within 1 day