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

[BUG][Calcite Engine] Calcite doesn't support cast decimal to double #3437

Open
qianheng-aws opened this issue Mar 17, 2025 · 2 comments
Open
Labels
bug Something isn't working untriaged

Comments

@qianheng-aws
Copy link
Contributor

What is the bug?
When converting a set of literals to Sarg, calcite will throw exception if there is both type of integer and double, although they are both numeric family

Exception stack:

class java.lang.Double cannot be cast to class java.math.BigDecimal (java.lang.Double and java.math.BigDecimal are in module java.base of loader 'bootstrap')
java.lang.ClassCastException: class java.lang.Double cannot be cast to class java.math.BigDecimal (java.lang.Double and java.math.BigDecimal are in module java.base of loader 'bootstrap')
	at java.base/java.math.BigDecimal.compareTo(BigDecimal.java:305)
	at com.google.common.collect.Range.compareOrThrow(Range.java:702)
	at com.google.common.collect.Cut.compareTo(Cut.java:80)
	at com.google.common.collect.Range.<init>(Range.java:331)
	at com.google.common.collect.Range.create(Range.java:132)
	at com.google.common.collect.Range.closed(Range.java:157)
	at org.apache.calcite.rex.RexBuilder.makeBetween(RexBuilder.java:1805)
	at org.apache.calcite.tools.RelBuilder.between(RelBuilder.java:1153)
	at org.apache.calcite.tools.RelBuilder.call(RelBuilder.java:752)
	at org.apache.calcite.tools.RelBuilder.call(RelBuilder.java:765)
	at org.apache.calcite.tools.RelBuilder.call(RelBuilder.java:736)

@LantaoJin
Copy link
Member

This issue should be fixed in #3433

@qianheng-aws
Copy link
Contributor Author

qianheng-aws commented Mar 17, 2025

This issue should be fixed in #3433

It should work to perform cast from our side as a workaround. But I believe it should be a bug from Calcite. For RexBuilder::makeIn, since RexBuilder::areAssignable returns true, it should be able to transform into a Sarg. Otherwise it should return false and choose to invoke composeDisjunction(which should works as well) instead of throw exception; For RexBuilder::makeBetween, it should choose to build And(a > low, a < upper).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged
Projects
None yet
Development

No branches or pull requests

2 participants