opensearch-project / opensearch-project/sql
[RFC] Support DECIMAL data type in SQL/PPL
@LantaoJin is already working on this.
Since Mar 26, 2026.
- Dominant language
- Java
- Stars
- 176
- Forks
- 229
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 43
Description
Problem Statement
Since OpenSearch Core doesn't have a Decimal type, ref link, SQL and PPL correspondingly don't have Decimal types either.
Current State
For decimal number processing, Double or Float types are used. Both Double and Float have precision loss issues. For example, https://github.com/opensearch-project/sql/issues/3614 mentioned an issue about precision loss in Double
Long-Term Goals
- Support
Decimaltype in SQL/PPL - Support
DecimalLiteraland set numeric literal to decimal literal as default, e.g. 0.06 is decimal literal. - Support type suffix to specify numeric literal, e.g.
0.06Dis double literal,0.06Fis float literal,0.06BDis decimal literal. - Support auto implicitly cast (least restrictive type) for operations, e.g.
decimal(2.2) - decimal(3.3) => decimal(4.3),double + decimal => double, etc.
Proposal
As PPL/SQL serves as a unified and general-purpose query language, it shouldn't be completely bound to the underlying engine and should maintain certain cross-platform compatibility, as we've already supported PPL queries on Spark. To better support cross-engine query requirements and avoid Double precision loss issues"
Approach
- Add a new Data Type
Decimal - Update g4 files to support type suffix literal
- Support auto implicitly cast (least restrictive type) for operations in Calcite
Alternative
There are two alternatives:
- Continue as-is.
- To fix the literal issue only https://github.com/opensearch-project/sql/issues/3614, we can just treat double literal as decimal literal.
Implementation Discussion
Here is some reference about how Spark handle decimal:
spark-sql (default)> select 0.06 - 0.01; -- default numeric literal is decimal literal
(0.06 - 0.01)
0.05
spark-sql (default)> select typeof(0.06 - 0.01);
typeof((0.06 - 0.01))
decimal(3,2)
spark-sql (default)> select 0.06D - 0.01D; -- support type suffix
(0.06 - 0.01)
0.049999999999999996
spark-sql (default)> select typeof(0.06D - 0.01D);
typeof((0.06 - 0.01))
double
spark-sql (default)> select 0.06 - 0.01D; -- support implicitly casting
(0.06 - 0.01)
0.04999999999999999
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.