A predicate on a multi-valued field matches only when it is pushed down

オープン
#5,834 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java, sql
領域
backend, databases

調査の方向性

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 の本文から書いたものです。

説明

bug calcite PPL
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, sort and any other operator that blocks pushdown moves a predicate from one semantics to the other without the query saying anything about it.
Directions
  1. Represent a multi-valued field as an ARRAY in 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.
  2. 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時間
マージ済み PR(30日)
34

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

opensearch-project/sql のほかの issue

opensearch-project/sql の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。