[ 
https://issues.apache.org/jira/browse/CALCITE-2080?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16286709#comment-16286709
 ] 

Julian Hyde commented on CALCITE-2080:
--------------------------------------

Tightening constraints (such as when I added {{assert 
!RexUtil.isNullabilityCast}} to the {{Filter}} constructor) is always a 
double-edged sword. It makes life harder for those upstream (who must obey the 
constraint), and easier for those downstream (who can rely on the constraint 
holding). I should have fixed every place that creates a {{Filter}}, and I 
missed one. (Sadly, there may be more. But I am heartened that your case only 
showed up when the ANY type was involved.)

These days, more and more code uses {{RelBuilder.filter}} to create 
{{Filter}}s, and this removes nullability casts automatically. I wasn't able to 
use {{RelBuilder.filter}} here, because it performs so many optimizations that 
some tests were breaking.

> Query with NOT IN operator and literal fails with error 
> java.lang.AssertionError: Cast for just nullability not allowed
> -----------------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-2080
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2080
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Volodymyr Vysotskyi
>            Assignee: Julian Hyde
>             Fix For: 1.16.0
>
>
> This test
> {code:java}
>   @Test
>   public void testNotInWithLiteral() {
>     final String sql = "SELECT *\n"
>         + "FROM SALES.NATION\n"
>         + "WHERE n_name NOT IN\n"
>         + "    (SELECT ''\n"
>         + "     FROM SALES.NATION)";
>     sql(sql).with(getTesterWithDynamicTable()).ok();
>   }
> {code}
> fails with error:
> {noformat}
> java.lang.AssertionError: Cast for just nullability not allowed
>       at org.apache.calcite.util.Litmus$1.fail(Litmus.java:31)
>       at org.apache.calcite.rel.core.Filter.isValid(Filter.java:116)
>       at 
> org.apache.calcite.test.SqlToRelConverterTest$RelValidityChecker.visit(SqlToRelConverterTest.java:2753)
>       at org.apache.calcite.rel.SingleRel.childrenAccept(SingleRel.java:72)
>       at org.apache.calcite.rel.RelVisitor.visit(RelVisitor.java:44)
>       at 
> org.apache.calcite.test.SqlToRelConverterTest$RelValidityChecker.visit(SqlToRelConverterTest.java:2756)
>       at org.apache.calcite.rel.RelVisitor.go(RelVisitor.java:61)
>       at 
> org.apache.calcite.test.SqlToRelTestBase.assertValid(SqlToRelTestBase.java:129)
>       at 
> org.apache.calcite.test.SqlToRelTestBase$TesterImpl.assertConvertsTo(SqlToRelTestBase.java:693)
>       at 
> org.apache.calcite.test.SqlToRelConverterTest$Sql.convertsTo(SqlToRelConverterTest.java:2790)
>       at 
> org.apache.calcite.test.SqlToRelConverterTest$Sql.ok(SqlToRelConverterTest.java:2786)
>       at 
> org.apache.calcite.test.SqlToRelConverterTest.testNotInWithLiteral(SqlToRelConverterTest.java:1299)
> {noformat}
> In [this 
> line|https://github.com/apache/calcite/blob/c7d9b3d561243c3cb97595f4fe9a0ccf05ce85ac/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java#L4502]
>  cast which just changes types nullability was made. The ending type is taken 
> form validator and it [was made 
> nullable|https://github.com/apache/calcite/blob/f47465236b7650f2280092b708fa39062fe79ffd/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java#L163]
>  because right operand has a nullable type.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to