[CALCITE-2494] RexFieldAccess should implement equals/hashCode
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/6b2b9ffd Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/6b2b9ffd Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/6b2b9ffd Branch: refs/heads/master Commit: 6b2b9ffd7e620696e7e7cf34e38641d1817f0fd9 Parents: 9f7e565 Author: Vladimir Sitnikov <[email protected]> Authored: Tue Aug 28 12:29:18 2018 +0300 Committer: Vladimir Sitnikov <[email protected]> Committed: Tue Aug 28 15:06:33 2018 +0300 ---------------------------------------------------------------------- .../org/apache/calcite/rex/RexFieldAccess.java | 19 +++++++++++++++++++ .../org/apache/calcite/test/RexProgramTest.java | 13 +++++++++++++ 2 files changed, 32 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/6b2b9ffd/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java b/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java index cf731d2..6de5548 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java +++ b/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java @@ -91,6 +91,25 @@ public class RexFieldAccess extends RexNode { public RexNode getReferenceExpr() { return expr; } + + @Override public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + RexFieldAccess that = (RexFieldAccess) o; + + return field.equals(that.field) && expr.equals(that.expr); + } + + @Override public int hashCode() { + int result = expr.hashCode(); + result = 31 * result + field.hashCode(); + return result; + } } // End RexFieldAccess.java http://git-wip-us.apache.org/repos/asf/calcite/blob/6b2b9ffd/core/src/test/java/org/apache/calcite/test/RexProgramTest.java ---------------------------------------------------------------------- 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 990afb6..25c99e5 100644 --- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java +++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java @@ -70,6 +70,8 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertThat; /** @@ -1559,6 +1561,17 @@ public class RexProgramTest extends RexProgramBuilderBase { "false"); } + @Test public void fieldAccessEqualsHashCode() { + assertEquals("vBool() instances should be equal", vBool(), vBool()); + assertEquals("vBool().hashCode()", vBool().hashCode(), vBool().hashCode()); + assertNotSame("vBool() is expected to produce new RexFieldAccess", vBool(), vBool()); + assertNotEquals("vBool(0) != vBool(1)", vBool(0), vBool(1)); + } + + @Test public void testSimplifyDynamicParam() { + checkSimplify2(or(vBool(), vBool()), "?0.bool0", "?0.bool0"); + } + /** Unit test for * <a href="https://issues.apache.org/jira/browse/CALCITE-1289">[CALCITE-1289] * RexUtil.simplifyCase() should account for nullability</a>. */
