[BUG] dedup after sort returns 500 on a number field whose type differs across indices
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Java
- Stelle
- 176
- Fork
- 237
- Merge medio
- 2g 12h
- PR unite (30g)
- 34
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di opensearch-project/sql
-
bug untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
opensearch-project/sql#5990 ·
I maintainer di solito rispondono entro 1 giorno
-
bug untriaged
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
opensearch-project/sql#5983 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"Forse già presa @nagendramohan l’ha presa 107 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
opensearch-project/sql#5684 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[DOC] Calcite settings documentation missing examplesForse già presa @AzazelSensei l’ha presa 64 giorni fa. Apertadocumentation PPL
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
opensearch-project/sql#4806 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
calcite enhancement Meta performance PPL untriaged
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
opensearch-project/sql#5991 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di opensearch-project/sql
Issue simili
-
chore
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
lugassawan/swe-workbench#841 ·
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
EndlessPixel-Studio/FakePlayer-CE#155 ·
I maintainer di solito rispondono entro 1 giorno
-
Document the isv:HDFGroup Linux package repositories and signing keyForse già presa @brtnfld l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
checkstyle/checkstyle#23174 ·
I maintainer di solito rispondono entro 1 giorno