[FEATURE] Define a schema-conflict and mismatched-data handling policy for multi-index queries

未关闭
#5,610 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
冷清
技术栈
java
领域
backend, databases

调研方向

先阅读 MergeRuleHelper 及其 DeepMergeRule、TextKeywordConflictRule 和 LatestRule 实现,然后沿着报告中的 parsing 路径跟踪 OpenSearchExprValueFactory 和 ObjectContent。比较当前如何处理 schema 冲突和每个文档的不匹配。完成的条件是:为两个层级制定一致同意的策略和明确的行为,包括如何指定和测试任何可配置模式。

由索引模型根据 Issue 内容生成。

描述

enhancement

Is your feature request related to a problem?

Querying across multiple indices (e.g. a wildcard index pattern like source=logs-*) has no consistent policy for handling two related but distinct problems:

  1. Schema-merge-time conflicts: the same field name has genuinely incompatible mapping types across backing indices (e.g. object in some, scalar text in others). MergeRuleHelper currently resolves conflicts via an ordered rule chain:
    • DeepMergeRule only merges struct-vs-struct sub-properties.
    • TextKeywordConflictRule only resolves scalar-vs-scalar (text/keyword) conflicts.
    • Any other mismatch falls through to LatestRule, which silently picks whichever backing index's mapping was processed last, with no validation, error or coercion.
  2. Execution-time mismatched data: even once a unified schema is settled on, an individual document's actual value can still fail to match the declared type for that field — not because the document is malformed, but because it came from a differently-mapped index (e.g. dynamic mapping drift across backing indices, or one index legitimately storing the field as a plain string while another stores it as a nested object). OpenSearchExprValueFactory blindly casts each document's raw value to the declared type with no defensive handling, so a document from a mismatched-mapping shard throws:
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.Map
  at org.opensearch.sql.opensearch.data.utils.ObjectContent.map(ObjectContent.java:81)
  at org.opensearch.sql.opensearch.data.value.OpenSearchExprValueFactory.parseStruct(OpenSearchExprValueFactory.java:376)
  at org.opensearch.sql.opensearch.data.value.OpenSearchExprValueFactory.parse(OpenSearchExprValueFactory.java:218)
  at org.opensearch.sql.opensearch.data.value.OpenSearchExprValueFactory.construct(OpenSearchExprValueFactory.java:189)
  at org.opensearch.sql.opensearch.response.OpenSearchResponse.lambda$handleAggregationResponse$2(OpenSearchResponse.java:263)
  at org.opensearch.sql.opensearch.storage.scan.OpenSearchIndexEnumerator.moveNext(OpenSearchIndexEnumerator.java:139)

What solution would you like?

Solutions generally fall into four strategies. Some apply only at execution time (per document, during row deserialization); others apply at both schema-merge time (before query execution, once per index-pattern resolution) and execution time, depending on where they're implemented. Rather than hardcoding a single strategy, these could be exposed as a configurable mode, similar to Spark's CSV/JSON reader mode option (PERMISSIVE, FAILFAST, DROPMALFORMED), letting users choose the behavior that fits their use case:

Strategy Applies to Mechanism Reference model
Fail-fast Schema-merge time & execution time Reject an unresolvable conflict (schema-merge time) or throw on a per-row mismatch (execution time), instead of silently picking one or crashing uncontrolled Spark (AnalysisException on schema merge; FAILFAST mode for per-record parsing), Trino (fails at split planning), Iceberg (rejects writes with mismatched schema unless mergeSchema is explicitly enabled)
Coercion Schema-merge time & execution time Pick one common declared type across indices (schema-merge time), or convert a mismatched value into the expected type per row (execution time) Spark's Parquet mergeSchema read option (widens compatible types across files); Iceberg's mergeSchema write option (adds missing columns at ingestion time, opt-in via write.spark.accept-any-schema)
Null on mismatch Execution time only When a value doesn't match the expected type, return null for that field/row instead of throwing ES|QL's unsupported column type behavior; Spark's PERMISSIVE mode (default) for malformed field values
Drop mismatched row Execution time only Silently exclude the offending row/document from results entirely Spark's DROPMALFORMED mode

What alternatives have you considered?

  • Schema-on-read with no unified type: the most permissive, but a much larger architectural change inconsistent with OpenSearch SQL/PPL's current Calcite-based single-row-schema design.
  • A VARIANT-like semi-structured type for conflicting fields: would require a new core data type and query syntax (field:path::type), a larger change than extending the existing merge/parsing layers.

Do you have any additional context?

Related work

This gap has been patched twice before, each time narrowly for one specific type pairing rather than as a general policy:

Issue / PR Conflict type Layer fixed Fix
#3625 / #3653 struct vs. struct (differing sub-properties) Schema-merge time Added DeepMergeRule to recursively merge sub-properties from both indices
#4659 text vs. keyword (scalar vs. scalar) Schema-merge time Added TextKeywordConflictRule, forcing _source-based retrieval instead of doc_values
Examples

Minimal reproduction (OpenSearch 3.8.0-SNAPSHOT, main HEAD):

PUT /log-repro-object
{
  "mappings": {
    "properties": {
      "log": { "properties": { "ts": { "type": "date" } } }
    }
  }
}

PUT /log-repro-scalar
{
  "mappings": {
    "properties": {
      "log": { "type": "text" }
    }
  }
}

POST /log-repro-object/_doc
{ "log": { "ts": "2026-07-06T10:00:00Z" }, "path": "/a" }

POST /log-repro-scalar/_doc
{ "log": "plain string log line", "path": "/b" }
POST /_plugins/_ppl
{ "query": "source = log-repro-* | dedup path" }
主要语言
Java
星标
176
派生
237
平均合并
2 天 12 小时
30 天内合并 PR
34

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

opensearch-project/sql 的其他 Issue

查看 opensearch-project/sql 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。