sql icon indicating copy to clipboard operation
sql copied to clipboard

[BUG] `ArrayIndexOutOfBoundsException` when querying index with disabled objects containing dot-only field names

Open ahkcs opened this issue 2 months ago • 1 comments

Bug Description

When querying an OpenSearch index that contains documents with field names consisting only of dots (e.g., ".", "..") inside disabled objects ("enabled": false), the SQL plugin throws:

ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0

The root cause is in the constructor of OpenSearchExprValueFactory.JsonPath:

public JsonPath(String rawPath) {
  this.paths = List.of(rawPath.split("\\."));
}

When rawPath is ".", the call rawPath.split("\\.") returns an empty array ([]), causing paths.get(0) to fail.


Steps to Reproduce

  1. Create index with disabled object mapping
curl -X PUT "localhost:9200/logs-disabled-test" -H 'Content-Type: application/json' -d '{
  "mappings": {
    "properties": {
      "log": {"type": "object", "enabled": false},
      "@timestamp": {"type": "date"}
    }
  }
}'
  1. Index a document with a dot-only field name
curl -X POST "localhost:9200/logs-disabled-test/_doc" -H 'Content-Type: application/json' -d '{
  "@timestamp": "2025-11-26T17:10:00.000Z",
  "log": {".": "problematic value"}
}'
  1. Run a PPL query
curl -X POST "localhost:9200/_plugins/_ppl" -H "Content-Type: application/json" -d '{
  "query": "source=logs-disabled-test"
}'
  1. Observed result

OpenSearch returns HTTP 500 with an internal exception:

{
  "error": {
    "reason": "There was internal problem at backend",
    "details": "java.sql.SQLException: exception while executing query: Index 0 out of bounds for length 0",
    "type": "RuntimeException"
  },
  "status": 500
}

Expected Behavior

The query should:

  1. Either return results successfully, treating "." as a literal field name
  2. Or return a clean, user-facing validation error

The plugin should not crash with an ArrayIndexOutOfBoundsException.


Environment

  • OS: Any
  • OpenSearch Version: 2.19-dev
  • SQL Plugin Version: 2.19-dev (Calcite engine enabled)

Additional Context

This occurs because OpenSearch setting allows arbitrary inner field names for "enabled": false object fields. These documents are indexed without validation. When log pipelines generate malformed keys like ".", they pass through fine, but the SQL plugin fails when trying to parse the field path.

Stack Trace (excerpt)

java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at java.base/java.util.ImmutableCollections$ListN.get(ImmutableCollections.java:687)
    at org.opensearch.sql.opensearch.data.value.OpenSearchExprValueFactory$JsonPath.getRootPath(...)
    at org.opensearch.sql.opensearch.data.value.OpenSearchExprValueFactory.populateValueRecursive(...)
    ...

ahkcs avatar Dec 03 '25 00:12 ahkcs

What's left here after #4907?

Swiddis avatar Dec 05 '25 17:12 Swiddis