You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Maksim Zhuravkov (Jira)" <ji...@apache.org> on 2023/02/15 18:36:00 UTC

[jira] [Created] (CALCITE-5531) Regression in rewriting COALESCE expression.

Maksim Zhuravkov created CALCITE-5531:
-----------------------------------------

             Summary: Regression in rewriting COALESCE expression.
                 Key: CALCITE-5531
                 URL: https://issues.apache.org/jira/browse/CALCITE-5531
             Project: Calcite
          Issue Type: Bug
    Affects Versions: 1.33.0
            Reporter: Maksim Zhuravkov


After updating to calcite 1.33.0, I found that validation of the following query fails with a ClassCastException.

Query: 

{code:java}
SELECT COALESCE(DATE '2021-07-08', DATE '2020-01-01’)
{code}

Error:
{code:java}
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)
{code}

When I move a commit pointer prior to the commit that introduces SqlUnknownLiteral ([CALCITE-5424] Customize handling of literals based on type system), the following test case passes successfully.

The reproducer (added to RexSqlStandardConvertletTableTest):
  
{code:java}
@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());
  }
{code}




--
This message was sent by Atlassian Jira
(v8.20.10#820010)