diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/AbstractMapBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/AbstractMapBlock.java index 2fc54e01fb65b..aeade5a5ef889 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/AbstractMapBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/AbstractMapBlock.java @@ -21,6 +21,7 @@ import java.lang.invoke.MethodHandle; import java.util.Arrays; +import java.util.Objects; import java.util.Optional; import static com.facebook.presto.common.block.BlockUtil.appendNullToIsNullArray; @@ -468,6 +469,26 @@ public void loadHashTables(int positionCount, int[] offsets, boolean[] mapIsNull } set(hashTables); } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + HashTables other = (HashTables) obj; + return Arrays.equals(this.hashTables, other.hashTables) && + Objects.equals(this.expectedHashTableCount, other.expectedHashTableCount); + } + + @Override + public int hashCode() + { + return Objects.hash(Arrays.hashCode(hashTables), expectedHashTableCount); + } } @Override diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/ArrayBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/ArrayBlock.java index 445abe681b5db..66392a579a769 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/ArrayBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/ArrayBlock.java @@ -17,6 +17,8 @@ import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.Objects; import java.util.Optional; import java.util.function.BiConsumer; @@ -223,4 +225,37 @@ public Block getSingleValueBlock(int position) return getSingleValueBlockInternal(position); } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + ArrayBlock other = (ArrayBlock) obj; + return Objects.equals(this.arrayOffset, other.arrayOffset) && + Objects.equals(this.positionCount, other.positionCount) && + Arrays.equals(this.valueIsNull, other.valueIsNull) && + Objects.equals(this.values, other.values) && + Arrays.equals(this.offsets, other.offsets) && + Objects.equals(this.sizeInBytes, other.sizeInBytes) && + Objects.equals(this.logicalSizeInBytes, other.logicalSizeInBytes) && + Objects.equals(this.retainedSizeInBytes, other.retainedSizeInBytes); + } + + @Override + public int hashCode() + { + return Objects.hash(arrayOffset, + positionCount, + Arrays.hashCode(valueIsNull), + values, + Arrays.hashCode(offsets), + sizeInBytes, + logicalSizeInBytes, + retainedSizeInBytes); + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/ByteArrayBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/ByteArrayBlock.java index 1b3834a69b4f0..89b5074b3f623 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/ByteArrayBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/ByteArrayBlock.java @@ -18,6 +18,8 @@ import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.Objects; import java.util.Optional; import java.util.function.BiConsumer; @@ -264,4 +266,33 @@ public Block appendNull() return new ByteArrayBlock(arrayOffset, positionCount + 1, newValueIsNull, newValues); } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + ByteArrayBlock other = (ByteArrayBlock) obj; + return Objects.equals(this.arrayOffset, other.arrayOffset) && + Objects.equals(this.positionCount, other.positionCount) && + Arrays.equals(this.valueIsNull, other.valueIsNull) && + Arrays.equals(this.values, other.values) && + Objects.equals(this.sizeInBytes, other.sizeInBytes) && + Objects.equals(this.retainedSizeInBytes, other.retainedSizeInBytes); + } + + @Override + public int hashCode() + { + return Objects.hash(arrayOffset, + positionCount, + Arrays.hashCode(valueIsNull), + Arrays.hashCode(values), + sizeInBytes, + retainedSizeInBytes); + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/DictionaryBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/DictionaryBlock.java index d405610f20ee1..5e671a1be5f30 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/DictionaryBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/DictionaryBlock.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.function.BiConsumer; import static com.facebook.presto.common.block.BlockUtil.checkArrayRange; @@ -608,4 +609,39 @@ public Block appendNull() return new DictionaryBlock(idsOffset, positionCount + 1, newDictionary, newIds, isCompact(), getDictionarySourceId()); } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + DictionaryBlock other = (DictionaryBlock) obj; + return Objects.equals(this.positionCount, other.positionCount) && + Objects.equals(this.dictionary, other.dictionary) && + Objects.equals(this.idsOffset, other.idsOffset) && + Arrays.equals(this.ids, other.ids) && + Objects.equals(this.retainedSizeInBytes, other.retainedSizeInBytes) && + Objects.equals(this.sizeInBytes, other.sizeInBytes) && + Objects.equals(this.logicalSizeInBytes, other.logicalSizeInBytes) && + Objects.equals(this.uniqueIds, other.uniqueIds) && + Objects.equals(this.dictionarySourceId, other.dictionarySourceId); + } + + @Override + public int hashCode() + { + return Objects.hash(positionCount, + dictionary, + idsOffset, + Arrays.hashCode(ids), + retainedSizeInBytes, + sizeInBytes, + logicalSizeInBytes, + uniqueIds, + dictionarySourceId); + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlock.java index 16fa7fcbc7aa3..c577f6773eb55 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlock.java @@ -20,6 +20,8 @@ import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.Objects; import java.util.Optional; import java.util.function.BiConsumer; @@ -359,4 +361,33 @@ public Block appendNull() long[] newValues = ensureCapacity(values, (positionOffset + positionCount + 1) * 2); return new Int128ArrayBlock(positionOffset, positionCount + 1, newValueIsNull, newValues); } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + Int128ArrayBlock other = (Int128ArrayBlock) obj; + return Objects.equals(this.positionOffset, other.positionOffset) && + Objects.equals(this.positionCount, other.positionCount) && + Arrays.equals(this.valueIsNull, other.valueIsNull) && + Arrays.equals(this.values, other.values) && + Objects.equals(this.sizeInBytes, other.sizeInBytes) && + Objects.equals(this.retainedSizeInBytes, other.retainedSizeInBytes); + } + + @Override + public int hashCode() + { + return Objects.hash(positionOffset, + positionCount, + Arrays.hashCode(valueIsNull), + Arrays.hashCode(values), + sizeInBytes, + retainedSizeInBytes); + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/LongArrayBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/LongArrayBlock.java index 092748eb25f9f..affee152a2716 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/LongArrayBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/LongArrayBlock.java @@ -18,6 +18,8 @@ import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.Objects; import java.util.Optional; import java.util.function.BiConsumer; @@ -302,4 +304,33 @@ public Block appendNull() return new LongArrayBlock(arrayOffset, positionCount + 1, newValueIsNull, newValues); } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + LongArrayBlock other = (LongArrayBlock) obj; + return Objects.equals(this.arrayOffset, other.arrayOffset) && + Objects.equals(this.positionCount, other.positionCount) && + Arrays.equals(this.valueIsNull, other.valueIsNull) && + Arrays.equals(this.values, other.values) && + Objects.equals(this.sizeInBytes, other.sizeInBytes) && + Objects.equals(this.retainedSizeInBytes, other.retainedSizeInBytes); + } + + @Override + public int hashCode() + { + return Objects.hash(arrayOffset, + positionCount, + Arrays.hashCode(valueIsNull), + Arrays.hashCode(values), + sizeInBytes, + retainedSizeInBytes); + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/MapBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/MapBlock.java index 48182c6999f38..afde82361bd78 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/MapBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/MapBlock.java @@ -19,6 +19,8 @@ import javax.annotation.Nullable; import java.lang.invoke.MethodHandle; +import java.util.Arrays; +import java.util.Objects; import java.util.Optional; import java.util.function.BiConsumer; @@ -300,4 +302,39 @@ protected void ensureHashTableLoaded(MethodHandle keyBlockHashCode) } } } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + MapBlock other = (MapBlock) obj; + return Objects.equals(this.startOffset, other.startOffset) && + Objects.equals(this.positionCount, other.positionCount) && + Arrays.equals(this.mapIsNull, other.mapIsNull) && + Arrays.equals(this.offsets, other.offsets) && + Objects.equals(this.keyBlock, other.keyBlock) && + Objects.equals(this.valueBlock, other.valueBlock) && + Objects.equals(this.hashTables, other.hashTables) && + Objects.equals(this.retainedSizeInBytesExceptHashtable, other.retainedSizeInBytesExceptHashtable) && + Objects.equals(this.sizeInBytes, other.sizeInBytes); + } + + @Override + public int hashCode() + { + return Objects.hash(startOffset, + positionCount, + Arrays.hashCode(mapIsNull), + Arrays.hashCode(offsets), + keyBlock, + valueBlock, + hashTables, + retainedSizeInBytesExceptHashtable, + sizeInBytes); + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/RowBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/RowBlock.java index 2be65924fc8c2..26dc14722a04f 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/RowBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/RowBlock.java @@ -17,6 +17,8 @@ import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.Objects; import java.util.Optional; import java.util.function.BiConsumer; @@ -240,4 +242,37 @@ public Block getLoadedBlock() fieldBlockOffsets, loadedFieldBlocks); } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + RowBlock other = (RowBlock) obj; + return Objects.equals(this.startOffset, other.startOffset) && + Objects.equals(this.positionCount, other.positionCount) && + Arrays.equals(this.rowIsNull, other.rowIsNull) && + Arrays.equals(this.fieldBlockOffsets, other.fieldBlockOffsets) && + Arrays.equals(this.fieldBlocks, other.fieldBlocks) && + Objects.equals(this.sizeInBytes, other.sizeInBytes) && + Objects.equals(this.logicalSizeInBytes, other.logicalSizeInBytes) && + Objects.equals(this.retainedSizeInBytes, other.retainedSizeInBytes); + } + + @Override + public int hashCode() + { + return Objects.hash(startOffset, + positionCount, + Arrays.hashCode(rowIsNull), + Arrays.hashCode(fieldBlockOffsets), + Arrays.hashCode(fieldBlocks), + sizeInBytes, + logicalSizeInBytes, + retainedSizeInBytes); + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/RunLengthEncodedBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/RunLengthEncodedBlock.java index f9e72f48fcf8f..bcc80bce30575 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/RunLengthEncodedBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/RunLengthEncodedBlock.java @@ -19,6 +19,7 @@ import io.airlift.slice.SliceOutput; import org.openjdk.jol.info.ClassLayout; +import java.util.Objects; import java.util.function.BiConsumer; import static com.facebook.presto.common.block.BlockUtil.checkArrayRange; @@ -411,4 +412,24 @@ public Block appendNull() return new DictionaryBlock(dictionary, ids); } } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + RunLengthEncodedBlock other = (RunLengthEncodedBlock) obj; + return Objects.equals(this.value, other.value) && + Objects.equals(this.positionCount, other.positionCount); + } + + @Override + public int hashCode() + { + return Objects.hash(value, positionCount); + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/ShortArrayBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/ShortArrayBlock.java index f5fdcb6a80a7c..ee38aa1be09d6 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/ShortArrayBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/ShortArrayBlock.java @@ -18,6 +18,8 @@ import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.Objects; import java.util.Optional; import java.util.function.BiConsumer; @@ -263,4 +265,33 @@ public Block appendNull() short[] newValues = ensureCapacity(values, arrayOffset + positionCount + 1); return new ShortArrayBlock(arrayOffset, positionCount + 1, newValueIsNull, newValues); } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + ShortArrayBlock other = (ShortArrayBlock) obj; + return Objects.equals(this.arrayOffset, other.arrayOffset) && + Objects.equals(this.positionCount, other.positionCount) && + Arrays.equals(this.valueIsNull, other.valueIsNull) && + Arrays.equals(this.values, other.values) && + Objects.equals(this.sizeInBytes, other.sizeInBytes) && + Objects.equals(this.retainedSizeInBytes, other.retainedSizeInBytes); + } + + @Override + public int hashCode() + { + return Objects.hash(arrayOffset, + positionCount, + Arrays.hashCode(valueIsNull), + Arrays.hashCode(values), + sizeInBytes, + retainedSizeInBytes); + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/SingleMapBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/SingleMapBlock.java index b358d87460d01..aadd179ddcf85 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/SingleMapBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/SingleMapBlock.java @@ -22,6 +22,7 @@ import javax.annotation.Nullable; import java.lang.invoke.MethodHandle; +import java.util.Objects; import java.util.function.BiConsumer; import static com.facebook.presto.common.block.AbstractMapBlock.HASH_MULTIPLIER; @@ -451,4 +452,29 @@ private static void checkNotIndeterminate(Boolean equalsResult) throw new NotSupportedException("map key cannot be null or contain nulls"); } } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + SingleMapBlock other = (SingleMapBlock) obj; + return Objects.equals(this.positionInMap, other.positionInMap) && + Objects.equals(this.offset, other.offset) && + Objects.equals(this.positionCount, other.positionCount) && + Objects.equals(this.mapBlock, other.mapBlock); + } + + @Override + public int hashCode() + { + return Objects.hash(positionInMap, + offset, + positionCount, + mapBlock); + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/SingleRowBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/SingleRowBlock.java index c8e368ac6307c..d5e6ded27c262 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/SingleRowBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/SingleRowBlock.java @@ -16,6 +16,7 @@ import org.openjdk.jol.info.ClassLayout; +import java.util.Arrays; import java.util.function.BiConsumer; import static java.lang.String.format; @@ -120,4 +121,23 @@ public Block appendNull() { throw new UnsupportedOperationException("SingleRowBlock does not support appendNull()"); } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + SingleRowBlock other = (SingleRowBlock) obj; + return Arrays.equals(this.fieldBlocks, other.fieldBlocks); + } + + @Override + public int hashCode() + { + return Arrays.hashCode(fieldBlocks); + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/block/VariableWidthBlock.java b/presto-common/src/main/java/com/facebook/presto/common/block/VariableWidthBlock.java index 855c8cf840e4a..6c6a9fb2ddf16 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/block/VariableWidthBlock.java +++ b/presto-common/src/main/java/com/facebook/presto/common/block/VariableWidthBlock.java @@ -21,6 +21,8 @@ import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.Objects; import java.util.Optional; import java.util.function.BiConsumer; @@ -295,4 +297,35 @@ public Block appendNull() return new VariableWidthBlock(arrayOffset, positionCount + 1, slice, newOffsets, newValueIsNull); } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + VariableWidthBlock other = (VariableWidthBlock) obj; + return Objects.equals(this.arrayOffset, other.arrayOffset) && + Objects.equals(this.positionCount, other.positionCount) && + Objects.equals(this.slice, other.slice) && + Arrays.equals(this.offsets, other.offsets) && + Arrays.equals(this.valueIsNull, other.valueIsNull) && + Objects.equals(this.retainedSizeInBytes, other.retainedSizeInBytes) && + Objects.equals(this.sizeInBytes, other.sizeInBytes); + } + + @Override + public int hashCode() + { + return Objects.hash(arrayOffset, + positionCount, + slice, + Arrays.hashCode(offsets), + Arrays.hashCode(valueIsNull), + retainedSizeInBytes, + sizeInBytes); + } }