[ https://issues.apache.org/jira/browse/CALCITE-2605?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16676504#comment-16676504 ]
Ruben Quesada Lopez commented on CALCITE-2605: ---------------------------------------------- [~vladimirsitnikov], sorry, but I think I missed an error in [https://github.com/apache/calcite/pull/901/] The if block selector requires also {{rightResult.physType}}, otherwise the dynamically generated code (for EnumerableDefaults#correlateJoin, resultSelector parameter) will not compile, see the error in [https://github.com/apache/calcite/pull/884] To sum up, it should not be: {code:java} Expression selector; if (joinType.returnsJustFirstInput()) { // SEMI, ANTI selector = EnumUtils.joinSelector(JoinRelType.INNER, physType, ImmutableList.of(leftResult.physType)); } else { // INNER, LEFT selector = EnumUtils.joinSelector(joinType.toJoinType(), physType, ImmutableList.of(leftResult.physType, rightResult.physType)); } {code} but: {code:java} Expression selector; if (joinType.returnsJustFirstInput()) { // SEMI, ANTI selector = EnumUtils.joinSelector(JoinRelType.INNER, physType, ImmutableList.of(leftResult.physType, rightResult.physType)); // <-- CHANGE HERE } else { // INNER, LEFT selector = EnumUtils.joinSelector(joinType.toJoinType(), physType, ImmutableList.of(leftResult.physType, rightResult.physType)); } {code} > NullPointerException when left outer join implemented with EnumerableCorrelate > ------------------------------------------------------------------------------ > > Key: CALCITE-2605 > URL: https://issues.apache.org/jira/browse/CALCITE-2605 > Project: Calcite > Issue Type: Bug > Affects Versions: 1.17.0 > Reporter: Ruben Quesada Lopez > Assignee: Julian Hyde > Priority: Major > Fix For: 1.18.0 > > > In the context of a LEFT OUTER JOIN implemented via EnumerableCorrelate, the > generated code for the selector does not check if the right object is null > (which can be, since it is a LEFT join). This situation can lead to a > NullPointerException. > The root cause is located in EnumerableCorrelate::implement method, which > builds the selector expression using a ternary operator whose "if" and "else" > statements are switched: > {code:java} > Expression selector = > EnumUtils.joinSelector( > joinType.returnsJustFirstInput() ? joinType.toJoinType() > : JoinRelType.INNER, physType, > ImmutableList.of(leftResult.physType, rightResult.physType)); > {code} > This code works (by coincidence) in the case of an INNER join; but in case of > LEFT, it will incorrectly call EnumUtils.joinSelector(...) with > JoinRelType.INNER instead of JoinRelType.LEFT, which will produce the > problematic generated code. Also, the current code in the context of a SEMI > or ANTI join will throw an IllegalStateException when calling > SemiJoinType::toJoinType. > If I am not mistaken, to fix this we just need to switch the ternary operator > statements: > {code:java} > Expression selector = > EnumUtils.joinSelector( > joinType.returnsJustFirstInput() ? JoinRelType.INNER > : joinType.toJoinType(), physType, > ImmutableList.of(leftResult.physType, rightResult.physType)); > {code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)