opensearch-project / opensearch-project/sql

[RFC] Support DECIMAL data type in SQL/PPL

Open
#3,619 1 comment 0 reactions 1 assignee View on GitHub

@LantaoJin is already working on this.

Since Mar 26, 2026.

field types support PPL RFC SQL
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 Decimal type in SQL/PPL
  • Support DecimalLiteral and 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.06D is double literal, 0.06F is float literal, 0.06BD is 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:

  1. Continue as-is.
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.