rdblue commented on code in PR #18704:
URL: https://github.com/apache/iceberg/pull/18704#discussion_r4428834529
##########
core/src/test/java/org/apache/iceberg/mumbling/TestMumblingBitmap.java:
##########
@@ -776,6 +779,443 @@ public void testRelocatedBufferUpdateSerialization() {
assertThat(serialized.slice(containersOffset + 35, 2)).isEqualTo(sparse(3,
7).buffer());
}
+ @Test
+ public void testMergeSparseIntoSparse() {
+ int[] positions = new int[] {0, 10, 20, 255};
+ int[] otherPositions = new int[] {0, 15, 20, 30, 255};
+
+ Mutable bitmap = bitmap(sparse(positions)).asMutable();
+ bitmap.merge(bitmap(sparse(otherPositions)));
+
+ assertThat(bitmap.cardinality()).isEqualTo(6);
+ assertThat(bitmap.descriptorArray()).containsExactly(6);
+ assertSet(bitmap, 0, positions);
+ assertSet(bitmap, 0, otherPositions);
+ }
+
+ @Test
+ public void testMergeSparseIntoSparseConvertsToDense() {
+ int[] positions = range(0, 20);
+ int[] otherPositions = range(10, 40);
+
+ Mutable bitmap = bitmap(sparse(positions)).asMutable();
+ bitmap.merge(bitmap(sparse(otherPositions)));
+
+ assertThat(bitmap.cardinality()).isEqualTo(40);
+ assertThat(bitmap.descriptorArray()).containsExactly(32);
+ assertSet(bitmap, 0, positions);
+ assertSet(bitmap, 0, otherPositions);
+ }
+
+ @Test
+ public void testMergeSparseIntoDense() {
+ int[] otherPositions = new int[] {0, 15, 40, 100, 255};
+
+ Mutable bitmap = bitmap(dense(DENSE_CONTAINER)).asMutable();
+ bitmap.merge(bitmap(sparse(otherPositions)));
+
+ assertThat(bitmap.cardinality()).isEqualTo(35);
+ assertThat(bitmap.descriptorArray()).containsExactly(32);
+ assertSet(bitmap, 0, DENSE_CONTAINER);
+ assertSet(bitmap, 0, otherPositions);
+ }
+
+ @Test
+ public void testMergeDenseIntoSparse() {
+ int[] positions = new int[] {0, 15, 40, 100, 255};
+
+ Mutable bitmap = bitmap(sparse(positions)).asMutable();
+ bitmap.merge(bitmap(dense(DENSE_CONTAINER)));
+
+ assertThat(bitmap.cardinality()).isEqualTo(35);
+ assertThat(bitmap.descriptorArray()).containsExactly(32);
+ assertSet(bitmap, 0, positions);
+ assertSet(bitmap, 0, DENSE_CONTAINER);
+ }
+
+ @Test
+ public void testMergeDenseIntoDense() {
+ // positions 48-79
+ byte[] otherDense = new byte[32];
+ otherDense[6] = (byte) 0xFF;
+ otherDense[7] = (byte) 0xFF;
+ otherDense[8] = (byte) 0xFF;
+ otherDense[9] = (byte) 0xFF;
+
+ Mutable bitmap = bitmap(dense(DENSE_CONTAINER)).asMutable();
+ bitmap.merge(bitmap(dense(otherDense)));
+
+ assertThat(bitmap.cardinality()).isEqualTo(56);
+ assertThat(bitmap.descriptorArray()).containsExactly(32);
+ assertSet(bitmap, 0, DENSE_CONTAINER);
+ assertSet(bitmap, 0, otherDense);
+ }
+
+ @Test
+ public void testMergeSparseIntoSparseWithDenseArray() {
+ int[] positions = range(0, 31);
+ int[] otherPositions = new int[] {0, 255};
+
+ Mutable bitmap = bitmap(sparse(positions)).asMutable();
+ assertThat(bitmap.set(0)).as("Converts to dense but does not set a new
bit").isFalse();
+
+ bitmap.merge(bitmap(sparse(otherPositions)));
+
+ assertThat(bitmap.cardinality()).isEqualTo(32);
+ assertThat(bitmap.descriptorArray()).containsExactly(32);
+ assertSet(bitmap, 0, positions);
+ assertSet(bitmap, 0, otherPositions);
+ }
+
+ @Test
+ public void testMergeSparseWithDenseArrayIntoEmpty() {
+ int[] otherPositions = range(0, 31);
+
+ Mutable other = bitmap(sparse(otherPositions)).asMutable();
+ assertThat(other.set(0)).as("Converts to dense but does not set a new
bit").isFalse();
+
+ Mutable bitmap = MumblingBitmap.newMutableBitmap();
+ bitmap.merge(other);
+
+ assertThat(bitmap.cardinality()).isEqualTo(31);
+ assertThat(bitmap.descriptorArray()).containsExactly(31);
+ assertSet(bitmap, 0, otherPositions);
+ }
+
+ @Test
+ public void testMergeSparseWithDenseArrayIntoSparse() {
Review Comment:
I'd rather this name reflect the main case it is testing, which is the pair
(sparse with dense array, sparse). Adding "subset" seems to make it more
confusing to me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]