diff --git a/core/src/main/java/org/apache/calcite/rex/RexCall.java b/core/src/main/java/org/apache/calcite/rex/RexCall.java index 98d352e31d5..40b38d64684 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexCall.java +++ b/core/src/main/java/org/apache/calcite/rex/RexCall.java @@ -57,11 +57,18 @@ public class RexCall extends RexNode { public final ImmutableList operands; public final RelDataType type; + /** + * Simple binary operators are those operators which expects operands from the same Domain. + * + * Example: simple comparisions (=,<) + * Note: it doesn't contain IN because that is defined on D x D^n + */ private static final Set SIMPLE_BINARY_OPS; static { EnumSet kinds = EnumSet.of(SqlKind.PLUS, SqlKind.MINUS, SqlKind.TIMES, SqlKind.DIVIDE); kinds.addAll(SqlKind.COMPARISON); + kinds.remove(SqlKind.IN); SIMPLE_BINARY_OPS = Sets.immutableEnumSet(kinds); } @@ -111,7 +118,7 @@ protected final StringBuilder appendOperands(StringBuilder sb) { && operand.getType().getSqlTypeName() == SqlTypeName.BOOLEAN) { includeType = RexDigestIncludeType.NO_TYPE; } - if (SIMPLE_BINARY_OPS.contains(getKind())) { + if (SIMPLE_BINARY_OPS.contains(getKind()) && operands.size() == 2) { RexNode otherArg = operands.get(1 - i); if ((!(otherArg instanceof RexLiteral) || ((RexLiteral) otherArg).digestIncludesType() == RexDigestIncludeType.NO_TYPE) diff --git a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java index 23045225071..9e4ebf924c6 100644 --- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java +++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java @@ -2546,6 +2546,14 @@ private void checkIs(RexNode e, boolean expected) { private Comparable eval(RexNode e) { return RexInterpreter.evaluate(e, ImmutableMap.of()); } -} + /** Unit test for + * [CALCITE-2842] + * Computing digest of IN expressions leads to Exceptions. */ + @Test public void testInDigest() { + RexNode e = in(vInt(), literal(1), literal(2)); + assertThat(e.toString(), is("IN(?0.int0, 1, 2)")); + } + +} // End RexProgramTest.java