You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Wang Yanlin (Jira)" <ji...@apache.org> on 2019/10/15 08:56:00 UTC

[jira] [Updated] (CALCITE-3413) AssertionError for interpertering union/intersect/minus with null value

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

Wang Yanlin updated CALCITE-3413:
---------------------------------
    Issue Type: Bug  (was: New Feature)

> AssertionError for interpertering union/intersect/minus with null value
> -----------------------------------------------------------------------
>
>                 Key: CALCITE-3413
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3413
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Wang Yanlin
>            Priority: Major
>
> Add the following test case in *InterpreterTest*
> {code:java}
> @Test public void testInterpretUnionWithNullValue() throws Exception {
>     final String sql = "select * from\n"
>         + "(select x, y from (values (cast(NULL as int), cast(NULL as varchar(1))),\n"
>         + "(cast(NULL as int), cast(NULL as varchar(1)))) as t(x, y))\n"
>         + "union\n"
>         + "(select x, y from (values (cast(NULL as int), cast(NULL as varchar(1)))) as t2(x, y))\n";
>     SqlNode validate = planner.validate(planner.parse(sql));
>     RelNode convert = planner.rel(validate).rel;
>     final Interpreter interpreter = new Interpreter(dataContext, convert);
>     assertRows(interpreter, "[null, null]");
>   }
>   @Test public void testInterpretUnionAllWithNullValue() throws Exception {
>     final String sql = "select * from\n"
>         + "(select x, y from (values (cast(NULL as int), cast(NULL as varchar(1))),\n"
>         + "(cast(NULL as int), cast(NULL as varchar(1)))) as t(x, y))\n"
>         + "union all\n"
>         + "(select x, y from (values (cast(NULL as int), cast(NULL as varchar(1)))) as t2(x, y))\n";
>     SqlNode validate = planner.validate(planner.parse(sql));
>     RelNode convert = planner.rel(validate).rel;
>     final Interpreter interpreter = new Interpreter(dataContext, convert);
>     assertRows(interpreter, "[null, null]", "[null, null]", "[null, null]");
>   }
> {code}
> got
> {code:java}
> java.lang.AssertionError
> 	at org.apache.calcite.interpreter.Interpreter$CompilerImpl.source(Interpreter.java:510)
> 	at org.apache.calcite.interpreter.Nodes$CoreCompiler.source(Nodes.java:46)
> 	at org.apache.calcite.interpreter.AbstractSingleNode.<init>(AbstractSingleNode.java:33)
> 	at org.apache.calcite.interpreter.ProjectNode.<init>(ProjectNode.java:31)
> 	at org.apache.calcite.interpreter.Nodes$CoreCompiler.visit(Nodes.java:60)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:498)
> 	at org.apache.calcite.util.ReflectUtil.invokeVisitorInternal(ReflectUtil.java:257)
> 	at org.apache.calcite.util.ReflectUtil.invokeVisitor(ReflectUtil.java:214)
> 	at org.apache.calcite.util.ReflectUtil$1.invokeVisitor(ReflectUtil.java:464)
> 	at org.apache.calcite.interpreter.Interpreter$CompilerImpl.visit(Interpreter.java:451)
> 	at org.apache.calcite.interpreter.Nodes$CoreCompiler.visit(Nodes.java:46)
> 	at org.apache.calcite.rel.AbstractRelNode.childrenAccept(AbstractRelNode.java:265)
> 	at org.apache.calcite.interpreter.Interpreter$CompilerImpl.visit(Interpreter.java:447)
> 	at org.apache.calcite.interpreter.Nodes$CoreCompiler.visit(Nodes.java:46)
> 	at org.apache.calcite.interpreter.Interpreter$CompilerImpl.visitRoot(Interpreter.java:405)
> 	at org.apache.calcite.interpreter.Interpreter.<init>(Interpreter.java:88)
> 	at org.apache.calcite.test.InterpreterTest.testInterpretMinusWithNullValue(InterpreterTest.java:418)
> {code}
> The cause lies in the optimize of [Interpreter|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java#L85]
> before optimize, the relnode tree is as follows, no renode with same id exists
> {code:java}
> LogicalUnion(all=[false]), id = 19
>   LogicalProject(X=[$0], Y=[$1]), id = 16
>     LogicalUnion(all=[true]), id = 15
>       LogicalProject(EXPR$0=[null:INTEGER], EXPR$1=[null:VARCHAR(1)]), id = 12
>         LogicalValues(tuples=[[{ 0 }]]), id = 11
>       LogicalProject(EXPR$0=[null:INTEGER], EXPR$1=[null:VARCHAR(1)]), id = 14
>         LogicalValues(tuples=[[{ 0 }]]), id = 13
>   LogicalProject(X=[null:INTEGER], Y=[null:VARCHAR(1)]), id = 18
>     LogicalValues(tuples=[[{ 0 }]]), id = 17
> {code}
> after optimize, the relnode tree is as follows,
> {code:java}
> LogicalUnion(all=[false]), id = 30
>   LogicalProject(X=[$0], Y=[$1]), id = 26
>     LogicalUnion(all=[true]), id = 24
>       LogicalProject(EXPR$0=[null:INTEGER], EXPR$1=[null:VARCHAR(1)]), id = 21
>         LogicalValues(tuples=[[{ 0 }]]), id = 11
>       LogicalProject(EXPR$0=[null:INTEGER], EXPR$1=[null:VARCHAR(1)]), id = 21
>         LogicalValues(tuples=[[{ 0 }]]), id = 11
>   LogicalProject(X=[null:INTEGER], Y=[null:VARCHAR(1)]), id = 28
>     LogicalValues(tuples=[[{ 0 }]]), id = 11
> {code}
> there exists relnodes with same id, thus breaking the inner structure of [CompilerImpl|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java#L381]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)