opensearch-project / opensearch-project/sql

[BUG] Dedup crashes with ClassCastException

Open
#5,614 0 comments 0 reactions 1 assignee View on GitHub

@dai-chen is already working on this.

Since Jul 14, 2026.

bug PPL
Dominant language
Java
Stars
176
Forks
229
Avg merge
2d 21h
Merged PRs (30d)
43

Description

Bug Report

Describe the bug:

PPL DEDUP command crashes with a ClassCastException when:

  1. The dedup pushdown path is taken (composite aggregation + top_hits) — i.e., no WHERE clause precedes DEDUP
  2. The index contains any field whose _source representation is a non-primitive (Map/Object), such as geo_point stored as {"lat":..., "lon":...} or object-type fields

The top_hits response parser appears to iterate over _source fields and assumes all values are String, but encounters HashMap values from structured field types.

OpenSearch version: 3.7.0 (also reproduces on 3.4.0 with the reversed cast direction)
SQL plugin version: 3.7.0.0

Reproduction

Minimal reproduction:

# Create index with a geo_point field (stored as object in _source)
PUT test_dedup_geo
{
  "mappings": {
    "properties": {
      "name": { "type": "keyword" },
      "location": { "type": "geo_point" }
    }
  }
}

POST test_dedup_geo/_bulk
{"index":{}}
{"name":"alice","location":{"lat":40.7,"lon":-74.0}}
{"index":{}}
{"name":"bob","location":{"lat":34.0,"lon":-118.2}}
{"index":{}}
{"name":"alice","location":{"lat":51.5,"lon":-0.1}}

POST test_dedup_geo/_refresh

# This FAILS:
POST _plugins/_ppl
{"query": "SOURCE = test_dedup_geo | DEDUP name | FIELDS name"}

# This WORKS (WHERE clause prevents dedup pushdown):
POST _plugins/_ppl
{"query": "SOURCE = test_dedup_geo | WHERE name IS NOT NULL | DEDUP name | FIELDS name"}
On 3.7.0:
{
  "error": {
    "reason": "java.sql.SQLException: exception while executing query: class java.util.HashMap cannot be cast to class java.lang.String (java.util.HashMap and java.lang.String are in module java.base of loader 'bootstrap')",
    "type": "RuntimeException"
  },
  "status": 500
}
On 3.4.0:
{
  "error": {
    "reason": "java.sql.SQLException: exception while executing query: class java.lang.String cannot be cast to class java.util.Map (java.lang.String and java.util.Map are in module java.base of loader 'bootstrap')",
    "type": "RuntimeException"
  },
  "status": 500
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.