[BUG] dedup after sort returns 500 on a number field whose type differs across indices
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
調査の方向性
Start with the dedup sort branch in opensearch/src/main/java/org/opensearch/sql/opensearch/request/AggregateAnalyzer.java at the linked lines, then trace how field mappings determine the sort request. Reproduce with the supplied byte and long mappings and compare the pushed top_hits sort with a request that sets numeric_type. Done when the sorted dedup query returns the expected smallest f value across indices with differing numeric types.
索引モデルが issue の本文から書いたものです。
説明
Query Information
PPL Command/Query:
source=dedup_* | sort f | dedup g
f is mapped as byte in dedup_byte and as long in dedup_long. Both indices hold a document with g set to x.
Expected Result: One row for g = x, holding the document with the smallest f, which is 1. The same query with plugins.calcite.pushdown.enabled set to false returns that row, and each index queried alone returns 200 with its own row.
Actual Result: HTTP 500.
Pushdown on:
{
"error": {
"context": {
"stage": "executing",
"stage_description": "Running the query"
},
"reason": "java.sql.SQLException: exception while executing query: Failed to fetch data from the index: the background task failed or interrupted.\n Inner error: Failed to execute phase [fetch], ",
"details": "java.sql.SQLException: exception while executing query: Failed to fetch data from the index: the background task failed or interrupted.\n Inner error: Failed to execute phase [fetch], ",
"location": ["while running the query"],
"code": "UNKNOWN",
"type": "RuntimeException"
},
"status": 500
}
Pushdown off:
{
"schema": [
{
"name": "f",
"type": "bigint"
},
{
"name": "g",
"type": "string"
}
],
"datarows": [
[
1,
"x"
]
],
"total": 1,
"size": 1
}
The error body does not name the cause. The same request sent as a raw _search fails with class java.lang.Integer cannot be cast to class java.lang.Long, shown under Issue Summary.
Dataset Information
Dataset/Schema Type
- OpenTelemetry (OTEL)
- Simple Schema for Observability (SS4O)
- Open Cybersecurity Schema Framework (OCSF)
- Custom (details below)
Index Mapping
PUT dedup_byte { "mappings": { "properties": { "f": { "type": "byte" }, "g": { "type": "keyword" } } } }
PUT dedup_long { "mappings": { "properties": { "f": { "type": "long" }, "g": { "type": "keyword" } } } }
Sample Data
POST dedup_byte/_doc/1?refresh=true { "f": 1, "g": "x" }
POST dedup_long/_doc/1?refresh=true { "f": 3, "g": "x" }
Bug Description
Issue Summary:
A pushed dedup after sort becomes a composite aggregation on the dedup field with a top_hits of size 1 inside it, sorted on the sort field. The sort is added in the dedup branch of AggregateAnalyzer as SortBuilders.fieldSort(key.field()).order(order).missing(missing). The composite groups on g, and the top_hits sorts on f with no numeric_type.
Pushed request from _explain
{
"from": 0,
"size": 0,
"timeout": "1m",
"aggregations": {
"composite_buckets": {
"composite": {
"size": 10000,
"sources": [
{
"g": {
"terms": {
"field": "g",
"missing_bucket": false,
"order": "asc"
}
}
}
]
},
"aggregations": {
"$f1": {
"top_hits": {
"from": 0,
"size": 1,
"version": false,
"seq_no_primary_term": false,
"explain": false,
"fields": [
{
"field": "g"
},
{
"field": "f"
}
],
"sort": [
{
"f": {
"order": "asc",
"missing": "_first"
}
}
]
}
}
}
}
}
}
Each shard returns its sort values in its own field's Java type, an Integer from the byte index and a Long from the long index. When both shards return hits for the same bucket, InternalTopHits.reduce merges them with TopDocs.merge, which compares the two values directly and throws. Sent as a raw _search to dedup_*?error_trace=true, the pushed request returns 500 with class java.lang.Integer cannot be cast to class java.lang.Long.
Stack from the raw _search
java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Long
at java.base/java.lang.Long.compareTo(Long.java:73)
at org.apache.lucene.search.FieldComparator.compareValues(FieldComparator.java:115)
at org.apache.lucene.search.TopDocs$MergeSortQueue.lessThan(TopDocs.java:188)
at org.apache.lucene.search.TopDocs$MergeSortQueue.lessThan(TopDocs.java:126)
at org.apache.lucene.util.PriorityQueue.upHeap(PriorityQueue.java:308)
at org.apache.lucene.util.PriorityQueue.add(PriorityQueue.java:192)
at org.apache.lucene.search.TopDocs.mergeAux(TopDocs.java:306)
at org.apache.lucene.search.TopDocs.merge(TopDocs.java:261)
at org.opensearch.search.aggregations.metrics.InternalTopHits.reduce(InternalTopHits.java:150)
at org.opensearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:188)
at org.opensearch.search.aggregations.bucket.composite.InternalComposite.reduceBucket(InternalComposite.java:280)
at org.opensearch.search.aggregations.bucket.composite.InternalComposite.reduce(InternalComposite.java:229)
A plain sort f on dedup_* returns 200 with both rows, so the failure is specific to the top_hits sort. The failure does not depend on which type PPL picks when it merges the index mappings, since the request names only the field.
f in index 0 |
f in index 1 |
Merged types seen | sort f | dedup g |
sort - f | dedup g |
dedup g with no sort |
|---|---|---|---|---|---|
byte |
long |
tinyint, bigint |
500 | 500 | 200 |
integer |
long |
int |
500 | 500 | 200 |
integer |
double |
double, int |
500 | 500 | 200 |
float |
double |
float |
500 | 500 | 200 |
short |
integer |
smallint, int |
200 | 200 | 200 |
Each row used two indices built like the repro, with two documents each, g set to x and y, and f values of 1 and 2 for byte, 3 and 4 for short, 5 and 6 for integer, 7 and 8 for long, 1.5 and 2.5 for float, and 3.25 and 4.75 for double. Each pair ran under three sets of index names. The merged type depends on the index names, so the column lists every type seen. Every index queried alone returned 200 for sort f | dedup g. The short and integer row passes because both shards return the same Java type for the sort value.
Setting numeric_type on the sort makes the raw request pass. With "numeric_type": "long" and with "numeric_type": "double", the raw top_hits returned 200 for byte with long, integer with long, integer with double and float with double. Which of the two the plugin should set depends on the field's types.
Steps to Reproduce:
curl -s -XPUT "localhost:9200/dedup_byte" -H 'Content-Type: application/json' \
-d '{"mappings":{"properties":{"f":{"type":"byte"},"g":{"type":"keyword"}}}}'
curl -s -XPUT "localhost:9200/dedup_long" -H 'Content-Type: application/json' \
-d '{"mappings":{"properties":{"f":{"type":"long"},"g":{"type":"keyword"}}}}'
curl -s -XPOST "localhost:9200/dedup_byte/_doc/1?refresh=true" -H 'Content-Type: application/json' -d '{"f":1,"g":"x"}'
curl -s -XPOST "localhost:9200/dedup_long/_doc/1?refresh=true" -H 'Content-Type: application/json' -d '{"f":3,"g":"x"}'
# 1. dedup after sort returns HTTP 500
curl -s -XPOST "localhost:9200/_plugins/_ppl" -H 'Content-Type: application/json' \
-d '{"query":"source=dedup_* | sort f | dedup g"}' -w '\nHTTP %{http_code}\n'
# 2. dedup without the sort returns HTTP 200
curl -s -XPOST "localhost:9200/_plugins/_ppl" -H 'Content-Type: application/json' \
-d '{"query":"source=dedup_* | dedup g"}' -w '\nHTTP %{http_code}\n'
# 3. With pushdown off, query 1 returns HTTP 200 with the row for f = 1
curl -s -XPUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' \
-d '{"transient":{"plugins.calcite.pushdown.enabled":false}}'
curl -s -XPOST "localhost:9200/_plugins/_ppl" -H 'Content-Type: application/json' \
-d '{"query":"source=dedup_* | sort f | dedup g"}' -w '\nHTTP %{http_code}\n'
# Restore the default
curl -s -XPUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' \
-d '{"transient":{"plugins.calcite.pushdown.enabled":null}}'
Impact:
Any dedup after a sort on a rollover or wildcard source fails once one index maps the sort field to a type whose sort values have a different Java type, such as an integer field that a later index maps as long.
Environment Information
OpenSearch Version: 3.10.0-SNAPSHOT, sql plugin built from main at f36c99f84.
Additional Details: plugins.calcite.enabled is true, plugins.calcite.pushdown.enabled is true and plugins.calcite.fallback.allowed is false, all defaults. With plugins.calcite.enabled set to false the query returns the same body as pushdown off.
- 主要言語
- Java
- スター
- 176
- フォーク
- 237
- 平均マージ
- 2日 12時間
- マージ済み PR(30日)
- 34
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 1週間以上 初心者へのやさしさ 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 ·