Skip to content
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

[CALCITE-6684] Arrow adapter should supports filter conditions of Decimal type #4043

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

caicancai
Copy link
Member

@caicancai caicancai commented Nov 10, 2024

@caicancai caicancai changed the title [CALCITE-6684] Arrow adapter should supports filter conditions of Dec… [CALCITE-6684] Arrow adapter should supports filter conditions of Decimal type Nov 10, 2024
@@ -194,6 +194,8 @@ private static TreeNode makeLiteralNode(String literal, String type) {
return TreeBuilder.makeLiteral(parseFloat(literal));
case "double":
return TreeBuilder.makeLiteral(parseDouble(literal));
case "decimal":
return TreeBuilder.makeDecimalLiteral(literal, 19, 0);
Copy link
Member Author

Choose a reason for hiding this comment

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

Comply with Calcite's default Decimal type

Copy link
Contributor

Choose a reason for hiding this comment

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

You should use the type system to retrieve the default type, assuming it is available here.
Maybe there is a default type for Arrow, but the "default" type for Calcite is irrelevant in this context.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no way this can be right, this drops all digits after the decimal point.
At least make 19 and 0 some constants like ARROW_DEFAULT_PRECISION and ARROW_DEFAULT_SCALE.

private static String getLiteralType(Object literal, RelDataType type) {
if (type.getSqlTypeName() == SqlTypeName.DECIMAL) {
return "decimal";
} else if (literal instanceof BigDecimal) {
Copy link
Contributor

Choose a reason for hiding this comment

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

since now you are passing type information to this function you should use it everywhere. There is no reason to guess the type based on the Java type of the literal.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link

sonarcloud bot commented Nov 12, 2024

@@ -194,6 +194,8 @@ private static TreeNode makeLiteralNode(String literal, String type) {
return TreeBuilder.makeLiteral(parseFloat(literal));
case "double":
return TreeBuilder.makeLiteral(parseDouble(literal));
case "decimal":
return TreeBuilder.makeDecimalLiteral(literal, 19, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use the type system to retrieve the default type, assuming it is available here.
Maybe there is a default type for Arrow, but the "default" type for Calcite is irrelevant in this context.

} else if (type.getSqlTypeName() == SqlTypeName.VARCHAR
|| type.getSqlTypeName() == SqlTypeName.CHAR) {
return "string";
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

there are many unhandled cases, but perhaps this is a good start.

Copy link
Member Author

@caicancai caicancai Nov 13, 2024

Choose a reason for hiding this comment

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

@mihaibudiu
Unfortunately, Arrow does not have a default decimal type.
The Arrow adapter currently converts Decimal types to DECIMAL(19, 0) by default. I don't know why the previous person implemented it this way. It seems that he simply called the calcite native API without considering any precision issues.

image So in this pr, the decimal type I specified is also DECIMAL(19, 0)

I am working on a new type system for the Arrow adapter, which seems to be a big project

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

Successfully merging this pull request may close these issues.

2 participants