Skip to content

Support decimal literal with Calcite #3673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 4, 2025

Conversation

LantaoJin
Copy link
Member

@LantaoJin LantaoJin commented May 26, 2025

Description

Support decimal literal with Calcite

  • Behavior in v2 is no changing.
  • The decimal number, e.g.. 3.0, 2.5 in PPL statement will be treated as a decimal literal unless adding a d(double), f(float) suffix
  • This decimal literal will keep Decimal type in Calcite plan.
  • The decimal literal is present as double in runtime (ExprType)

Related Issues

Resolves #3614

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@@ -166,7 +166,7 @@ void populate() {
registerOperator(ADD, SqlStdOperatorTable.PLUS);
registerOperator(SUBTRACT, SqlStdOperatorTable.MINUS);
registerOperator(MULTIPLY, SqlStdOperatorTable.MULTIPLY);
// registerOperator(DIVIDE, SqlStdOperatorTable.DIVIDE);
registerOperator(TRUNCATE, SqlStdOperatorTable.TRUNCATE);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a missing function which is not related to this PR. But we need it in CalciteMathematicalFunctionIT.java


import org.opensearch.sql.common.setting.Settings;

public class CalcitePPLCryptographicFunctionPushdownIT extends CalcitePPLCryptographicFunctionIT {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing IT which is not related to this issue.

Comment on lines +10 to +11
public class CalcitePPLDateTimeBuiltinFunctionPushdownIT
extends CalcitePPLDateTimeBuiltinFunctionIT {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect inheritance which is not related to this issue.


import org.opensearch.sql.common.setting.Settings;

public class CalcitePPLFillnullPushdownIT extends CalcitePPLFillnullIT {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing IT which is not related to this issue.


import org.opensearch.sql.common.setting.Settings;

public class CalcitePPLIPFunctionPushdownIT extends CalcitePPLIPFunctionIT {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines +43 to +47
if (isCalciteEnabled()) {
verifySchema(result, schema("f", null, "int"));
} else {
verifySchema(result, schema("f", null, "bigint"));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return types between v2 and v3 are different, not related to this issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why dose this IT could pass before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why dose this IT could pass before?

CalciteMathematicalFunctionIT was missing before this PR.

LantaoJin added 4 commits May 27, 2025 11:55
Signed-off-by: Lantao Jin <[email protected]>
Signed-off-by: Lantao Jin <[email protected]>
Signed-off-by: Lantao Jin <[email protected]>
Signed-off-by: Lantao Jin <[email protected]>
@LantaoJin LantaoJin added breaking calcite calcite migration releated labels May 27, 2025
Signed-off-by: Lantao Jin <[email protected]>
public class Literal extends UnresolvedExpression {

private final Object value;
private final DataType type;

public Literal(Object value, DataType dataType) {
if (dataType == DataType.DECIMAL && value instanceof Double) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will we create a decimal literal with double value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to be compatible with calls like new Literal(2.0, Decimal) , otherwise we can only use new Literal(new BigDecimal("2.0"), Decimal)

penghuo

This comment was marked as off-topic.

Copy link
Collaborator

@penghuo penghuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change! One minor suggestion would be to add a small note in the documentation about this change to help users understand the precision behavior, but that could also be addressed separately.

@LantaoJin
Copy link
Member Author

Thanks for the change! One minor suggestion would be to add a small note in the documentation about this change to help users understand the precision behavior, but that could also be addressed separately.

Sure, I will summary the break changes for 3.1.0 release in a new PR.

Copy link
Collaborator

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! Should we also update user manualhttps://github.com/opensearch-project/sql/blob/main/docs/user/ppl/general/datatypes.rst?

@LantaoJin LantaoJin merged commit f1e3b5b into opensearch-project:main Jun 4, 2025
22 checks passed
@LantaoJin
Copy link
Member Author

LantaoJin commented Jun 4, 2025

Thanks for the changes! Should we also update user manualhttps://github.com/opensearch-project/sql/blob/main/docs/user/ppl/general/datatypes.rst?

Decimal is not a new supported datatype, we'd better update that doc after #3619 addressed. I will highlight this breaking changes in release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking calcite calcite migration releated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Numeric literal precision is inconsistent with Spark/MySQL
4 participants