Zhen Chen created CALCITE-7400:
----------------------------------

             Summary: PruneJoinSingleValue rule causes type mismatch in IN
                 Key: CALCITE-7400
                 URL: https://issues.apache.org/jira/browse/CALCITE-7400
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.41.0
            Reporter: Zhen Chen
            Assignee: Zhen Chen
             Fix For: 1.42.0


Using CoreQuidemTest2 to test the following SQL will result in an error.
{code:java}
select 1 in (values(null), (null));
+--------+
| EXPR$0 |
+--------+
|        |
+--------+
(1 row)

!ok {code}
Error message:

> Caused by: java.lang.RuntimeException: Error occurred while applying rule 
> PruneJoinSingleValueRule(left)
>     at 
> org.apache.calcite.plan.volcano.VolcanoRuleCall.transformTo(VolcanoRuleCall.java:157)
>     at 
> org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:273)
>     at 
> org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:288)
>     at 
> org.apache.calcite.rel.rules.SingleValuesOptimizationRules$PruneSingleValueRule.onMatch(SingleValuesOptimizationRules.java:276)
>     at 
> org.apache.calcite.rel.rules.SingleValuesOptimizationRules$JoinLeftSingleRuleConfig$1.onMatch(SingleValuesOptimizationRules.java:343)
>     at 
> org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:223)
>     ... 24 more
> Caused by: java.lang.IllegalArgumentException: Type mismatch:
> rel rowtype: RecordType(BOOLEAN $f0, INTEGER EXPR$0) NOT NULL
> equiv rowtype: RecordType(INTEGER NOT NULL ZERO, BOOLEAN markCol) NOT NULL
> Difference:
> $f0: BOOLEAN -> INTEGER NOT NULL
> EXPR$0: INTEGER -> BOOLEAN

 

The plan before PruneJoinSingleValueRule(left) processing is as follows.
{code:java}
LogicalProject(EXPR$0=[$1])
  LogicalJoin(condition=[=(1, $1)], joinType=[left_mark])
    LogicalValues(tuples=[[{ 0 }]])
    LogicalValues(tuples=[[{ null }, { null }]]) {code}
I believe we should prohibit this scenario. To remove JOIN, we would need to 
add operators like AGG to the right child for more complex processing, and it's 
uncertain whether this would increase costs.



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

Reply via email to