[BUG] dedup after sort returns 500 on a number field whose type differs across indices
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Java
- Estrellas
- 176
- Forks
- 237
- Merge medio
- 2 d 12 h
- PR fusionados (30 d)
- 34
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de opensearch-project/sql
-
bug untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
opensearch-project/sql#5990 ·
Los mantenedores suelen responder en 1 día
-
bug untriaged
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
opensearch-project/sql#5983 ·
Los mantenedores suelen responder en 1 día
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"Posiblemente ocupada @nagendramohan la tomó hace 107 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
opensearch-project/sql#5684 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
[DOC] Calcite settings documentation missing examplesPosiblemente ocupada @AzazelSensei la tomó hace 64 días. Abiertodocumentation PPL
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
opensearch-project/sql#4806 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
calcite enhancement Meta performance PPL untriaged
Dificultad 5/5 Más de una semana Aptitud para principiantes 8/100
opensearch-project/sql#5991 ·
Los mantenedores suelen responder en 1 día
Todos los issues de opensearch-project/sql
Issues similares
-
NeoForge 安装任务的子任务描述有误Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
PCL-Community/PCL-CE#3907 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
Los mantenedores suelen responder en 2 días
-
area/dependencies area/dependencies/quarkus backport/26.6 backport/26.8 kind/cve severity/critical source/scan-dependencies status/triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 2 días
-
docker-to-squash.py: check_dependencies should find mksquashfs on PATHPosiblemente ocupada @linzch3 la tomó hoy. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
chore
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
lugassawan/swe-workbench#841 ·