A predicate on a multi-valued field matches only when it is pushed down
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Java
- 星标
- 176
- 派生
- 237
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 34
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
opensearch-project/sql 的其他 Issue
-
bug untriaged
难度 2/5 1-3 小时 新手友好度 78/100
opensearch-project/sql#5990 ·
维护者通常 1 天内回复
-
bug untriaged
难度 1/5 1 小时以内 新手友好度 85/100
opensearch-project/sql#5983 ·
维护者通常 1 天内回复
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"可能已有人在做 @nagendramohan 于 107 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 74/100
opensearch-project/sql#5684 · 4 条评论 ·
维护者通常 1 天内回复
-
[DOC] Calcite settings documentation missing examples可能已有人在做 @AzazelSensei 于 64 天前认领。 未关闭documentation PPL
难度 2/5 1-3 小时 新手友好度 72/100
opensearch-project/sql#4806 · 1 条评论 ·
维护者通常 1 天内回复
-
calcite enhancement Meta performance PPL untriaged
难度 5/5 一周以上 新手友好度 8/100
opensearch-project/sql#5991 ·
维护者通常 1 天内回复
查看 opensearch-project/sql 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 68/100
PCL-Community/PCL-CE#3907 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 2 天内回复
-
area/dependencies area/dependencies/quarkus backport/26.6 backport/26.8 kind/cve severity/critical source/scan-dependencies status/triage
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
docker-to-squash.py: check_dependencies should find mksquashfs on PATH可能已有人在做 @linzch3 今天认领。 未关闭
难度 1/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
chore
难度 1/5 1-3 小时 新手友好度 88/100
lugassawan/swe-workbench#841 ·