Skip to content

Commit

Permalink
[CALCITE-2842] Computing RexCall digest containing IN expressions lea…
Browse files Browse the repository at this point in the history
…ds to Exceptions

Close apache#1040
  • Loading branch information
kgyrtkirk authored and jcamachor committed Feb 21, 2019
1 parent 9924699 commit 880393e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion core/src/main/java/org/apache/calcite/rex/RexCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,18 @@ public class RexCall extends RexNode {
public final ImmutableList<RexNode> operands;
public final RelDataType type;

/**
* Simple binary operators are those operators which expects operands from the same Domain.
*
* Example: simple comparisions (=,&lt;)
* Note: it doesn't contain IN because that is defined on D x D^n
*/
private static final Set<SqlKind> SIMPLE_BINARY_OPS;

static {
EnumSet<SqlKind> 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);
}

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion core/src/test/java/org/apache/calcite/test/RexProgramTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <a href="https://issues.apache.org/jira/browse/CALCITE-2842">[CALCITE-2842]
* Computing digest of IN expressions leads to Exceptions</a>. */
@Test public void testInDigest() {
RexNode e = in(vInt(), literal(1), literal(2));
assertThat(e.toString(), is("IN(?0.int0, 1, 2)"));
}

}
// End RexProgramTest.java

0 comments on commit 880393e

Please sign in to comment.