Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.33.0
-
None
-
None
Description
A call to the COALESCE function throws ClassCastException. This is a regression caused by CALCITE-5424.
After updating to calcite 1.33.0, I found that validation of the following query fails with a ClassCastException. Query:
SELECT COALESCE(DATE '2021-07-08', DATE '2020-01-01’)
Error:
org.apache.calcite.tools.ValidationException: java.lang.ClassCastException: class org.apache.calcite.sql.SqlLiteral cannot be cast to class org.apache.calcite.sql.SqlUnknownLiteral (org.apache.calcite.sql.SqlLiteral and org.apache.calcite.sql.SqlUnknownLiteral are in unnamed module of loader 'app') at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:226) at org.apache.calcite.rex.RexSqlStandardConvertletTableTest.convertSqlToRel(RexSqlStandardConvertletTableTest.java:101) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) Caused by: java.lang.ClassCastException: class org.apache.calcite.sql.SqlLiteral cannot be cast to class org.apache.calcite.sql.SqlUnknownLiteral (org.apache.calcite.sql.SqlLiteral and org.apache.calcite.sql.SqlUnknownLiteral are in unnamed module of loader 'app') at org.apache.calcite.sql.validate.SqlValidatorImpl.resolveLiteral(SqlValidatorImpl.java:6152) at org.apache.calcite.sql.validate.SqlValidatorImpl$Expander.visit(SqlValidatorImpl.java:6617) at org.apache.calcite.sql.validate.SqlValidatorImpl$Expander.visit(SqlValidatorImpl.java:6590)
When I move a commit pointer prior to the commit that introduces SqlUnknownLiteral, CALCITE-5424, the following test case passes successfully.
The reproducer (added to RexSqlStandardConvertletTableTest):
@Test void testCoalesceWithUnknownLiteral() { final Project project = (Project) convertSqlToRel( "SELECT COALESCE(DATE '2021-07-08', DATE '2020-01-01')", false); final RexNode rex = project.getProjects().get(0); final RexToSqlNodeConverter rexToSqlNodeConverter = rexToSqlNodeConverter(); final SqlNode convertedSql = rexToSqlNodeConverter.convertNode(rex); assertEquals( "CASE WHEN DATE '2021-07-08' IS NOT NULL THEN DATE '2021-07-08' ELSE DATE '2020-01-01' END", convertedSql.toString()); }
Attachments
Issue Links
- blocks
-
IGNITE-18752 Sql. Bump calcite version to 1.34.0
- Resolved
- is caused by
-
CALCITE-5424 Customize handling of literals based on type system
- Closed