diff --git a/core/trino-spi/src/main/java/io/trino/spi/predicate/SortedRangeSet.java b/core/trino-spi/src/main/java/io/trino/spi/predicate/SortedRangeSet.java index e88a78511cc8..6c09ec3e8532 100644 --- a/core/trino-spi/src/main/java/io/trino/spi/predicate/SortedRangeSet.java +++ b/core/trino-spi/src/main/java/io/trino/spi/predicate/SortedRangeSet.java @@ -817,8 +817,9 @@ public int hashCode() if (hash == 0) { hash = Objects.hash(type, Arrays.hashCode(inclusive)); for (int position = 0; position < sortedRanges.getPositionCount(); position++) { - if (sortedRanges.isNull(position)) { - hash = hash * 31; + boolean positionIsNull = sortedRanges.isNull(position); + hash = hash * 31 + Boolean.hashCode(positionIsNull); + if (positionIsNull) { continue; } try { diff --git a/core/trino-spi/src/test/java/io/trino/spi/predicate/TestSortedRangeSet.java b/core/trino-spi/src/test/java/io/trino/spi/predicate/TestSortedRangeSet.java index 68925d8728ef..b9bc9a288a9c 100644 --- a/core/trino-spi/src/test/java/io/trino/spi/predicate/TestSortedRangeSet.java +++ b/core/trino-spi/src/test/java/io/trino/spi/predicate/TestSortedRangeSet.java @@ -731,6 +731,13 @@ public void testExpandRangesForDenseType() } } + @Test + public void testRangeSetHashcode() + { + assertThat(ValueSet.ofRanges(Range.lessThan(INTEGER, 0L)).hashCode()).isNotEqualTo(ValueSet.ofRanges(Range.greaterThan(INTEGER, 0L)).hashCode()); + assertThat(ValueSet.ofRanges(Range.lessThan(INTEGER, 1L)).hashCode()).isNotEqualTo(ValueSet.ofRanges(Range.range(INTEGER, 0L, false, 1L, false)).hashCode()); + } + private void assertUnion(SortedRangeSet first, SortedRangeSet second, SortedRangeSet expected) { assertThat(first.union(second)).isEqualTo(expected);