[ 
https://issues.apache.org/jira/browse/CALCITE-6823?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Thomas Rebele updated CALCITE-6823:
-----------------------------------
    Affects Version/s: 1.38.0

> Cannot convert CHAR to Integer when applying SubstitutionVisitor
> ----------------------------------------------------------------
>
>                 Key: CALCITE-6823
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6823
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.38.0
>            Reporter: Thomas Rebele
>            Priority: Major
>
> I've encountered an assertion {{cannot convert CHAR literal to class 
> java.lang.Integer}} with the following test in 
> MaterializedViewSubstitutionVisitorTest:
> {code:java}
>   @Test void testDateFilter() {
>     sql("SELECT HIREDATE FROM EMP WHERE HIREDATE > '1990-10-01'",
>         "SELECT * FROM EMP WHERE HIREDATE > '1990-05-01'")
>         .withDefaultSchemaSpec(SchemaSpec.SCOTT)
>         .noMat();
>   }{code}
> The stacktrace:
> {code:java}
> java.lang.AssertionError: cannot convert CHAR literal to class 
> java.lang.Integer
>     at org.apache.calcite.rex.RexLiteral.getValueAs(RexLiteral.java:1177)
>     at 
> org.apache.calcite.plan.VisitorDataContext.getValue(VisitorDataContext.java:144)
>     at 
> org.apache.calcite.plan.VisitorDataContext.of(VisitorDataContext.java:98)
>     at 
> org.apache.calcite.plan.RexImplicationChecker.implies2(RexImplicationChecker.java:243)
>     at 
> org.apache.calcite.plan.RexImplicationChecker.impliesConjunction(RexImplicationChecker.java:151)
>     at 
> org.apache.calcite.plan.RexImplicationChecker.impliesAny(RexImplicationChecker.java:141)
>     at 
> org.apache.calcite.plan.RexImplicationChecker.implies(RexImplicationChecker.java:127)
>     at 
> org.apache.calcite.plan.SubstitutionVisitor.implies(SubstitutionVisitor.java:1832)
>     at 
> org.apache.calcite.plan.SubstitutionVisitor.access$900(SubstitutionVisitor.java:128)
>     at 
> org.apache.calcite.plan.SubstitutionVisitor$CalcToCalcUnifyRule.apply(SubstitutionVisitor.java:1162)
>     at 
> org.apache.calcite.plan.SubstitutionVisitor.go(SubstitutionVisitor.java:587)
>     at 
> org.apache.calcite.plan.SubstitutionVisitor.go(SubstitutionVisitor.java:521)
>     at 
> org.apache.calcite.test.MaterializedViewSubstitutionVisitorTest$1.optimize(MaterializedViewSubstitutionVisitorTest.java:91)
>     at 
> org.apache.calcite.test.MaterializedViewTester.checkNoMaterialize(MaterializedViewTester.java:94)
>     at 
> org.apache.calcite.test.MaterializedViewFixture.noMat(MaterializedViewFixture.java:60)
>     at 
> org.apache.calcite.test.MaterializedViewSubstitutionVisitorTest.testDateFilter(MaterializedViewSubstitutionVisitorTest.java:117)
>  {code}
> The assertion disappears when adding DATE in front of the literals, e.g., 
> {{{}HIREDATE > DATE '1990-10-01'{}}}.
>  
> Many databases support comparing DATE fields with CHAR literals, e.g., SQLite 
> and Postgres:
> [https://sqlfiddle.com/postgresql/online-compiler?id=70a19e42-4909-4c74-af09-a063cc567021].
>  For Oracle Database the DATE keyword is required, though.
>  
> I would have expected that if Calcite converts SQL queries to RelNode 
> objects, that these RelNode objects can be used for view substitution.
>  
> PS: I've checked with the most recent commit on the main branch, 
> f1c370a0cb57675b6e5a442b3d98e29d75a64043.



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

Reply via email to