[FEATURE] Define a schema-conflict and mismatched-data handling policy for multi-index queries
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
先阅读 MergeRuleHelper 及其 DeepMergeRule、TextKeywordConflictRule 和 LatestRule 实现,然后沿着报告中的 parsing 路径跟踪 OpenSearchExprValueFactory 和 ObjectContent。比较当前如何处理 schema 冲突和每个文档的不匹配。完成的条件是:为两个层级制定一致同意的策略和明确的行为,包括如何指定和测试任何可配置模式。
由索引模型根据 Issue 内容生成。
描述
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:
- Schema-merge-time conflicts: the same field name has genuinely incompatible mapping types across backing indices (e.g.
objectin some, scalartextin others).MergeRuleHelpercurrently resolves conflicts via an ordered rule chain:DeepMergeRuleonly merges struct-vs-struct sub-properties.TextKeywordConflictRuleonly 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.
- 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).
OpenSearchExprValueFactoryblindly 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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
opensearch-project/sql 的其他 Issue
-
bug untriaged
难度 2/5 1-3 小时 新手友好度 78/100
opensearch-project/sql#5990 ·
维护者通常 1 天内回复
-
bug untriaged
难度 1/5 1 小时以内 新手友好度 85/100
opensearch-project/sql#5983 ·
维护者通常 1 天内回复
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"可能已有人在做 @nagendramohan 于 107 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 74/100
opensearch-project/sql#5684 · 4 条评论 ·
维护者通常 1 天内回复
-
[DOC] Calcite settings documentation missing examples可能已有人在做 @AzazelSensei 于 64 天前认领。 未关闭documentation PPL
难度 2/5 1-3 小时 新手友好度 72/100
opensearch-project/sql#4806 · 1 条评论 ·
维护者通常 1 天内回复
-
calcite enhancement Meta performance PPL untriaged
难度 5/5 一周以上 新手友好度 8/100
opensearch-project/sql#5991 ·
维护者通常 1 天内回复
查看 opensearch-project/sql 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 68/100
PCL-Community/PCL-CE#3907 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 2 天内回复
-
area/dependencies area/dependencies/quarkus backport/26.6 backport/26.8 kind/cve severity/critical source/scan-dependencies status/triage
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
docker-to-squash.py: check_dependencies should find mksquashfs on PATH可能已有人在做 @linzch3 今天认领。 未关闭
难度 1/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
chore
难度 1/5 1-3 小时 新手友好度 88/100
lugassawan/swe-workbench#841 ·