From dabc326df75bd22823c182a212012c01dc2f8706 Mon Sep 17 00:00:00 2001 From: Ulrich Kramer Date: Tue, 7 May 2024 17:31:18 +0200 Subject: [PATCH] EXPB-2253 CALCITE-6401 JDBC adapter cannot push down joins with complex JOIN condition --- .../calcite/adapter/jdbc/JdbcRules.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java index 8bfedbe47fe..1cf6e9f5802 100644 --- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java +++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java @@ -348,19 +348,19 @@ protected JdbcJoinRule(Config config) { private static boolean canJoinOnCondition(RexNode node) { final List operands; switch (node.getKind()) { + case NOT: + case IS_NULL: + case IS_NOT_NULL: + case IS_FALSE: + case IS_NOT_FALSE: + case IS_TRUE: + case IS_NOT_TRUE: + case INPUT_REF: case LITERAL: // literal on a join condition would be TRUE or FALSE return true; case AND: case OR: - operands = ((RexCall) node).getOperands(); - for (RexNode operand : operands) { - if (!canJoinOnCondition(operand)) { - return false; - } - } - return true; - case EQUALS: case IS_NOT_DISTINCT_FROM: case NOT_EQUALS: @@ -369,12 +369,12 @@ private static boolean canJoinOnCondition(RexNode node) { case LESS_THAN: case LESS_THAN_OR_EQUAL: operands = ((RexCall) node).getOperands(); - if ((operands.get(0) instanceof RexInputRef) - && (operands.get(1) instanceof RexInputRef)) { - return true; + for (RexNode operand : operands) { + if (!canJoinOnCondition(operand)) { + return false; + } } - // fall through - + return true; default: return false; }