[BUG] Comparing a string field to both an integer and a decimal literal returns 500 ClassCastException

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
22/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java
领域
database

调研方向

The failure comes from the Calcite RexSimplify$RexSargBuilder.addRange call at RexSimplify.java:3617, reached through RexSimplify$SargCollector.accept2b, so start by reproducing the two-comparison query with the PPL endpoint and reading that path. The open question is whether string-to-number comparison should be allowed at all, which the maintainers need to settle before the literal-type merge can be fixed. Done means the same query either returns consistent results or fails with a 400 instead of a 500.

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

描述

bug duplicate untriaged

What is the bug?
A filter that compares a string field to an integer literal and a decimal literal fails in Calcite's RexSimplify with a ClassCastException.

How can one reproduce the bug?

  1. Create the index and doc:
curl -s -X PUT localhost:9200/hdemo -H 'Content-Type: application/json' \
  -d '{"mappings":{"properties":{"s":{"type":"keyword"},"n":{"type":"integer"},"d":{"type":"double"},"b":{"type":"boolean"},"ts":{"type":"date"}}}}' | jq .acknowledged
curl -s -X POST 'localhost:9200/hdemo/_doc?refresh=true' -H 'Content-Type: application/json' \
  -d '{"s":"abc","n":7,"d":1.5,"b":true,"ts":"2026-01-02T03:04:05Z"}' | jq .result
  1. Either comparison on its own works (where s = 0 and where s = 0.5 each return no rows).
  2. Both together fail:
curl -s -X POST localhost:9200/_plugins/_ppl -H 'Content-Type: application/json' \
  -d '{"query":"source=hdemo | where s = 0.5 or s = 0"}' | jq -c '{status, type: .error.type, error: .error.details[0:120]}'
# {"status":500,"type":"ClassCastException","error":"class java.math.BigDecimal cannot be cast to class java.lang.Double (java.math.BigDecimal and java.lang.Double are in mo"}
  1. Two separate where commands fail too, because they get merged: where s = 0.5 | where s = 0, or where s <= 0.5 | where 0 = s. Reversing the literal order flips the message (Double cannot be cast to BigDecimal).

What is the expected behavior?
No rows, the same as each comparison on its own, or a 400 if comparing a string to a number is meant to be rejected. Not a 500.

What is your host/environment?

  • mainline (3.10.0-SNAPSHOT, c7e2cea98), single node. Same result with plugins.calcite.pushdown.enabled=false.

Do you have any screenshots?
N/A

Do you have any additional context?

  • Stack: RexSimplify$RexSargBuilder.addRange(RexSimplify.java:3617) ← RexSimplify$SargCollector.accept2b. The implicit cast of s to a number gives the two comparisons different literal types (DOUBLE vs DECIMAL), and the Sarg builder merges them into one range set without unifying the types.
  • Whether string = number comparison should be allowed at all is a separate question. Today it's accepted silently (where s = 0 → 200).
  • Found by a property-based type checker (hegel).
主要语言
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 摘要。