diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/crypto/DecryptionPropertiesFactoryTest.java b/parquet-hadoop/src/test/java/org/apache/parquet/crypto/DecryptionPropertiesFactoryTest.java index a351317610..cebe153329 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/crypto/DecryptionPropertiesFactoryTest.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/crypto/DecryptionPropertiesFactoryTest.java @@ -19,7 +19,7 @@ package org.apache.parquet.crypto; -import static org.junit.Assert.assertArrayEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.apache.hadoop.conf.Configuration; import org.junit.Test; @@ -36,12 +36,10 @@ public void testLoadDecPropertiesFactory() { FileDecryptionProperties decryptionProperties = decryptionPropertiesFactory.getFileDecryptionProperties(conf, null); - assertArrayEquals(decryptionProperties.getFooterKey(), SampleDecryptionPropertiesFactory.FOOTER_KEY); - assertArrayEquals( - decryptionProperties.getColumnKey(SampleDecryptionPropertiesFactory.COL1), - SampleDecryptionPropertiesFactory.COL1_KEY); - assertArrayEquals( - decryptionProperties.getColumnKey(SampleDecryptionPropertiesFactory.COL2), - SampleDecryptionPropertiesFactory.COL2_KEY); + assertThat(decryptionProperties.getFooterKey()).isEqualTo(SampleDecryptionPropertiesFactory.FOOTER_KEY); + assertThat(decryptionProperties.getColumnKey(SampleDecryptionPropertiesFactory.COL1)) + .isEqualTo(SampleDecryptionPropertiesFactory.COL1_KEY); + assertThat(decryptionProperties.getColumnKey(SampleDecryptionPropertiesFactory.COL2)) + .isEqualTo(SampleDecryptionPropertiesFactory.COL2_KEY); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/crypto/EncryptionPropertiesFactoryTest.java b/parquet-hadoop/src/test/java/org/apache/parquet/crypto/EncryptionPropertiesFactoryTest.java index 51133251dd..865bf2179f 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/crypto/EncryptionPropertiesFactoryTest.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/crypto/EncryptionPropertiesFactoryTest.java @@ -19,8 +19,7 @@ package org.apache.parquet.crypto; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.apache.hadoop.conf.Configuration; import org.apache.parquet.conf.ParquetConfiguration; @@ -40,13 +39,11 @@ public void testLoadEncPropertiesFactory() { FileEncryptionProperties encryptionProperties = encryptionPropertiesFactory.getFileEncryptionProperties(conf, null, null); - assertArrayEquals(encryptionProperties.getFooterKey(), SampleEncryptionPropertiesFactory.FOOTER_KEY); - assertEquals( - encryptionProperties.getColumnProperties(SampleEncryptionPropertiesFactory.COL1), - SampleEncryptionPropertiesFactory.COL1_ENCR_PROPERTIES); - assertEquals( - encryptionProperties.getColumnProperties(SampleEncryptionPropertiesFactory.COL2), - SampleEncryptionPropertiesFactory.COL2_ENCR_PROPERTIES); + assertThat(encryptionProperties.getFooterKey()).isEqualTo(SampleEncryptionPropertiesFactory.FOOTER_KEY); + assertThat(encryptionProperties.getColumnProperties(SampleEncryptionPropertiesFactory.COL1)) + .isEqualTo(SampleEncryptionPropertiesFactory.COL1_ENCR_PROPERTIES); + assertThat(encryptionProperties.getColumnProperties(SampleEncryptionPropertiesFactory.COL2)) + .isEqualTo(SampleEncryptionPropertiesFactory.COL2_ENCR_PROPERTIES); } @Test @@ -60,12 +57,10 @@ public void testLoadEncPropertiesFactoryParquetConfiguration() { FileEncryptionProperties encryptionProperties = encryptionPropertiesFactory.getFileEncryptionProperties( ConfigurationUtil.createHadoopConfiguration(conf), null, null); - assertArrayEquals(encryptionProperties.getFooterKey(), SampleEncryptionPropertiesFactory.FOOTER_KEY); - assertEquals( - encryptionProperties.getColumnProperties(SampleEncryptionPropertiesFactory.COL1), - SampleEncryptionPropertiesFactory.COL1_ENCR_PROPERTIES); - assertEquals( - encryptionProperties.getColumnProperties(SampleEncryptionPropertiesFactory.COL2), - SampleEncryptionPropertiesFactory.COL2_ENCR_PROPERTIES); + assertThat(encryptionProperties.getFooterKey()).isEqualTo(SampleEncryptionPropertiesFactory.FOOTER_KEY); + assertThat(encryptionProperties.getColumnProperties(SampleEncryptionPropertiesFactory.COL1)) + .isEqualTo(SampleEncryptionPropertiesFactory.COL1_ENCR_PROPERTIES); + assertThat(encryptionProperties.getColumnProperties(SampleEncryptionPropertiesFactory.COL2)) + .isEqualTo(SampleEncryptionPropertiesFactory.COL2_ENCR_PROPERTIES); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/crypto/propertiesfactory/SchemaControlEncryptionTest.java b/parquet-hadoop/src/test/java/org/apache/parquet/crypto/propertiesfactory/SchemaControlEncryptionTest.java index 733fb9f085..65d5cf4fc8 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/crypto/propertiesfactory/SchemaControlEncryptionTest.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/crypto/propertiesfactory/SchemaControlEncryptionTest.java @@ -24,8 +24,7 @@ import static org.apache.parquet.schema.Type.Repetition.OPTIONAL; import static org.apache.parquet.schema.Type.Repetition.REPEATED; import static org.apache.parquet.schema.Type.Repetition.REQUIRED; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import java.nio.file.Files; @@ -172,14 +171,14 @@ private void decryptParquetFileAndValid(String file, Configuration conf) throws .build(); for (int i = 0; i < numRecord; i++) { Group group = reader.read(); - assertEquals(testData.get("Name")[i], group.getBinary("Name", 0).toStringUsingUTF8()); - assertEquals(testData.get("Age")[i], group.getLong("Age", 0)); + assertThat(group.getBinary("Name", 0).toStringUsingUTF8()).isEqualTo(testData.get("Name")[i]); + assertThat(group.getLong("Age", 0)).isEqualTo(testData.get("Age")[i]); Group subGroup = group.getGroup("WebLinks", 0); - assertArrayEquals( - subGroup.getBinary("LinkedIn", 0).getBytes(), ((String) testData.get("LinkedIn")[i]).getBytes()); - assertArrayEquals( - subGroup.getBinary("Twitter", 0).getBytes(), ((String) testData.get("Twitter")[i]).getBytes()); + assertThat(((String) testData.get("LinkedIn")[i]).getBytes()) + .isEqualTo(subGroup.getBinary("LinkedIn", 0).getBytes()); + assertThat(((String) testData.get("Twitter")[i]).getBytes()) + .isEqualTo(subGroup.getBinary("Twitter", 0).getBytes()); } reader.close(); } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/encodings/FileEncodingsIT.java b/parquet-hadoop/src/test/java/org/apache/parquet/encodings/FileEncodingsIT.java index c35b13f8fc..d7d052ab90 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/encodings/FileEncodingsIT.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/encodings/FileEncodingsIT.java @@ -18,7 +18,7 @@ */ package org.apache.parquet.encodings; -import static junit.framework.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; @@ -555,12 +555,11 @@ public PageValuesValidator(int rowGroupID, int pageID, List expectedValues) { } public void validateNextValue(Object value) { - assertEquals( - String.format( + assertThat(value) + .as(String.format( "Value from page is different than expected, ROW_GROUP_ID=%d PAGE_ID=%d VALUE_POS=%d", - rowGroupID, pageID, currentPos), - expectedValues.get(currentPos++), - value); + rowGroupID, pageID, currentPos)) + .isEqualTo(expectedValues.get(currentPos++)); } public static void validateValuesForPage( diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/TestFiltersWithMissingColumns.java b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/TestFiltersWithMissingColumns.java index d4324a1ee5..1fd74d6971 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/TestFiltersWithMissingColumns.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/TestFiltersWithMissingColumns.java @@ -36,7 +36,7 @@ import static org.apache.parquet.schema.OriginalType.UTF8; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.BINARY; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; @@ -99,116 +99,110 @@ public void createDataFile() throws Exception { @Test public void testNormalFilter() throws Exception { - assertEquals(500, countFilteredRecords(path, lt(longColumn("id"), 500L))); + assertThat(countFilteredRecords(path, lt(longColumn("id"), 500L))).isEqualTo(500); } @Test public void testSimpleMissingColumnFilter() throws Exception { - assertEquals(0, countFilteredRecords(path, lt(longColumn("missing"), 500L))); + assertThat(countFilteredRecords(path, lt(longColumn("missing"), 500L))).isEqualTo(0); Set values = new HashSet<>(); values.add(1L); values.add(2L); values.add(5L); - assertEquals(0, countFilteredRecords(path, in(longColumn("missing"), values))); - assertEquals(1000, countFilteredRecords(path, notIn(longColumn("missing"), values))); + assertThat(countFilteredRecords(path, in(longColumn("missing"), values))) + .isEqualTo(0); + assertThat(countFilteredRecords(path, notIn(longColumn("missing"), values))) + .isEqualTo(1000); } @Test public void testAndMissingColumnFilter() throws Exception { // missing column filter is true - assertEquals( - 500, countFilteredRecords(path, and(lt(longColumn("id"), 500L), eq(binaryColumn("missing"), null)))); - assertEquals( - 500, - countFilteredRecords( - path, and(lt(longColumn("id"), 500L), notEq(binaryColumn("missing"), fromString("any"))))); - - assertEquals( - 500, countFilteredRecords(path, and(eq(binaryColumn("missing"), null), lt(longColumn("id"), 500L)))); - assertEquals( - 500, - countFilteredRecords( - path, and(notEq(binaryColumn("missing"), fromString("any")), lt(longColumn("id"), 500L)))); + assertThat(countFilteredRecords(path, and(lt(longColumn("id"), 500L), eq(binaryColumn("missing"), null)))) + .isEqualTo(500); + assertThat(countFilteredRecords( + path, and(lt(longColumn("id"), 500L), notEq(binaryColumn("missing"), fromString("any"))))) + .isEqualTo(500); + + assertThat(countFilteredRecords(path, and(eq(binaryColumn("missing"), null), lt(longColumn("id"), 500L)))) + .isEqualTo(500); + assertThat(countFilteredRecords( + path, and(notEq(binaryColumn("missing"), fromString("any")), lt(longColumn("id"), 500L)))) + .isEqualTo(500); // missing column filter is false - assertEquals( - 0, - countFilteredRecords( - path, and(lt(longColumn("id"), 500L), eq(binaryColumn("missing"), fromString("any"))))); - assertEquals( - 0, countFilteredRecords(path, and(lt(longColumn("id"), 500L), notEq(binaryColumn("missing"), null)))); - assertEquals( - 0, countFilteredRecords(path, and(lt(longColumn("id"), 500L), lt(doubleColumn("missing"), 33.33)))); - assertEquals( - 0, countFilteredRecords(path, and(lt(longColumn("id"), 500L), ltEq(doubleColumn("missing"), 33.33)))); - assertEquals( - 0, countFilteredRecords(path, and(lt(longColumn("id"), 500L), gt(doubleColumn("missing"), 33.33)))); - assertEquals( - 0, countFilteredRecords(path, and(lt(longColumn("id"), 500L), gtEq(doubleColumn("missing"), 33.33)))); - - assertEquals( - 0, - countFilteredRecords( - path, and(eq(binaryColumn("missing"), fromString("any")), lt(longColumn("id"), 500L)))); - assertEquals( - 0, countFilteredRecords(path, and(notEq(binaryColumn("missing"), null), lt(longColumn("id"), 500L)))); - assertEquals( - 0, countFilteredRecords(path, and(lt(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))); - assertEquals( - 0, countFilteredRecords(path, and(ltEq(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))); - assertEquals( - 0, countFilteredRecords(path, and(gt(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))); - assertEquals( - 0, countFilteredRecords(path, and(gtEq(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))); + assertThat(countFilteredRecords( + path, and(lt(longColumn("id"), 500L), eq(binaryColumn("missing"), fromString("any"))))) + .isEqualTo(0); + assertThat(countFilteredRecords(path, and(lt(longColumn("id"), 500L), notEq(binaryColumn("missing"), null)))) + .isEqualTo(0); + assertThat(countFilteredRecords(path, and(lt(longColumn("id"), 500L), lt(doubleColumn("missing"), 33.33)))) + .isEqualTo(0); + assertThat(countFilteredRecords(path, and(lt(longColumn("id"), 500L), ltEq(doubleColumn("missing"), 33.33)))) + .isEqualTo(0); + assertThat(countFilteredRecords(path, and(lt(longColumn("id"), 500L), gt(doubleColumn("missing"), 33.33)))) + .isEqualTo(0); + assertThat(countFilteredRecords(path, and(lt(longColumn("id"), 500L), gtEq(doubleColumn("missing"), 33.33)))) + .isEqualTo(0); + + assertThat(countFilteredRecords( + path, and(eq(binaryColumn("missing"), fromString("any")), lt(longColumn("id"), 500L)))) + .isEqualTo(0); + assertThat(countFilteredRecords(path, and(notEq(binaryColumn("missing"), null), lt(longColumn("id"), 500L)))) + .isEqualTo(0); + assertThat(countFilteredRecords(path, and(lt(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))) + .isEqualTo(0); + assertThat(countFilteredRecords(path, and(ltEq(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))) + .isEqualTo(0); + assertThat(countFilteredRecords(path, and(gt(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))) + .isEqualTo(0); + assertThat(countFilteredRecords(path, and(gtEq(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))) + .isEqualTo(0); } @Test public void testOrMissingColumnFilter() throws Exception { // missing column filter is false - assertEquals( - 500, - countFilteredRecords( - path, or(lt(longColumn("id"), 500L), eq(binaryColumn("missing"), fromString("any"))))); - assertEquals( - 500, countFilteredRecords(path, or(lt(longColumn("id"), 500L), notEq(binaryColumn("missing"), null)))); - assertEquals( - 500, countFilteredRecords(path, or(lt(longColumn("id"), 500L), lt(doubleColumn("missing"), 33.33)))); - assertEquals( - 500, countFilteredRecords(path, or(lt(longColumn("id"), 500L), ltEq(doubleColumn("missing"), 33.33)))); - assertEquals( - 500, countFilteredRecords(path, or(lt(longColumn("id"), 500L), gt(doubleColumn("missing"), 33.33)))); - assertEquals( - 500, countFilteredRecords(path, or(lt(longColumn("id"), 500L), gtEq(doubleColumn("missing"), 33.33)))); - - assertEquals( - 500, - countFilteredRecords( - path, or(eq(binaryColumn("missing"), fromString("any")), lt(longColumn("id"), 500L)))); - assertEquals( - 500, countFilteredRecords(path, or(notEq(binaryColumn("missing"), null), lt(longColumn("id"), 500L)))); - assertEquals( - 500, countFilteredRecords(path, or(lt(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))); - assertEquals( - 500, countFilteredRecords(path, or(ltEq(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))); - assertEquals( - 500, countFilteredRecords(path, or(gt(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))); - assertEquals( - 500, countFilteredRecords(path, or(gtEq(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))); + assertThat(countFilteredRecords( + path, or(lt(longColumn("id"), 500L), eq(binaryColumn("missing"), fromString("any"))))) + .isEqualTo(500); + assertThat(countFilteredRecords(path, or(lt(longColumn("id"), 500L), notEq(binaryColumn("missing"), null)))) + .isEqualTo(500); + assertThat(countFilteredRecords(path, or(lt(longColumn("id"), 500L), lt(doubleColumn("missing"), 33.33)))) + .isEqualTo(500); + assertThat(countFilteredRecords(path, or(lt(longColumn("id"), 500L), ltEq(doubleColumn("missing"), 33.33)))) + .isEqualTo(500); + assertThat(countFilteredRecords(path, or(lt(longColumn("id"), 500L), gt(doubleColumn("missing"), 33.33)))) + .isEqualTo(500); + assertThat(countFilteredRecords(path, or(lt(longColumn("id"), 500L), gtEq(doubleColumn("missing"), 33.33)))) + .isEqualTo(500); + + assertThat(countFilteredRecords( + path, or(eq(binaryColumn("missing"), fromString("any")), lt(longColumn("id"), 500L)))) + .isEqualTo(500); + assertThat(countFilteredRecords(path, or(notEq(binaryColumn("missing"), null), lt(longColumn("id"), 500L)))) + .isEqualTo(500); + assertThat(countFilteredRecords(path, or(lt(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))) + .isEqualTo(500); + assertThat(countFilteredRecords(path, or(ltEq(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))) + .isEqualTo(500); + assertThat(countFilteredRecords(path, or(gt(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))) + .isEqualTo(500); + assertThat(countFilteredRecords(path, or(gtEq(doubleColumn("missing"), 33.33), lt(longColumn("id"), 500L)))) + .isEqualTo(500); // missing column filter is false - assertEquals( - 1000, countFilteredRecords(path, or(lt(longColumn("id"), 500L), eq(binaryColumn("missing"), null)))); - assertEquals( - 1000, - countFilteredRecords( - path, or(lt(longColumn("id"), 500L), notEq(binaryColumn("missing"), fromString("any"))))); - - assertEquals( - 1000, countFilteredRecords(path, or(eq(binaryColumn("missing"), null), lt(longColumn("id"), 500L)))); - assertEquals( - 1000, - countFilteredRecords( - path, or(notEq(binaryColumn("missing"), fromString("any")), lt(longColumn("id"), 500L)))); + assertThat(countFilteredRecords(path, or(lt(longColumn("id"), 500L), eq(binaryColumn("missing"), null)))) + .isEqualTo(1000); + assertThat(countFilteredRecords( + path, or(lt(longColumn("id"), 500L), notEq(binaryColumn("missing"), fromString("any"))))) + .isEqualTo(1000); + + assertThat(countFilteredRecords(path, or(eq(binaryColumn("missing"), null), lt(longColumn("id"), 500L)))) + .isEqualTo(1000); + assertThat(countFilteredRecords( + path, or(notEq(binaryColumn("missing"), fromString("any")), lt(longColumn("id"), 500L)))) + .isEqualTo(1000); } public static long countFilteredRecords(Path path, FilterPredicate pred) throws IOException { diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/bloomfilterlevel/TestBloomFilterImpl.java b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/bloomfilterlevel/TestBloomFilterImpl.java index f2a0cfe1f2..ff01d94417 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/bloomfilterlevel/TestBloomFilterImpl.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/bloomfilterlevel/TestBloomFilterImpl.java @@ -23,8 +23,7 @@ import static org.apache.parquet.filter2.predicate.FilterApi.eq; import static org.apache.parquet.filter2.predicate.FilterApi.floatColumn; import static org.apache.parquet.filter2.predicate.FilterApi.in; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.util.HashSet; import java.util.List; @@ -59,12 +58,15 @@ public void testDoubleNaNLiteralDoesNotDrop() { ColumnChunkMetaData meta = columnMeta("double_column", PrimitiveTypeName.DOUBLE); BloomFilterReader reader = bloomFilterReader(meta, new BlockSplitBloomFilter(0)); - assertTrue(BloomFilterImpl.canDrop(eq(column, 1.0D), List.of(meta), reader)); - assertFalse(BloomFilterImpl.canDrop(eq(column, DOUBLE_NAN), List.of(meta), reader)); + assertThat(BloomFilterImpl.canDrop(eq(column, 1.0D), List.of(meta), reader)) + .isTrue(); + assertThat(BloomFilterImpl.canDrop(eq(column, DOUBLE_NAN), List.of(meta), reader)) + .isFalse(); Set values = new HashSet<>(); values.add(DOUBLE_NAN); - assertFalse(BloomFilterImpl.canDrop(in(column, values), List.of(meta), reader)); + assertThat(BloomFilterImpl.canDrop(in(column, values), List.of(meta), reader)) + .isFalse(); } @Test @@ -73,12 +75,15 @@ public void testFloatNaNLiteralDoesNotDrop() { ColumnChunkMetaData meta = columnMeta("float_column", PrimitiveTypeName.FLOAT); BloomFilterReader reader = bloomFilterReader(meta, new BlockSplitBloomFilter(0)); - assertTrue(BloomFilterImpl.canDrop(eq(column, 1.0F), List.of(meta), reader)); - assertFalse(BloomFilterImpl.canDrop(eq(column, FLOAT_NAN), List.of(meta), reader)); + assertThat(BloomFilterImpl.canDrop(eq(column, 1.0F), List.of(meta), reader)) + .isTrue(); + assertThat(BloomFilterImpl.canDrop(eq(column, FLOAT_NAN), List.of(meta), reader)) + .isFalse(); Set values = new HashSet<>(); values.add(FLOAT_NAN); - assertFalse(BloomFilterImpl.canDrop(in(column, values), List.of(meta), reader)); + assertThat(BloomFilterImpl.canDrop(in(column, values), List.of(meta), reader)) + .isFalse(); } @Test @@ -91,11 +96,13 @@ public void testFloat16NaNLiteralDoesNotDrop() { ColumnChunkMetaData meta = columnMeta("float16_column", type); BloomFilterReader reader = bloomFilterReader(meta, new BlockSplitBloomFilter(0)); - assertFalse(BloomFilterImpl.canDrop(eq(column, FLOAT16_NAN), List.of(meta), reader)); + assertThat(BloomFilterImpl.canDrop(eq(column, FLOAT16_NAN), List.of(meta), reader)) + .isFalse(); Set values = new HashSet<>(); values.add(FLOAT16_NAN); - assertFalse(BloomFilterImpl.canDrop(in(column, values), List.of(meta), reader)); + assertThat(BloomFilterImpl.canDrop(in(column, values), List.of(meta), reader)) + .isFalse(); } private static ColumnChunkMetaData columnMeta(String name, PrimitiveTypeName type) { diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/compat/TestRowGroupFilter.java b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/compat/TestRowGroupFilter.java index 80bdda4170..7f125ca00c 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/compat/TestRowGroupFilter.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/compat/TestRowGroupFilter.java @@ -24,7 +24,7 @@ import static org.apache.parquet.filter2.predicate.FilterApi.notEq; import static org.apache.parquet.filter2.predicate.FilterApi.notIn; import static org.apache.parquet.hadoop.TestInputFormat.makeBlockFromStats; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; import java.util.HashSet; @@ -87,36 +87,36 @@ public void testApplyRowGroupFilters() { set1.add(10); set1.add(50); List filtered = RowGroupFilter.filterRowGroups(FilterCompat.get(in(foo, set1)), blocks, schema); - assertEquals(List.of(b1, b2, b5), filtered); + assertThat(filtered).containsExactly(b1, b2, b5); filtered = RowGroupFilter.filterRowGroups(FilterCompat.get(notIn(foo, set1)), blocks, schema); - assertEquals(List.of(b1, b2, b3, b4, b5, b6), filtered); + assertThat(filtered).containsExactly(b1, b2, b3, b4, b5, b6); Set set2 = new HashSet<>(); set2.add(null); filtered = RowGroupFilter.filterRowGroups(FilterCompat.get(in(foo, set2)), blocks, schema); - assertEquals(List.of(b1, b3, b4, b5, b6), filtered); + assertThat(filtered).containsExactly(b1, b3, b4, b5, b6); filtered = RowGroupFilter.filterRowGroups(FilterCompat.get(notIn(foo, set2)), blocks, schema); - assertEquals(List.of(b1, b2, b3, b4, b5, b6), filtered); + assertThat(filtered).containsExactly(b1, b2, b3, b4, b5, b6); set2.add(8); filtered = RowGroupFilter.filterRowGroups(FilterCompat.get(in(foo, set2)), blocks, schema); - assertEquals(List.of(b1, b2, b3, b4, b5, b6), filtered); + assertThat(filtered).containsExactly(b1, b2, b3, b4, b5, b6); filtered = RowGroupFilter.filterRowGroups(FilterCompat.get(notIn(foo, set2)), blocks, schema); - assertEquals(List.of(b1, b2, b3, b4, b5, b6), filtered); + assertThat(filtered).containsExactly(b1, b2, b3, b4, b5, b6); filtered = RowGroupFilter.filterRowGroups(FilterCompat.get(eq(foo, 50)), blocks, schema); - assertEquals(List.of(b1, b2, b5), filtered); + assertThat(filtered).containsExactly(b1, b2, b5); filtered = RowGroupFilter.filterRowGroups(FilterCompat.get(notEq(foo, 50)), blocks, schema); - assertEquals(List.of(b1, b2, b3, b4, b5, b6), filtered); + assertThat(filtered).containsExactly(b1, b2, b3, b4, b5, b6); filtered = RowGroupFilter.filterRowGroups(FilterCompat.get(eq(foo, null)), blocks, schema); - assertEquals(List.of(b1, b3, b4, b5, b6), filtered); + assertThat(filtered).containsExactly(b1, b3, b4, b5, b6); filtered = RowGroupFilter.filterRowGroups(FilterCompat.get(notEq(foo, null)), blocks, schema); - assertEquals(List.of(b1, b2, b3, b5, b6), filtered); + assertThat(filtered).containsExactly(b1, b2, b3, b5, b6); filtered = RowGroupFilter.filterRowGroups(FilterCompat.get(eq(foo, 0)), blocks, schema); - assertEquals(List.of(b6), filtered); + assertThat(filtered).containsExactly(b6); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/dictionarylevel/DictionaryFilterTest.java b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/dictionarylevel/DictionaryFilterTest.java index 75df3a8a67..5782c47c80 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/dictionarylevel/DictionaryFilterTest.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/dictionarylevel/DictionaryFilterTest.java @@ -42,8 +42,7 @@ import static org.apache.parquet.filter2.predicate.FilterApi.userDefined; import static org.apache.parquet.hadoop.metadata.CompressionCodecName.GZIP; import static org.apache.parquet.schema.MessageTypeParser.parseMessageType; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verifyNoInteractions; @@ -305,7 +304,7 @@ public void testDictionaryEncodedColumns() throws Exception { } @SuppressWarnings("deprecation") - private void testDictionaryEncodedColumnsV1() throws Exception { + private void testDictionaryEncodedColumnsV1() { Set dictionaryEncodedColumns = new HashSet(List.of( "binary_field", "single_value_field", @@ -320,30 +319,30 @@ private void testDictionaryEncodedColumnsV1() throws Exception { for (ColumnChunkMetaData column : ccmd) { String name = column.getPath().toDotString(); if (dictionaryEncodedColumns.contains(name)) { - assertTrue( - "Column should be dictionary encoded: " + name, - column.getEncodings().contains(Encoding.PLAIN_DICTIONARY)); - assertFalse( - "Column should not have plain data pages" + name, - column.getEncodings().contains(Encoding.PLAIN)); + assertThat(column.getEncodings()) + .as("Column should be dictionary encoded: " + name) + .contains(Encoding.PLAIN_DICTIONARY); + assertThat(column.getEncodings()) + .as("Column should not have plain data pages" + name) + .doesNotContain(Encoding.PLAIN); } else { - assertTrue( - "Column should have plain encoding: " + name, - column.getEncodings().contains(Encoding.PLAIN)); + assertThat(column.getEncodings()) + .as("Column should have plain encoding: " + name) + .contains(Encoding.PLAIN); if (name.startsWith("fallback")) { - assertTrue( - "Column should have some dictionary encoding: " + name, - column.getEncodings().contains(Encoding.PLAIN_DICTIONARY)); + assertThat(column.getEncodings()) + .as("Column should have some dictionary encoding: " + name) + .contains(Encoding.PLAIN_DICTIONARY); } else { - assertFalse( - "Column should have no dictionary encoding: " + name, - column.getEncodings().contains(Encoding.PLAIN_DICTIONARY)); + assertThat(column.getEncodings()) + .as("Column should have no dictionary encoding: " + name) + .doesNotContain(Encoding.PLAIN_DICTIONARY); } } } } - private void testDictionaryEncodedColumnsV2() throws Exception { + private void testDictionaryEncodedColumnsV2() { Set dictionaryEncodedColumns = new HashSet(List.of( "binary_field", "single_value_field", @@ -360,26 +359,33 @@ private void testDictionaryEncodedColumnsV2() throws Exception { EncodingStats encStats = column.getEncodingStats(); String name = column.getPath().toDotString(); if (dictionaryEncodedColumns.contains(name)) { - assertTrue("Column should have dictionary pages: " + name, encStats.hasDictionaryPages()); - assertTrue( - "Column should have dictionary encoded pages: " + name, encStats.hasDictionaryEncodedPages()); - assertFalse( - "Column should not have non-dictionary encoded pages: " + name, - encStats.hasNonDictionaryEncodedPages()); + assertThat(encStats.hasDictionaryPages()) + .as("Column should have dictionary pages: " + name) + .isTrue(); + assertThat(encStats.hasDictionaryEncodedPages()) + .as("Column should have dictionary encoded pages: " + name) + .isTrue(); + assertThat(encStats.hasNonDictionaryEncodedPages()) + .as("Column should not have non-dictionary encoded pages: " + name) + .isFalse(); } else { - assertTrue( - "Column should have non-dictionary encoded pages: " + name, - encStats.hasNonDictionaryEncodedPages()); + assertThat(encStats.hasNonDictionaryEncodedPages()) + .as("Column should have non-dictionary encoded pages: " + name) + .isTrue(); if (name.startsWith("fallback")) { - assertTrue("Column should have dictionary pages: " + name, encStats.hasDictionaryPages()); - assertTrue( - "Column should have dictionary encoded pages: " + name, - encStats.hasDictionaryEncodedPages()); + assertThat(encStats.hasDictionaryPages()) + .as("Column should have dictionary pages: " + name) + .isTrue(); + assertThat(encStats.hasDictionaryEncodedPages()) + .as("Column should have dictionary encoded pages: " + name) + .isTrue(); } else { - assertFalse("Column should not have dictionary pages: " + name, encStats.hasDictionaryPages()); - assertFalse( - "Column should not have dictionary encoded pages: " + name, - encStats.hasDictionaryEncodedPages()); + assertThat(encStats.hasDictionaryPages()) + .as("Column should not have dictionary pages: " + name) + .isFalse(); + assertThat(encStats.hasDictionaryEncodedPages()) + .as("Column should not have dictionary encoded pages: " + name) + .isFalse(); } } } @@ -390,12 +396,17 @@ public void testEqBinary() throws Exception { BinaryColumn b = binaryColumn("binary_field"); FilterPredicate pred = eq(b, Binary.fromString("c")); - assertFalse("Should not drop block for lower case letters", canDrop(pred, ccmd, dictionaries)); + assertThat(canDrop(pred, ccmd, dictionaries)) + .as("Should not drop block for lower case letters") + .isFalse(); - assertTrue( - "Should drop block for upper case letters", canDrop(eq(b, Binary.fromString("A")), ccmd, dictionaries)); + assertThat(canDrop(eq(b, Binary.fromString("A")), ccmd, dictionaries)) + .as("Should drop block for upper case letters") + .isTrue(); - assertFalse("Should not drop block for null", canDrop(eq(b, null), ccmd, dictionaries)); + assertThat(canDrop(eq(b, null), ccmd, dictionaries)) + .as("Should not drop block for null") + .isFalse(); } @Test @@ -404,12 +415,18 @@ public void testEqFixed() throws Exception { // Only V2 supports dictionary encoding for FIXED_LEN_BYTE_ARRAY values if (version == PARQUET_2_0) { - assertTrue("Should drop block for -2", canDrop(eq(b, toBinary("-2", 17)), ccmd, dictionaries)); + assertThat(canDrop(eq(b, toBinary("-2", 17)), ccmd, dictionaries)) + .as("Should drop block for -2") + .isTrue(); } - assertFalse("Should not drop block for -1", canDrop(eq(b, toBinary("-1", 17)), ccmd, dictionaries)); + assertThat(canDrop(eq(b, toBinary("-1", 17)), ccmd, dictionaries)) + .as("Should not drop block for -1") + .isFalse(); - assertFalse("Should not drop block for null", canDrop(eq(b, null), ccmd, dictionaries)); + assertThat(canDrop(eq(b, null), ccmd, dictionaries)) + .as("Should not drop block for null") + .isFalse(); } @Test @@ -417,11 +434,17 @@ public void testEqInt96() throws Exception { BinaryColumn b = binaryColumn("int96_field"); // INT96 ordering is undefined => no filtering shall be done - assertFalse("Should not drop block for -2", canDrop(eq(b, toBinary("-2", 12)), ccmd, dictionaries)); + assertThat(canDrop(eq(b, toBinary("-2", 12)), ccmd, dictionaries)) + .as("Should not drop block for -2") + .isFalse(); - assertFalse("Should not drop block for -1", canDrop(eq(b, toBinary("-1", 12)), ccmd, dictionaries)); + assertThat(canDrop(eq(b, toBinary("-1", 12)), ccmd, dictionaries)) + .as("Should not drop block for -1") + .isFalse(); - assertFalse("Should not drop block for null", canDrop(eq(b, null), ccmd, dictionaries)); + assertThat(canDrop(eq(b, null), ccmd, dictionaries)) + .as("Should not drop block for null") + .isFalse(); } @Test @@ -430,31 +453,33 @@ public void testNotEqBinary() throws Exception { BinaryColumn sharpAndNull = binaryColumn("optional_single_value_field"); BinaryColumn b = binaryColumn("binary_field"); - assertTrue( - "Should drop block with only the excluded value", - canDrop(notEq(sharp, Binary.fromString("sharp")), ccmd, dictionaries)); + assertThat(canDrop(notEq(sharp, Binary.fromString("sharp")), ccmd, dictionaries)) + .as("Should drop block with only the excluded value") + .isTrue(); - assertFalse( - "Should not drop block with any other value", - canDrop(notEq(sharp, Binary.fromString("applause")), ccmd, dictionaries)); + assertThat(canDrop(notEq(sharp, Binary.fromString("applause")), ccmd, dictionaries)) + .as("Should not drop block with any other value") + .isFalse(); - assertFalse( - "Should not drop block with only the excluded value and null", - canDrop(notEq(sharpAndNull, Binary.fromString("sharp")), ccmd, dictionaries)); + assertThat(canDrop(notEq(sharpAndNull, Binary.fromString("sharp")), ccmd, dictionaries)) + .as("Should not drop block with only the excluded value and null") + .isFalse(); - assertFalse( - "Should not drop block with any other value", - canDrop(notEq(sharpAndNull, Binary.fromString("applause")), ccmd, dictionaries)); + assertThat(canDrop(notEq(sharpAndNull, Binary.fromString("applause")), ccmd, dictionaries)) + .as("Should not drop block with any other value") + .isFalse(); - assertFalse( - "Should not drop block with a known value", - canDrop(notEq(b, Binary.fromString("x")), ccmd, dictionaries)); + assertThat(canDrop(notEq(b, Binary.fromString("x")), ccmd, dictionaries)) + .as("Should not drop block with a known value") + .isFalse(); - assertFalse( - "Should not drop block with a known value", - canDrop(notEq(b, Binary.fromString("B")), ccmd, dictionaries)); + assertThat(canDrop(notEq(b, Binary.fromString("B")), ccmd, dictionaries)) + .as("Should not drop block with a known value") + .isFalse(); - assertFalse("Should not drop block for null", canDrop(notEq(b, null), ccmd, dictionaries)); + assertThat(canDrop(notEq(b, null), ccmd, dictionaries)) + .as("Should not drop block for null") + .isFalse(); } @Test @@ -465,11 +490,16 @@ public void testLtInt() throws Exception { lowest = Math.min(lowest, value); } - assertTrue("Should drop: < lowest value", canDrop(lt(i32, lowest), ccmd, dictionaries)); - assertFalse("Should not drop: < (lowest value + 1)", canDrop(lt(i32, lowest + 1), ccmd, dictionaries)); + assertThat(canDrop(lt(i32, lowest), ccmd, dictionaries)) + .as("Should drop: < lowest value") + .isTrue(); + assertThat(canDrop(lt(i32, lowest + 1), ccmd, dictionaries)) + .as("Should not drop: < (lowest value + 1)") + .isFalse(); - assertFalse( - "Should not drop: contains matching values", canDrop(lt(i32, Integer.MAX_VALUE), ccmd, dictionaries)); + assertThat(canDrop(lt(i32, Integer.MAX_VALUE), ccmd, dictionaries)) + .as("Should not drop: contains matching values") + .isFalse(); } @Test @@ -478,10 +508,14 @@ public void testLtFixed() throws Exception { // Only V2 supports dictionary encoding for FIXED_LEN_BYTE_ARRAY values if (version == PARQUET_2_0) { - assertTrue("Should drop: < lowest value", canDrop(lt(fixed, DECIMAL_VALUES[0]), ccmd, dictionaries)); + assertThat(canDrop(lt(fixed, DECIMAL_VALUES[0]), ccmd, dictionaries)) + .as("Should drop: < lowest value") + .isTrue(); } - assertFalse("Should not drop: < 2nd lowest value", canDrop(lt(fixed, DECIMAL_VALUES[1]), ccmd, dictionaries)); + assertThat(canDrop(lt(fixed, DECIMAL_VALUES[1]), ccmd, dictionaries)) + .as("Should not drop: < 2nd lowest value") + .isFalse(); } @Test @@ -492,11 +526,16 @@ public void testLtEqLong() throws Exception { lowest = Math.min(lowest, value); } - assertTrue("Should drop: <= lowest - 1", canDrop(ltEq(i64, lowest - 1), ccmd, dictionaries)); - assertFalse("Should not drop: <= lowest", canDrop(ltEq(i64, lowest), ccmd, dictionaries)); + assertThat(canDrop(ltEq(i64, lowest - 1), ccmd, dictionaries)) + .as("Should drop: <= lowest - 1") + .isTrue(); + assertThat(canDrop(ltEq(i64, lowest), ccmd, dictionaries)) + .as("Should not drop: <= lowest") + .isFalse(); - assertFalse( - "Should not drop: contains matching values", canDrop(ltEq(i64, Long.MAX_VALUE), ccmd, dictionaries)); + assertThat(canDrop(ltEq(i64, Long.MAX_VALUE), ccmd, dictionaries)) + .as("Should not drop: contains matching values") + .isFalse(); } @Test @@ -507,10 +546,16 @@ public void testGtFloat() throws Exception { highest = Math.max(highest, toFloat(value)); } - assertTrue("Should drop: > highest value", canDrop(gt(f, highest), ccmd, dictionaries)); - assertFalse("Should not drop: > (highest value - 1.0)", canDrop(gt(f, highest - 1.0f), ccmd, dictionaries)); + assertThat(canDrop(gt(f, highest), ccmd, dictionaries)) + .as("Should drop: > highest value") + .isTrue(); + assertThat(canDrop(gt(f, highest - 1.0f), ccmd, dictionaries)) + .as("Should not drop: > (highest value - 1.0)") + .isFalse(); - assertFalse("Should not drop: contains matching values", canDrop(gt(f, Float.MIN_VALUE), ccmd, dictionaries)); + assertThat(canDrop(gt(f, Float.MIN_VALUE), ccmd, dictionaries)) + .as("Should not drop: contains matching values") + .isFalse(); } @Test @@ -521,11 +566,16 @@ public void testGtEqDouble() throws Exception { highest = Math.max(highest, toDouble(value)); } - assertTrue("Should drop: >= highest + 0.00000001", canDrop(gtEq(d, highest + 0.00000001), ccmd, dictionaries)); - assertFalse("Should not drop: >= highest", canDrop(gtEq(d, highest), ccmd, dictionaries)); + assertThat(canDrop(gtEq(d, highest + 0.00000001), ccmd, dictionaries)) + .as("Should drop: >= highest + 0.00000001") + .isTrue(); + assertThat(canDrop(gtEq(d, highest), ccmd, dictionaries)) + .as("Should not drop: >= highest") + .isFalse(); - assertFalse( - "Should not drop: contains matching values", canDrop(gtEq(d, Double.MIN_VALUE), ccmd, dictionaries)); + assertThat(canDrop(gtEq(d, Double.MIN_VALUE), ccmd, dictionaries)) + .as("Should not drop: contains matching values") + .isFalse(); } @Test @@ -536,41 +586,65 @@ public void testNaNDictionaryFilterIsConservative() throws Exception { FloatColumn floatColumn = floatColumn("float_nan_field"); BinaryColumn float16Column = binaryColumn("float16_nan_field"); - assertFalse(canDrop(eq(doubleColumn, DOUBLE_NAN_A), nanColumns, nanDictionaries)); - assertFalse(canDrop(eq(doubleColumn, DOUBLE_NAN_B), nanColumns, nanDictionaries)); - assertFalse(canDrop(notEq(doubleColumn, DOUBLE_NAN_A), nanColumns, nanDictionaries)); - assertFalse(canDrop(notEq(doubleColumn, DOUBLE_NAN_B), nanColumns, nanDictionaries)); - assertFalse(canDrop(lt(doubleColumn, DOUBLE_NAN_B), nanColumns, nanDictionaries)); - assertFalse(canDrop(gt(doubleColumn, DOUBLE_NAN_B), nanColumns, nanDictionaries)); - - assertFalse(canDrop(eq(floatColumn, FLOAT_NAN_A), nanColumns, nanDictionaries)); - assertFalse(canDrop(eq(floatColumn, FLOAT_NAN_B), nanColumns, nanDictionaries)); - assertFalse(canDrop(notEq(floatColumn, FLOAT_NAN_A), nanColumns, nanDictionaries)); - assertFalse(canDrop(notEq(floatColumn, FLOAT_NAN_B), nanColumns, nanDictionaries)); - assertFalse(canDrop(lt(floatColumn, FLOAT_NAN_B), nanColumns, nanDictionaries)); - assertFalse(canDrop(gt(floatColumn, FLOAT_NAN_B), nanColumns, nanDictionaries)); + assertThat(canDrop(eq(doubleColumn, DOUBLE_NAN_A), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(eq(doubleColumn, DOUBLE_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(notEq(doubleColumn, DOUBLE_NAN_A), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(notEq(doubleColumn, DOUBLE_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(lt(doubleColumn, DOUBLE_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(gt(doubleColumn, DOUBLE_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); + + assertThat(canDrop(eq(floatColumn, FLOAT_NAN_A), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(eq(floatColumn, FLOAT_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(notEq(floatColumn, FLOAT_NAN_A), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(notEq(floatColumn, FLOAT_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(lt(floatColumn, FLOAT_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(gt(floatColumn, FLOAT_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); Set doubleSet = new HashSet<>(); doubleSet.add(DOUBLE_NAN_B); - assertFalse(canDrop(in(doubleColumn, doubleSet), nanColumns, nanDictionaries)); - assertFalse(canDrop(notIn(doubleColumn, doubleSet), nanColumns, nanDictionaries)); + assertThat(canDrop(in(doubleColumn, doubleSet), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(notIn(doubleColumn, doubleSet), nanColumns, nanDictionaries)) + .isFalse(); Set floatSet = new HashSet<>(); floatSet.add(FLOAT_NAN_B); - assertFalse(canDrop(in(floatColumn, floatSet), nanColumns, nanDictionaries)); - assertFalse(canDrop(notIn(floatColumn, floatSet), nanColumns, nanDictionaries)); + assertThat(canDrop(in(floatColumn, floatSet), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(notIn(floatColumn, floatSet), nanColumns, nanDictionaries)) + .isFalse(); Set float16Set = new HashSet<>(); float16Set.add(FLOAT16_NAN_B); - assertFalse(canDrop(in(float16Column, float16Set), nanColumns, nanDictionaries)); - assertFalse(canDrop(notIn(float16Column, float16Set), nanColumns, nanDictionaries)); - - assertFalse(canDrop(eq(float16Column, FLOAT16_NAN_A), nanColumns, nanDictionaries)); - assertFalse(canDrop(eq(float16Column, FLOAT16_NAN_B), nanColumns, nanDictionaries)); - assertFalse(canDrop(notEq(float16Column, FLOAT16_NAN_A), nanColumns, nanDictionaries)); - assertFalse(canDrop(notEq(float16Column, FLOAT16_NAN_B), nanColumns, nanDictionaries)); - assertFalse(canDrop(lt(float16Column, FLOAT16_NAN_B), nanColumns, nanDictionaries)); - assertFalse(canDrop(gt(float16Column, FLOAT16_NAN_B), nanColumns, nanDictionaries)); + assertThat(canDrop(in(float16Column, float16Set), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(notIn(float16Column, float16Set), nanColumns, nanDictionaries)) + .isFalse(); + + assertThat(canDrop(eq(float16Column, FLOAT16_NAN_A), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(eq(float16Column, FLOAT16_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(notEq(float16Column, FLOAT16_NAN_A), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(notEq(float16Column, FLOAT16_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(lt(float16Column, FLOAT16_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); + assertThat(canDrop(gt(float16Column, FLOAT16_NAN_B), nanColumns, nanDictionaries)) + .isFalse(); } @Test @@ -586,21 +660,33 @@ private static void assertNaNDictionaryRangeFiltersAreConservative( FloatColumn floatColumn = floatColumn("float_nan_field"); BinaryColumn float16Column = binaryColumn("float16_nan_field"); - assertFalse(canDrop(gt(doubleColumn, 0.0D), nanColumns, dictionariesWithNaNs)); - assertFalse(canDrop(gtEq(doubleColumn, 0.0D), nanColumns, dictionariesWithNaNs)); - assertFalse(canDrop(lt(doubleColumn, 0.0D), nanColumns, dictionariesWithNaNs)); - assertFalse(canDrop(ltEq(doubleColumn, 0.0D), nanColumns, dictionariesWithNaNs)); - - assertFalse(canDrop(gt(floatColumn, 0.0F), nanColumns, dictionariesWithNaNs)); - assertFalse(canDrop(gtEq(floatColumn, 0.0F), nanColumns, dictionariesWithNaNs)); - assertFalse(canDrop(lt(floatColumn, 0.0F), nanColumns, dictionariesWithNaNs)); - assertFalse(canDrop(ltEq(floatColumn, 0.0F), nanColumns, dictionariesWithNaNs)); + assertThat(canDrop(gt(doubleColumn, 0.0D), nanColumns, dictionariesWithNaNs)) + .isFalse(); + assertThat(canDrop(gtEq(doubleColumn, 0.0D), nanColumns, dictionariesWithNaNs)) + .isFalse(); + assertThat(canDrop(lt(doubleColumn, 0.0D), nanColumns, dictionariesWithNaNs)) + .isFalse(); + assertThat(canDrop(ltEq(doubleColumn, 0.0D), nanColumns, dictionariesWithNaNs)) + .isFalse(); + + assertThat(canDrop(gt(floatColumn, 0.0F), nanColumns, dictionariesWithNaNs)) + .isFalse(); + assertThat(canDrop(gtEq(floatColumn, 0.0F), nanColumns, dictionariesWithNaNs)) + .isFalse(); + assertThat(canDrop(lt(floatColumn, 0.0F), nanColumns, dictionariesWithNaNs)) + .isFalse(); + assertThat(canDrop(ltEq(floatColumn, 0.0F), nanColumns, dictionariesWithNaNs)) + .isFalse(); Binary zero = Binary.fromConstantByteArray(new byte[] {0x00, 0x00}); - assertFalse(canDrop(gt(float16Column, zero), nanColumns, dictionariesWithNaNs)); - assertFalse(canDrop(gtEq(float16Column, zero), nanColumns, dictionariesWithNaNs)); - assertFalse(canDrop(lt(float16Column, zero), nanColumns, dictionariesWithNaNs)); - assertFalse(canDrop(ltEq(float16Column, zero), nanColumns, dictionariesWithNaNs)); + assertThat(canDrop(gt(float16Column, zero), nanColumns, dictionariesWithNaNs)) + .isFalse(); + assertThat(canDrop(gtEq(float16Column, zero), nanColumns, dictionariesWithNaNs)) + .isFalse(); + assertThat(canDrop(lt(float16Column, zero), nanColumns, dictionariesWithNaNs)) + .isFalse(); + assertThat(canDrop(ltEq(float16Column, zero), nanColumns, dictionariesWithNaNs)) + .isFalse(); } private static List nanColumns() { @@ -729,8 +815,12 @@ public void testInBinary() throws Exception { set1.add(Binary.fromString("E")); FilterPredicate predIn1 = in(b, set1); FilterPredicate predNotIn1 = notIn(b, set1); - assertFalse("Should not drop block", canDrop(predIn1, ccmd, dictionaries)); - assertFalse("Should not drop block", canDrop(predNotIn1, ccmd, dictionaries)); + assertThat(canDrop(predIn1, ccmd, dictionaries)) + .as("Should not drop block") + .isFalse(); + assertThat(canDrop(predNotIn1, ccmd, dictionaries)) + .as("Should not drop block") + .isFalse(); Set set2 = new HashSet<>(); for (int i = 0; i < 26; i++) { @@ -739,8 +829,12 @@ public void testInBinary() throws Exception { set2.add(Binary.fromString("A")); FilterPredicate predIn2 = in(b, set2); FilterPredicate predNotIn2 = notIn(b, set2); - assertFalse("Should not drop block", canDrop(predIn2, ccmd, dictionaries)); - assertTrue("Should not drop block", canDrop(predNotIn2, ccmd, dictionaries)); + assertThat(canDrop(predIn2, ccmd, dictionaries)) + .as("Should not drop block") + .isFalse(); + assertThat(canDrop(predNotIn2, ccmd, dictionaries)) + .as("Should not drop block") + .isTrue(); Set set3 = new HashSet<>(); set3.add(Binary.fromString("F")); @@ -749,15 +843,21 @@ public void testInBinary() throws Exception { set3.add(Binary.fromString("E")); FilterPredicate predIn3 = in(b, set3); FilterPredicate predNotIn3 = notIn(b, set3); - assertTrue("Should drop block", canDrop(predIn3, ccmd, dictionaries)); - assertFalse("Should not drop block", canDrop(predNotIn3, ccmd, dictionaries)); + assertThat(canDrop(predIn3, ccmd, dictionaries)).as("Should drop block").isTrue(); + assertThat(canDrop(predNotIn3, ccmd, dictionaries)) + .as("Should not drop block") + .isFalse(); Set set4 = new HashSet<>(); set4.add(null); FilterPredicate predIn4 = in(b, set4); FilterPredicate predNotIn4 = notIn(b, set4); - assertFalse("Should not drop block for null", canDrop(predIn4, ccmd, dictionaries)); - assertFalse("Should not drop block for null", canDrop(predNotIn4, ccmd, dictionaries)); + assertThat(canDrop(predIn4, ccmd, dictionaries)) + .as("Should not drop block for null") + .isFalse(); + assertThat(canDrop(predNotIn4, ccmd, dictionaries)) + .as("Should not drop block for null") + .isFalse(); BinaryColumn sharpAndNull = binaryColumn("optional_single_value_field"); @@ -766,8 +866,12 @@ public void testInBinary() throws Exception { set5.add(Binary.fromString("sharp")); FilterPredicate predNotIn5 = notIn(sharpAndNull, set5); FilterPredicate predIn5 = in(sharpAndNull, set5); - assertFalse("Should not drop block", canDrop(predNotIn5, ccmd, dictionaries)); - assertFalse("Should not drop block", canDrop(predIn5, ccmd, dictionaries)); + assertThat(canDrop(predNotIn5, ccmd, dictionaries)) + .as("Should not drop block") + .isFalse(); + assertThat(canDrop(predIn5, ccmd, dictionaries)) + .as("Should not drop block") + .isFalse(); } @Test @@ -782,23 +886,35 @@ public void testInFixed() throws Exception { set1.add(toBinary("12345", 17)); FilterPredicate predIn1 = in(b, set1); FilterPredicate predNotIn1 = notIn(b, set1); - assertTrue("Should drop block for in (-2, -22, 12345)", canDrop(predIn1, ccmd, dictionaries)); - assertFalse("Should not drop block for notIn (-2, -22, 12345)", canDrop(predNotIn1, ccmd, dictionaries)); + assertThat(canDrop(predIn1, ccmd, dictionaries)) + .as("Should drop block for in (-2, -22, 12345)") + .isTrue(); + assertThat(canDrop(predNotIn1, ccmd, dictionaries)) + .as("Should not drop block for notIn (-2, -22, 12345)") + .isFalse(); Set set2 = new HashSet<>(); set2.add(toBinary("-1", 17)); set2.add(toBinary("0", 17)); set2.add(toBinary("12345", 17)); - assertFalse("Should not drop block for in (-1, 0, 12345)", canDrop(in(b, set2), ccmd, dictionaries)); - assertFalse("Should not drop block for in (-1, 0, 12345)", canDrop(notIn(b, set2), ccmd, dictionaries)); + assertThat(canDrop(in(b, set2), ccmd, dictionaries)) + .as("Should not drop block for in (-1, 0, 12345)") + .isFalse(); + assertThat(canDrop(notIn(b, set2), ccmd, dictionaries)) + .as("Should not drop block for in (-1, 0, 12345)") + .isFalse(); } Set set3 = new HashSet<>(); set3.add(null); FilterPredicate predIn3 = in(b, set3); FilterPredicate predNotIn3 = notIn(b, set3); - assertFalse("Should not drop block for null", canDrop(predIn3, ccmd, dictionaries)); - assertFalse("Should not drop block for null", canDrop(predNotIn3, ccmd, dictionaries)); + assertThat(canDrop(predIn3, ccmd, dictionaries)) + .as("Should not drop block for null") + .isFalse(); + assertThat(canDrop(predNotIn3, ccmd, dictionaries)) + .as("Should not drop block for null") + .isFalse(); } @Test @@ -812,8 +928,12 @@ public void testInInt96() throws Exception { set1.add(toBinary("12345", 12)); FilterPredicate predIn1 = in(b, set1); FilterPredicate predNotIn1 = notIn(b, set1); - assertFalse("Should not drop block for in (-2, -0, 12345)", canDrop(predIn1, ccmd, dictionaries)); - assertFalse("Should not drop block for notIn (-2, -0, 12345)", canDrop(predNotIn1, ccmd, dictionaries)); + assertThat(canDrop(predIn1, ccmd, dictionaries)) + .as("Should not drop block for in (-2, -0, 12345)") + .isFalse(); + assertThat(canDrop(predNotIn1, ccmd, dictionaries)) + .as("Should not drop block for notIn (-2, -0, 12345)") + .isFalse(); Set set2 = new HashSet<>(); set2.add(toBinary("-2", 17)); @@ -821,15 +941,23 @@ public void testInInt96() throws Exception { set2.add(toBinary("-789", 17)); FilterPredicate predIn2 = in(b, set2); FilterPredicate predNotIn2 = notIn(b, set2); - assertFalse("Should not drop block for in (-2, 12345, -789)", canDrop(predIn2, ccmd, dictionaries)); - assertFalse("Should not drop block for notIn (-2, 12345, -789)", canDrop(predNotIn2, ccmd, dictionaries)); + assertThat(canDrop(predIn2, ccmd, dictionaries)) + .as("Should not drop block for in (-2, 12345, -789)") + .isFalse(); + assertThat(canDrop(predNotIn2, ccmd, dictionaries)) + .as("Should not drop block for notIn (-2, 12345, -789)") + .isFalse(); Set set3 = new HashSet<>(); set3.add(null); FilterPredicate predIn3 = in(b, set3); FilterPredicate predNotIn3 = notIn(b, set3); - assertFalse("Should not drop block for null", canDrop(predIn3, ccmd, dictionaries)); - assertFalse("Should not drop block for null", canDrop(predNotIn3, ccmd, dictionaries)); + assertThat(canDrop(predIn3, ccmd, dictionaries)) + .as("Should not drop block for null") + .isFalse(); + assertThat(canDrop(predNotIn3, ccmd, dictionaries)) + .as("Should not drop block for null") + .isFalse(); } @Test @@ -844,10 +972,18 @@ public void testAnd() throws Exception { FilterPredicate x = eq(col, Binary.fromString("x")); FilterPredicate y = eq(col, Binary.fromString("y")); - assertTrue("Should drop when either predicate must be false", canDrop(and(B, y), ccmd, dictionaries)); - assertTrue("Should drop when either predicate must be false", canDrop(and(x, C), ccmd, dictionaries)); - assertTrue("Should drop when either predicate must be false", canDrop(and(B, C), ccmd, dictionaries)); - assertFalse("Should not drop when either predicate could be true", canDrop(and(x, y), ccmd, dictionaries)); + assertThat(canDrop(and(B, y), ccmd, dictionaries)) + .as("Should drop when either predicate must be false") + .isTrue(); + assertThat(canDrop(and(x, C), ccmd, dictionaries)) + .as("Should drop when either predicate must be false") + .isTrue(); + assertThat(canDrop(and(B, C), ccmd, dictionaries)) + .as("Should drop when either predicate must be false") + .isTrue(); + assertThat(canDrop(and(x, y), ccmd, dictionaries)) + .as("Should not drop when either predicate could be true") + .isFalse(); } @Test @@ -862,10 +998,18 @@ public void testOr() throws Exception { FilterPredicate x = eq(col, Binary.fromString("x")); FilterPredicate y = eq(col, Binary.fromString("y")); - assertFalse("Should not drop when one predicate could be true", canDrop(or(B, y), ccmd, dictionaries)); - assertFalse("Should not drop when one predicate could be true", canDrop(or(x, C), ccmd, dictionaries)); - assertTrue("Should drop when both predicates must be false", canDrop(or(B, C), ccmd, dictionaries)); - assertFalse("Should not drop when one predicate could be true", canDrop(or(x, y), ccmd, dictionaries)); + assertThat(canDrop(or(B, y), ccmd, dictionaries)) + .as("Should not drop when one predicate could be true") + .isFalse(); + assertThat(canDrop(or(x, C), ccmd, dictionaries)) + .as("Should not drop when one predicate could be true") + .isFalse(); + assertThat(canDrop(or(B, C), ccmd, dictionaries)) + .as("Should drop when both predicates must be false") + .isTrue(); + assertThat(canDrop(or(x, y), ccmd, dictionaries)) + .as("Should not drop when one predicate could be true") + .isFalse(); } @Test @@ -873,13 +1017,13 @@ public void testUdp() throws Exception { InInt32UDP dropabble = new InInt32UDP(ImmutableSet.of(42)); InInt32UDP undroppable = new InInt32UDP(ImmutableSet.of(205)); - assertTrue( - "Should drop block for non-matching UDP", - canDrop(userDefined(intColumn("int32_field"), dropabble), ccmd, dictionaries)); + assertThat(canDrop(userDefined(intColumn("int32_field"), dropabble), ccmd, dictionaries)) + .as("Should drop block for non-matching UDP") + .isTrue(); - assertFalse( - "Should not drop block for matching UDP", - canDrop(userDefined(intColumn("int32_field"), undroppable), ccmd, dictionaries)); + assertThat(canDrop(userDefined(intColumn("int32_field"), undroppable), ccmd, dictionaries)) + .as("Should not drop block for matching UDP") + .isFalse(); } @Test @@ -890,10 +1034,12 @@ public void testNullAcceptingUdp() throws Exception { // A column with value 42 and 10% nulls IntColumn intColumnWithNulls = intColumn("optional_single_value_int32_field"); - assertTrue("Should drop block", canDrop(userDefined(intColumnWithNulls, drop42DenyNulls), ccmd, dictionaries)); - assertFalse( - "Should not drop block for null accepting udp", - canDrop(userDefined(intColumnWithNulls, drop42AcceptNulls), ccmd, dictionaries)); + assertThat(canDrop(userDefined(intColumnWithNulls, drop42DenyNulls), ccmd, dictionaries)) + .as("Should drop block") + .isTrue(); + assertThat(canDrop(userDefined(intColumnWithNulls, drop42AcceptNulls), ccmd, dictionaries)) + .as("Should not drop block for null accepting udp") + .isFalse(); } @Test @@ -909,12 +1055,17 @@ public void testInverseUdp() throws Exception { FilterPredicate inverse2 = LogicalInverseRewriter.rewrite(not(userDefined(intColumn("int32_field"), completeMatch))); - assertFalse("Should not drop block for inverse of non-matching UDP", canDrop(inverse, ccmd, dictionaries)); + assertThat(canDrop(inverse, ccmd, dictionaries)) + .as("Should not drop block for inverse of non-matching UDP") + .isFalse(); - assertFalse( - "Should not drop block for inverse of UDP with some matches", canDrop(inverse1, ccmd, dictionaries)); + assertThat(canDrop(inverse1, ccmd, dictionaries)) + .as("Should not drop block for inverse of UDP with some matches") + .isFalse(); - assertTrue("Should drop block for inverse of UDP with all matches", canDrop(inverse2, ccmd, dictionaries)); + assertThat(canDrop(inverse2, ccmd, dictionaries)) + .as("Should drop block for inverse of UDP with all matches") + .isTrue(); } @Test @@ -922,23 +1073,29 @@ public void testColumnWithoutDictionary() throws Exception { IntColumn plain = intColumn("plain_int32_field"); DictionaryPageReadStore dictionaryStore = mock(DictionaryPageReadStore.class); - assertFalse("Should never drop block using plain encoding", canDrop(eq(plain, -10), ccmd, dictionaryStore)); + assertThat(canDrop(eq(plain, -10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); - assertFalse("Should never drop block using plain encoding", canDrop(lt(plain, -10), ccmd, dictionaryStore)); + assertThat(canDrop(lt(plain, -10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); - assertFalse("Should never drop block using plain encoding", canDrop(ltEq(plain, -10), ccmd, dictionaryStore)); + assertThat(canDrop(ltEq(plain, -10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); - assertFalse( - "Should never drop block using plain encoding", - canDrop(gt(plain, nElements + 10), ccmd, dictionaryStore)); + assertThat(canDrop(gt(plain, nElements + 10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); - assertFalse( - "Should never drop block using plain encoding", - canDrop(gtEq(plain, nElements + 10), ccmd, dictionaryStore)); + assertThat(canDrop(gtEq(plain, nElements + 10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); - assertFalse( - "Should never drop block using plain encoding", - canDrop(notEq(plain, nElements + 10), ccmd, dictionaryStore)); + assertThat(canDrop(notEq(plain, nElements + 10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); verifyNoInteractions(dictionaryStore); } @@ -948,23 +1105,29 @@ public void testColumnWithDictionaryAndPlainEncodings() throws Exception { IntColumn plain = intColumn("fallback_binary_field"); DictionaryPageReadStore dictionaryStore = mock(DictionaryPageReadStore.class); - assertFalse("Should never drop block using plain encoding", canDrop(eq(plain, -10), ccmd, dictionaryStore)); + assertThat(canDrop(eq(plain, -10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); - assertFalse("Should never drop block using plain encoding", canDrop(lt(plain, -10), ccmd, dictionaryStore)); + assertThat(canDrop(lt(plain, -10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); - assertFalse("Should never drop block using plain encoding", canDrop(ltEq(plain, -10), ccmd, dictionaryStore)); + assertThat(canDrop(ltEq(plain, -10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); - assertFalse( - "Should never drop block using plain encoding", - canDrop(gt(plain, nElements + 10), ccmd, dictionaryStore)); + assertThat(canDrop(gt(plain, nElements + 10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); - assertFalse( - "Should never drop block using plain encoding", - canDrop(gtEq(plain, nElements + 10), ccmd, dictionaryStore)); + assertThat(canDrop(gtEq(plain, nElements + 10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); - assertFalse( - "Should never drop block using plain encoding", - canDrop(notEq(plain, nElements + 10), ccmd, dictionaryStore)); + assertThat(canDrop(notEq(plain, nElements + 10), ccmd, dictionaryStore)) + .as("Should never drop block using plain encoding") + .isFalse(); verifyNoInteractions(dictionaryStore); } @@ -973,57 +1136,62 @@ public void testColumnWithDictionaryAndPlainEncodings() throws Exception { public void testEqMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); - assertTrue( - "Should drop block for non-null query", canDrop(eq(b, Binary.fromString("any")), ccmd, dictionaries)); + assertThat(canDrop(eq(b, Binary.fromString("any")), ccmd, dictionaries)) + .as("Should drop block for non-null query") + .isTrue(); - assertFalse("Should not drop block null query", canDrop(eq(b, null), ccmd, dictionaries)); + assertThat(canDrop(eq(b, null), ccmd, dictionaries)) + .as("Should not drop block null query") + .isFalse(); } @Test public void testNotEqMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); - assertFalse( - "Should not drop block for non-null query", - canDrop(notEq(b, Binary.fromString("any")), ccmd, dictionaries)); + assertThat(canDrop(notEq(b, Binary.fromString("any")), ccmd, dictionaries)) + .as("Should not drop block for non-null query") + .isFalse(); - assertTrue("Should not drop block null query", canDrop(notEq(b, null), ccmd, dictionaries)); + assertThat(canDrop(notEq(b, null), ccmd, dictionaries)) + .as("Should not drop block null query") + .isTrue(); } @Test public void testLtMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); - assertTrue( - "Should drop block for any non-null query", - canDrop(lt(b, Binary.fromString("any")), ccmd, dictionaries)); + assertThat(canDrop(lt(b, Binary.fromString("any")), ccmd, dictionaries)) + .as("Should drop block for any non-null query") + .isTrue(); } @Test public void testLtEqMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); - assertTrue( - "Should drop block for any non-null query", - canDrop(ltEq(b, Binary.fromString("any")), ccmd, dictionaries)); + assertThat(canDrop(ltEq(b, Binary.fromString("any")), ccmd, dictionaries)) + .as("Should drop block for any non-null query") + .isTrue(); } @Test public void testGtMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); - assertTrue( - "Should drop block for any non-null query", - canDrop(gt(b, Binary.fromString("any")), ccmd, dictionaries)); + assertThat(canDrop(gt(b, Binary.fromString("any")), ccmd, dictionaries)) + .as("Should drop block for any non-null query") + .isTrue(); } @Test public void testGtEqMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); - assertTrue( - "Should drop block for any non-null query", - canDrop(gtEq(b, Binary.fromString("any")), ccmd, dictionaries)); + assertThat(canDrop(gtEq(b, Binary.fromString("any")), ccmd, dictionaries)) + .as("Should drop block for any non-null query") + .isTrue(); } @Test @@ -1032,12 +1200,12 @@ public void testUdpMissingColumn() throws Exception { InInt32UDP nullAccepting = new InInt32UDP(Sets.newHashSet((Integer) null)); IntColumn fake = intColumn("missing_column"); - assertTrue( - "Should drop block for null rejecting udp", - canDrop(userDefined(fake, nullRejecting), ccmd, dictionaries)); - assertFalse( - "Should not drop block for null accepting udp", - canDrop(userDefined(fake, nullAccepting), ccmd, dictionaries)); + assertThat(canDrop(userDefined(fake, nullRejecting), ccmd, dictionaries)) + .as("Should drop block for null rejecting udp") + .isTrue(); + assertThat(canDrop(userDefined(fake, nullAccepting), ccmd, dictionaries)) + .as("Should not drop block for null accepting udp") + .isFalse(); } @Test @@ -1046,12 +1214,12 @@ public void testInverseUdpMissingColumn() throws Exception { InInt32UDP nullAccepting = new InInt32UDP(Sets.newHashSet((Integer) null)); IntColumn fake = intColumn("missing_column"); - assertTrue( - "Should drop block for null accepting udp", - canDrop(LogicalInverseRewriter.rewrite(not(userDefined(fake, nullAccepting))), ccmd, dictionaries)); - assertFalse( - "Should not drop block for null rejecting udp", - canDrop(LogicalInverseRewriter.rewrite(not(userDefined(fake, nullRejecting))), ccmd, dictionaries)); + assertThat(canDrop(LogicalInverseRewriter.rewrite(not(userDefined(fake, nullAccepting))), ccmd, dictionaries)) + .as("Should drop block for null accepting udp") + .isTrue(); + assertThat(canDrop(LogicalInverseRewriter.rewrite(not(userDefined(fake, nullRejecting))), ccmd, dictionaries)) + .as("Should not drop block for null rejecting udp") + .isFalse(); } @Test @@ -1066,10 +1234,18 @@ public void testContainsAnd() throws Exception { Operators.Contains x = contains(eq(col, Binary.fromString("x"))); Operators.Contains y = contains(eq(col, Binary.fromString("y"))); - assertTrue("Should drop when either predicate must be false", canDrop(and(B, y), ccmd, dictionaries)); - assertTrue("Should drop when either predicate must be false", canDrop(and(x, C), ccmd, dictionaries)); - assertTrue("Should drop when either predicate must be false", canDrop(and(B, C), ccmd, dictionaries)); - assertFalse("Should not drop when either predicate could be true", canDrop(and(x, y), ccmd, dictionaries)); + assertThat(canDrop(and(B, y), ccmd, dictionaries)) + .as("Should drop when either predicate must be false") + .isTrue(); + assertThat(canDrop(and(x, C), ccmd, dictionaries)) + .as("Should drop when either predicate must be false") + .isTrue(); + assertThat(canDrop(and(B, C), ccmd, dictionaries)) + .as("Should drop when either predicate must be false") + .isTrue(); + assertThat(canDrop(and(x, y), ccmd, dictionaries)) + .as("Should not drop when either predicate could be true") + .isFalse(); } @Test @@ -1084,10 +1260,18 @@ public void testContainsOr() throws Exception { Operators.Contains x = contains(eq(col, Binary.fromString("x"))); Operators.Contains y = contains(eq(col, Binary.fromString("y"))); - assertFalse("Should not drop when one predicate could be true", canDrop(or(B, y), ccmd, dictionaries)); - assertFalse("Should not drop when one predicate could be true", canDrop(or(x, C), ccmd, dictionaries)); - assertTrue("Should drop when both predicates must be false", canDrop(or(B, C), ccmd, dictionaries)); - assertFalse("Should not drop when one predicate could be true", canDrop(or(x, y), ccmd, dictionaries)); + assertThat(canDrop(or(B, y), ccmd, dictionaries)) + .as("Should not drop when one predicate could be true") + .isFalse(); + assertThat(canDrop(or(x, C), ccmd, dictionaries)) + .as("Should not drop when one predicate could be true") + .isFalse(); + assertThat(canDrop(or(B, C), ccmd, dictionaries)) + .as("Should drop when both predicates must be false") + .isTrue(); + assertThat(canDrop(or(x, y), ccmd, dictionaries)) + .as("Should not drop when one predicate could be true") + .isFalse(); } private static final class InInt32UDP extends UserDefinedPredicate implements Serializable { diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/recordlevel/PhoneBookWriter.java b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/recordlevel/PhoneBookWriter.java index a0ecfa377d..aee901c3c7 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/recordlevel/PhoneBookWriter.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/recordlevel/PhoneBookWriter.java @@ -18,7 +18,7 @@ */ package org.apache.parquet.filter2.recordlevel; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; @@ -424,7 +424,9 @@ public static List readUsers(ParquetReader.Builder builder, boolean User u = userFromGroup(group); users.add(u); if (validateRowIndexes) { - assertEquals("Row index should be equal to User id", u.id, reader.getCurrentRowIndex()); + assertThat(reader.getCurrentRowIndex()) + .as("Row index should be equal to User id") + .isEqualTo(u.id); } } return users; diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/recordlevel/TestRecordLevelFilters.java b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/recordlevel/TestRecordLevelFilters.java index c69dce6917..3d6c0937ef 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/recordlevel/TestRecordLevelFilters.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/recordlevel/TestRecordLevelFilters.java @@ -34,7 +34,7 @@ import static org.apache.parquet.filter2.predicate.FilterApi.notIn; import static org.apache.parquet.filter2.predicate.FilterApi.or; import static org.apache.parquet.filter2.predicate.FilterApi.userDefined; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -149,11 +149,13 @@ private static List getExpected(UserFilter f) { private static void assertFilter(List found, UserFilter f) { List expected = getExpected(f); - assertEquals(expected.size(), found.size()); + assertThat(found).hasSameSizeAs(expected); Iterator expectedIter = expected.iterator(); Iterator foundIter = found.iterator(); while (expectedIter.hasNext()) { - assertEquals(expectedIter.next().toString(), foundIter.next().toString()); + assertThat(foundIter.next()) + .asString() + .isEqualTo(expectedIter.next().toString()); } } @@ -164,9 +166,9 @@ private static void assertPredicate(FilterPredicate predicate, long... expectedI private static void assertPredicate(File file, FilterPredicate predicate, long... expectedIds) throws IOException { List found = PhoneBookWriter.readFile(file, FilterCompat.get(predicate)); - assertEquals(expectedIds.length, found.size()); + assertThat(found).hasSameSizeAs(expectedIds); for (int i = 0; i < expectedIds.length; i++) { - assertEquals(expectedIds[i], found.get(i).getLong("id", 0)); + assertThat(found.get(i).getLong("id", 0)).isEqualTo(expectedIds[i]); } } @@ -217,7 +219,7 @@ public void testAllFilter() throws Exception { FilterPredicate pred = eq(name, Binary.fromString("no matches")); List found = PhoneBookWriter.readFile(phonebookFile, FilterCompat.get(pred)); - assertEquals(new ArrayList(), found); + assertThat(found).isEmpty(); } @Test @@ -245,10 +247,10 @@ public void testInFilter() throws Exception { // validate that all the values returned by the reader fulfills the filter and there are no values left out, // i.e. "thing1", "thing2" and from "p100" to "p199" and nothing else. - assertEquals(expectedNames.get(0), ((Group) (found.get(0))).getString("name", 0)); - assertEquals(expectedNames.get(1), ((Group) (found.get(1))).getString("name", 0)); + assertThat(((Group) (found.get(0))).getString("name", 0)).isEqualTo(expectedNames.get(0)); + assertThat(((Group) (found.get(1))).getString("name", 0)).isEqualTo(expectedNames.get(1)); for (int i = 2; i < 102; i++) { - assertEquals(expectedNames.get(i), ((Group) (found.get(i))).getString("name", 0)); + assertThat(((Group) (found.get(i))).getString("name", 0)).isEqualTo(expectedNames.get(i)); } assert (found.size() == 102); } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/statisticslevel/TestStatisticsFilter.java b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/statisticslevel/TestStatisticsFilter.java index 3cbccb13c5..81bd071595 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/statisticslevel/TestStatisticsFilter.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/statisticslevel/TestStatisticsFilter.java @@ -38,10 +38,7 @@ import static org.apache.parquet.filter2.statisticslevel.StatisticsFilter.canDrop; import static org.apache.parquet.io.api.Binary.fromString; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.HashSet; import java.util.List; @@ -141,17 +138,17 @@ private static ColumnChunkMetaData getDoubleColumnMeta( @Test public void testEqNonNull() { - assertTrue(canDrop(eq(intColumn, 9), columnMetas)); - assertFalse(canDrop(eq(intColumn, 10), columnMetas)); - assertFalse(canDrop(eq(intColumn, 100), columnMetas)); - assertTrue(canDrop(eq(intColumn, 101), columnMetas)); + assertThat(canDrop(eq(intColumn, 9), columnMetas)).isTrue(); + assertThat(canDrop(eq(intColumn, 10), columnMetas)).isFalse(); + assertThat(canDrop(eq(intColumn, 100), columnMetas)).isFalse(); + assertThat(canDrop(eq(intColumn, 101), columnMetas)).isTrue(); // drop columns of all nulls when looking for non-null value - assertTrue(canDrop(eq(intColumn, 0), nullColumnMetas)); - assertTrue(canDrop(eq(missingColumn, fromString("any")), columnMetas)); + assertThat(canDrop(eq(intColumn, 0), nullColumnMetas)).isTrue(); + assertThat(canDrop(eq(missingColumn, fromString("any")), columnMetas)).isTrue(); - assertFalse(canDrop(eq(intColumn, 50), missingMinMaxColumnMetas)); - assertFalse(canDrop(eq(doubleColumn, 50.0), missingMinMaxColumnMetas)); + assertThat(canDrop(eq(intColumn, 50), missingMinMaxColumnMetas)).isFalse(); + assertThat(canDrop(eq(doubleColumn, 50.0), missingMinMaxColumnMetas)).isFalse(); } @Test @@ -164,47 +161,53 @@ public void testEqNull() { statsSomeNulls.setMinMax(10, 100); statsSomeNulls.setNumNulls(3); - assertTrue(canDrop( - eq(intColumn, null), - List.of(getIntColumnMeta(statsNoNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + eq(intColumn, null), + List.of(getIntColumnMeta(statsNoNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); - assertFalse(canDrop( - eq(intColumn, null), - List.of(getIntColumnMeta(statsSomeNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + eq(intColumn, null), + List.of(getIntColumnMeta(statsSomeNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); - assertFalse(canDrop(eq(missingColumn, null), columnMetas)); + assertThat(canDrop(eq(missingColumn, null), columnMetas)).isFalse(); - assertFalse(canDrop(eq(intColumn, null), missingMinMaxColumnMetas)); - assertFalse(canDrop(eq(doubleColumn, null), missingMinMaxColumnMetas)); + assertThat(canDrop(eq(intColumn, null), missingMinMaxColumnMetas)).isFalse(); + assertThat(canDrop(eq(doubleColumn, null), missingMinMaxColumnMetas)).isFalse(); } @Test public void testNotEqNonNull() { - assertFalse(canDrop(notEq(intColumn, 9), columnMetas)); - assertFalse(canDrop(notEq(intColumn, 10), columnMetas)); - assertFalse(canDrop(notEq(intColumn, 100), columnMetas)); - assertFalse(canDrop(notEq(intColumn, 101), columnMetas)); + assertThat(canDrop(notEq(intColumn, 9), columnMetas)).isFalse(); + assertThat(canDrop(notEq(intColumn, 10), columnMetas)).isFalse(); + assertThat(canDrop(notEq(intColumn, 100), columnMetas)).isFalse(); + assertThat(canDrop(notEq(intColumn, 101), columnMetas)).isFalse(); IntStatistics allSevens = new IntStatistics(); allSevens.setMinMax(7, 7); - assertTrue(canDrop( - notEq(intColumn, 7), - List.of(getIntColumnMeta(allSevens, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + notEq(intColumn, 7), + List.of(getIntColumnMeta(allSevens, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); allSevens.setNumNulls(100L); - assertFalse(canDrop( - notEq(intColumn, 7), - List.of(getIntColumnMeta(allSevens, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + notEq(intColumn, 7), + List.of(getIntColumnMeta(allSevens, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); allSevens.setNumNulls(177L); - assertFalse(canDrop( - notEq(intColumn, 7), - List.of(getIntColumnMeta(allSevens, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + notEq(intColumn, 7), + List.of(getIntColumnMeta(allSevens, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); - assertFalse(canDrop(notEq(missingColumn, fromString("any")), columnMetas)); + assertThat(canDrop(notEq(missingColumn, fromString("any")), columnMetas)) + .isFalse(); - assertFalse(canDrop(notEq(intColumn, 50), missingMinMaxColumnMetas)); - assertFalse(canDrop(notEq(doubleColumn, 50.0), missingMinMaxColumnMetas)); + assertThat(canDrop(notEq(intColumn, 50), missingMinMaxColumnMetas)).isFalse(); + assertThat(canDrop(notEq(doubleColumn, 50.0), missingMinMaxColumnMetas)).isFalse(); } @Test @@ -221,86 +224,89 @@ public void testNotEqNull() { statsAllNulls.setMinMax(0, 0); statsAllNulls.setNumNulls(177); - assertFalse(canDrop( - notEq(intColumn, null), - List.of(getIntColumnMeta(statsNoNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + notEq(intColumn, null), + List.of(getIntColumnMeta(statsNoNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); - assertFalse(canDrop( - notEq(intColumn, null), - List.of(getIntColumnMeta(statsSomeNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + notEq(intColumn, null), + List.of(getIntColumnMeta(statsSomeNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); - assertTrue(canDrop( - notEq(intColumn, null), - List.of(getIntColumnMeta(statsAllNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + notEq(intColumn, null), + List.of(getIntColumnMeta(statsAllNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); - assertTrue(canDrop(notEq(missingColumn, null), columnMetas)); + assertThat(canDrop(notEq(missingColumn, null), columnMetas)).isTrue(); - assertFalse(canDrop(notEq(intColumn, null), missingMinMaxColumnMetas)); - assertFalse(canDrop(notEq(doubleColumn, null), missingMinMaxColumnMetas)); + assertThat(canDrop(notEq(intColumn, null), missingMinMaxColumnMetas)).isFalse(); + assertThat(canDrop(notEq(doubleColumn, null), missingMinMaxColumnMetas)).isFalse(); } @Test public void testLt() { - assertTrue(canDrop(lt(intColumn, 9), columnMetas)); - assertTrue(canDrop(lt(intColumn, 10), columnMetas)); - assertFalse(canDrop(lt(intColumn, 100), columnMetas)); - assertFalse(canDrop(lt(intColumn, 101), columnMetas)); + assertThat(canDrop(lt(intColumn, 9), columnMetas)).isTrue(); + assertThat(canDrop(lt(intColumn, 10), columnMetas)).isTrue(); + assertThat(canDrop(lt(intColumn, 100), columnMetas)).isFalse(); + assertThat(canDrop(lt(intColumn, 101), columnMetas)).isFalse(); - assertTrue(canDrop(lt(intColumn, 0), nullColumnMetas)); - assertTrue(canDrop(lt(intColumn, 7), nullColumnMetas)); + assertThat(canDrop(lt(intColumn, 0), nullColumnMetas)).isTrue(); + assertThat(canDrop(lt(intColumn, 7), nullColumnMetas)).isTrue(); - assertTrue(canDrop(lt(missingColumn, fromString("any")), columnMetas)); + assertThat(canDrop(lt(missingColumn, fromString("any")), columnMetas)).isTrue(); - assertFalse(canDrop(lt(intColumn, 0), missingMinMaxColumnMetas)); - assertFalse(canDrop(lt(doubleColumn, 0.0), missingMinMaxColumnMetas)); + assertThat(canDrop(lt(intColumn, 0), missingMinMaxColumnMetas)).isFalse(); + assertThat(canDrop(lt(doubleColumn, 0.0), missingMinMaxColumnMetas)).isFalse(); } @Test public void testLtEq() { - assertTrue(canDrop(ltEq(intColumn, 9), columnMetas)); - assertFalse(canDrop(ltEq(intColumn, 10), columnMetas)); - assertFalse(canDrop(ltEq(intColumn, 100), columnMetas)); - assertFalse(canDrop(ltEq(intColumn, 101), columnMetas)); + assertThat(canDrop(ltEq(intColumn, 9), columnMetas)).isTrue(); + assertThat(canDrop(ltEq(intColumn, 10), columnMetas)).isFalse(); + assertThat(canDrop(ltEq(intColumn, 100), columnMetas)).isFalse(); + assertThat(canDrop(ltEq(intColumn, 101), columnMetas)).isFalse(); - assertTrue(canDrop(ltEq(intColumn, 0), nullColumnMetas)); - assertTrue(canDrop(ltEq(intColumn, 7), nullColumnMetas)); + assertThat(canDrop(ltEq(intColumn, 0), nullColumnMetas)).isTrue(); + assertThat(canDrop(ltEq(intColumn, 7), nullColumnMetas)).isTrue(); - assertTrue(canDrop(ltEq(missingColumn, fromString("any")), columnMetas)); + assertThat(canDrop(ltEq(missingColumn, fromString("any")), columnMetas)).isTrue(); - assertFalse(canDrop(ltEq(intColumn, -1), missingMinMaxColumnMetas)); - assertFalse(canDrop(ltEq(doubleColumn, -0.1), missingMinMaxColumnMetas)); + assertThat(canDrop(ltEq(intColumn, -1), missingMinMaxColumnMetas)).isFalse(); + assertThat(canDrop(ltEq(doubleColumn, -0.1), missingMinMaxColumnMetas)).isFalse(); } @Test public void testGt() { - assertFalse(canDrop(gt(intColumn, 9), columnMetas)); - assertFalse(canDrop(gt(intColumn, 10), columnMetas)); - assertTrue(canDrop(gt(intColumn, 100), columnMetas)); - assertTrue(canDrop(gt(intColumn, 101), columnMetas)); + assertThat(canDrop(gt(intColumn, 9), columnMetas)).isFalse(); + assertThat(canDrop(gt(intColumn, 10), columnMetas)).isFalse(); + assertThat(canDrop(gt(intColumn, 100), columnMetas)).isTrue(); + assertThat(canDrop(gt(intColumn, 101), columnMetas)).isTrue(); - assertTrue(canDrop(gt(intColumn, 0), nullColumnMetas)); - assertTrue(canDrop(gt(intColumn, 7), nullColumnMetas)); + assertThat(canDrop(gt(intColumn, 0), nullColumnMetas)).isTrue(); + assertThat(canDrop(gt(intColumn, 7), nullColumnMetas)).isTrue(); - assertTrue(canDrop(gt(missingColumn, fromString("any")), columnMetas)); + assertThat(canDrop(gt(missingColumn, fromString("any")), columnMetas)).isTrue(); - assertFalse(canDrop(gt(intColumn, 0), missingMinMaxColumnMetas)); - assertFalse(canDrop(gt(doubleColumn, 0.0), missingMinMaxColumnMetas)); + assertThat(canDrop(gt(intColumn, 0), missingMinMaxColumnMetas)).isFalse(); + assertThat(canDrop(gt(doubleColumn, 0.0), missingMinMaxColumnMetas)).isFalse(); } @Test public void testGtEq() { - assertFalse(canDrop(gtEq(intColumn, 9), columnMetas)); - assertFalse(canDrop(gtEq(intColumn, 10), columnMetas)); - assertFalse(canDrop(gtEq(intColumn, 100), columnMetas)); - assertTrue(canDrop(gtEq(intColumn, 101), columnMetas)); + assertThat(canDrop(gtEq(intColumn, 9), columnMetas)).isFalse(); + assertThat(canDrop(gtEq(intColumn, 10), columnMetas)).isFalse(); + assertThat(canDrop(gtEq(intColumn, 100), columnMetas)).isFalse(); + assertThat(canDrop(gtEq(intColumn, 101), columnMetas)).isTrue(); - assertTrue(canDrop(gtEq(intColumn, 0), nullColumnMetas)); - assertTrue(canDrop(gtEq(intColumn, 7), nullColumnMetas)); + assertThat(canDrop(gtEq(intColumn, 0), nullColumnMetas)).isTrue(); + assertThat(canDrop(gtEq(intColumn, 7), nullColumnMetas)).isTrue(); - assertTrue(canDrop(gtEq(missingColumn, fromString("any")), columnMetas)); + assertThat(canDrop(gtEq(missingColumn, fromString("any")), columnMetas)).isTrue(); - assertFalse(canDrop(gtEq(intColumn, 1), missingMinMaxColumnMetas)); - assertFalse(canDrop(gtEq(doubleColumn, 0.1), missingMinMaxColumnMetas)); + assertThat(canDrop(gtEq(intColumn, 1), missingMinMaxColumnMetas)).isFalse(); + assertThat(canDrop(gtEq(doubleColumn, 0.1), missingMinMaxColumnMetas)).isFalse(); } @Test @@ -311,8 +317,8 @@ public void testInNotIn() { values1.add(15); values1.add(17); values1.add(19); - assertFalse(canDrop(in(intColumn, values1), columnMetas)); - assertFalse(canDrop(notIn(intColumn, values1), columnMetas)); + assertThat(canDrop(in(intColumn, values1), columnMetas)).isFalse(); + assertThat(canDrop(notIn(intColumn, values1), columnMetas)).isFalse(); Set values2 = new HashSet<>(); values2.add(109); @@ -320,8 +326,8 @@ public void testInNotIn() { values2.add(5); values2.add(117); values2.add(101); - assertFalse(canDrop(in(intColumn, values2), columnMetas)); - assertFalse(canDrop(notIn(intColumn, values2), columnMetas)); + assertThat(canDrop(in(intColumn, values2), columnMetas)).isFalse(); + assertThat(canDrop(notIn(intColumn, values2), columnMetas)).isFalse(); Set values3 = new HashSet<>(); values3.add(1); @@ -329,14 +335,14 @@ public void testInNotIn() { values3.add(5); values3.add(7); values3.add(10); - assertFalse(canDrop(in(intColumn, values3), columnMetas)); - assertFalse(canDrop(notIn(intColumn, values3), columnMetas)); + assertThat(canDrop(in(intColumn, values3), columnMetas)).isFalse(); + assertThat(canDrop(notIn(intColumn, values3), columnMetas)).isFalse(); Set values4 = new HashSet<>(); values4.add(50); values4.add(60); - assertFalse(canDrop(in(intColumn, values4), missingMinMaxColumnMetas)); - assertFalse(canDrop(notIn(intColumn, values4), missingMinMaxColumnMetas)); + assertThat(canDrop(in(intColumn, values4), missingMinMaxColumnMetas)).isFalse(); + assertThat(canDrop(notIn(intColumn, values4), missingMinMaxColumnMetas)).isFalse(); Set values5 = new HashSet<>(); values5.add(1.0); @@ -344,24 +350,24 @@ public void testInNotIn() { values5.add(95.0); values5.add(107.0); values5.add(99.0); - assertFalse(canDrop(in(doubleColumn, values5), columnMetas)); - assertFalse(canDrop(notIn(doubleColumn, values5), columnMetas)); + assertThat(canDrop(in(doubleColumn, values5), columnMetas)).isFalse(); + assertThat(canDrop(notIn(doubleColumn, values5), columnMetas)).isFalse(); Set values6 = new HashSet<>(); values6.add(Binary.fromString("test1")); values6.add(Binary.fromString("test2")); - assertTrue(canDrop(in(missingColumn, values6), columnMetas)); - assertFalse(canDrop(notIn(missingColumn, values6), columnMetas)); + assertThat(canDrop(in(missingColumn, values6), columnMetas)).isTrue(); + assertThat(canDrop(notIn(missingColumn, values6), columnMetas)).isFalse(); Set values7 = new HashSet<>(); values7.add(null); - assertFalse(canDrop(in(intColumn, values7), nullColumnMetas)); - assertFalse(canDrop(notIn(intColumn, values7), nullColumnMetas)); + assertThat(canDrop(in(intColumn, values7), nullColumnMetas)).isFalse(); + assertThat(canDrop(notIn(intColumn, values7), nullColumnMetas)).isFalse(); Set values8 = new HashSet<>(); values8.add(null); - assertFalse(canDrop(in(missingColumn, values8), columnMetas)); - assertFalse(canDrop(notIn(missingColumn, values8), columnMetas)); + assertThat(canDrop(in(missingColumn, values8), columnMetas)).isFalse(); + assertThat(canDrop(notIn(missingColumn, values8), columnMetas)).isFalse(); IntStatistics statsNoNulls = new IntStatistics(); statsNoNulls.setMinMax(10, 100); @@ -373,21 +379,25 @@ public void testInNotIn() { Set values9 = new HashSet<>(); values9.add(null); - assertTrue(canDrop( - in(intColumn, values9), - List.of(getIntColumnMeta(statsNoNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))); - - assertFalse(canDrop( - notIn(intColumn, values9), - List.of(getIntColumnMeta(statsNoNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))); - - assertFalse(canDrop( - in(intColumn, values9), - List.of(getIntColumnMeta(statsSomeNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))); - - assertFalse(canDrop( - notIn(intColumn, values9), - List.of(getIntColumnMeta(statsSomeNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + in(intColumn, values9), + List.of(getIntColumnMeta(statsNoNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); + + assertThat(canDrop( + notIn(intColumn, values9), + List.of(getIntColumnMeta(statsNoNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); + + assertThat(canDrop( + in(intColumn, values9), + List.of(getIntColumnMeta(statsSomeNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); + + assertThat(canDrop( + notIn(intColumn, values9), + List.of(getIntColumnMeta(statsSomeNulls, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); } @Test @@ -431,54 +441,55 @@ public void testInWithNullLiteralAndUnsetNumNulls() { @Test public void testContainsEqNonNull() { - assertTrue(canDrop(contains(eq(intColumn, 9)), columnMetas)); - assertFalse(canDrop(contains(eq(intColumn, 10)), columnMetas)); - assertFalse(canDrop(contains(eq(intColumn, 100)), columnMetas)); - assertTrue(canDrop(contains(eq(intColumn, 101)), columnMetas)); + assertThat(canDrop(contains(eq(intColumn, 9)), columnMetas)).isTrue(); + assertThat(canDrop(contains(eq(intColumn, 10)), columnMetas)).isFalse(); + assertThat(canDrop(contains(eq(intColumn, 100)), columnMetas)).isFalse(); + assertThat(canDrop(contains(eq(intColumn, 101)), columnMetas)).isTrue(); // drop columns of all nulls when looking for non-null value - assertTrue(canDrop(contains(eq(intColumn, 0)), nullColumnMetas)); - assertFalse(canDrop(contains(eq(intColumn, 50)), missingMinMaxColumnMetas)); + assertThat(canDrop(contains(eq(intColumn, 0)), nullColumnMetas)).isTrue(); + assertThat(canDrop(contains(eq(intColumn, 50)), missingMinMaxColumnMetas)) + .isFalse(); } @Test public void testContainsAnd() { Operators.Contains yes = contains(eq(intColumn, 9)); Operators.Contains no = contains(eq(doubleColumn, 50D)); - assertTrue(canDrop(and(yes, yes), columnMetas)); - assertTrue(canDrop(and(yes, no), columnMetas)); - assertTrue(canDrop(and(no, yes), columnMetas)); - assertFalse(canDrop(and(no, no), columnMetas)); + assertThat(canDrop(and(yes, yes), columnMetas)).isTrue(); + assertThat(canDrop(and(yes, no), columnMetas)).isTrue(); + assertThat(canDrop(and(no, yes), columnMetas)).isTrue(); + assertThat(canDrop(and(no, no), columnMetas)).isFalse(); } @Test public void testContainsOr() { Operators.Contains yes = contains(eq(intColumn, 9)); Operators.Contains no = contains(eq(doubleColumn, 50D)); - assertTrue(canDrop(or(yes, yes), columnMetas)); - assertFalse(canDrop(or(yes, no), columnMetas)); - assertFalse(canDrop(or(no, yes), columnMetas)); - assertFalse(canDrop(or(no, no), columnMetas)); + assertThat(canDrop(or(yes, yes), columnMetas)).isTrue(); + assertThat(canDrop(or(yes, no), columnMetas)).isFalse(); + assertThat(canDrop(or(no, yes), columnMetas)).isFalse(); + assertThat(canDrop(or(no, no), columnMetas)).isFalse(); } @Test public void testAnd() { FilterPredicate yes = eq(intColumn, 9); FilterPredicate no = eq(doubleColumn, 50D); - assertTrue(canDrop(and(yes, yes), columnMetas)); - assertTrue(canDrop(and(yes, no), columnMetas)); - assertTrue(canDrop(and(no, yes), columnMetas)); - assertFalse(canDrop(and(no, no), columnMetas)); + assertThat(canDrop(and(yes, yes), columnMetas)).isTrue(); + assertThat(canDrop(and(yes, no), columnMetas)).isTrue(); + assertThat(canDrop(and(no, yes), columnMetas)).isTrue(); + assertThat(canDrop(and(no, no), columnMetas)).isFalse(); } @Test public void testOr() { FilterPredicate yes = eq(intColumn, 9); FilterPredicate no = eq(doubleColumn, 50D); - assertTrue(canDrop(or(yes, yes), columnMetas)); - assertFalse(canDrop(or(yes, no), columnMetas)); - assertFalse(canDrop(or(no, yes), columnMetas)); - assertFalse(canDrop(or(no, no), columnMetas)); + assertThat(canDrop(or(yes, yes), columnMetas)).isTrue(); + assertThat(canDrop(or(yes, no), columnMetas)).isFalse(); + assertThat(canDrop(or(no, yes), columnMetas)).isFalse(); + assertThat(canDrop(or(no, no), columnMetas)).isFalse(); } public static class SevensAndEightsUdp extends UserDefinedPredicate { @@ -556,67 +567,89 @@ public void testUdp() { IntStatistics neither = new IntStatistics(); neither.setMinMax(1, 2); - assertTrue(canDrop(pred, List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop(pred, List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); - assertFalse(canDrop(pred, List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop(pred, List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); - assertFalse(canDrop(pred, List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop(pred, List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); - assertFalse(canDrop(invPred, List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop(invPred, List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); - assertTrue(canDrop(invPred, List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop(invPred, List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); - assertFalse(canDrop(invPred, List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop(invPred, List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); // udpDropMissingColumn drops null column. - assertTrue(canDrop( - udpDropMissingColumn, List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + udpDropMissingColumn, + List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); - assertTrue(canDrop( - udpDropMissingColumn, List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + udpDropMissingColumn, + List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); - assertTrue(canDrop( - udpDropMissingColumn, - List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + udpDropMissingColumn, + List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); // invUdpDropMissingColumn (i.e., not(udpDropMissingColumn)) keeps null column. - assertFalse(canDrop( - invUdpDropMissingColumn, - List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + invUdpDropMissingColumn, + List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); - assertFalse(canDrop( - invUdpDropMissingColumn, - List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + invUdpDropMissingColumn, + List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); - assertFalse(canDrop( - invUdpDropMissingColumn, - List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + invUdpDropMissingColumn, + List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); // udpKeepMissingColumn keeps null column. - assertFalse(canDrop( - udpKeepMissingColumn, List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + udpKeepMissingColumn, + List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); - assertFalse(canDrop( - udpKeepMissingColumn, List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + udpKeepMissingColumn, + List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); - assertFalse(canDrop( - udpKeepMissingColumn, - List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))); + assertThat(canDrop( + udpKeepMissingColumn, + List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isFalse(); // invUdpKeepMissingColumn (i.e., not(udpKeepMissingColumn)) drops null column. - assertTrue(canDrop( - invUdpKeepMissingColumn, - List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))); - - assertTrue(canDrop( - invUdpKeepMissingColumn, - List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))); - - assertTrue(canDrop( - invUdpKeepMissingColumn, - List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))); - - assertFalse(canDrop(allPositivePred, missingMinMaxColumnMetas)); + assertThat(canDrop( + invUdpKeepMissingColumn, + List.of(getIntColumnMeta(seven, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); + + assertThat(canDrop( + invUdpKeepMissingColumn, + List.of(getIntColumnMeta(eight, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); + + assertThat(canDrop( + invUdpKeepMissingColumn, + List.of(getIntColumnMeta(neither, 177L), getDoubleColumnMeta(doubleStats, 177L)))) + .isTrue(); + + assertThat(canDrop(allPositivePred, missingMinMaxColumnMetas)).isFalse(); } @Test @@ -626,15 +659,11 @@ public void testClearExceptionForNots() { FilterPredicate pred = and(not(eq(doubleColumn, 12.0)), eq(intColumn, 17)); - try { - canDrop(pred, columnMetas); - fail("This should throw"); - } catch (IllegalArgumentException e) { - assertEquals( - "This predicate contains a not! Did you forget to run this predicate through LogicalInverseRewriter?" - + " not(eq(double.column, 12.0))", - e.getMessage()); - } + assertThatThrownBy(() -> canDrop(pred, columnMetas)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage( + "This predicate contains a not! Did you forget to run this predicate through LogicalInverseRewriter?" + + " not(eq(double.column, 12.0))"); } private static final FloatColumn floatCol = floatColumn("float.column"); @@ -682,21 +711,23 @@ public void testNaNDoubleAllNaN() { List metas = List.of(getIntColumnMeta(intStats, 177L), getDoubleColumnMeta(allNanStats, 177L)); - assertTrue(canDrop(eq(doubleColumn, 5.0), metas)); - assertFalse(canDrop(notEq(doubleColumn, 5.0), metas)); - assertFalse(canDrop(lt(doubleColumn, 5.0), metas)); - assertFalse(canDrop(ltEq(doubleColumn, 5.0), metas)); - assertFalse(canDrop(gt(doubleColumn, 5.0), metas)); - assertFalse(canDrop(gtEq(doubleColumn, 5.0), metas)); - assertTrue(canDrop(in(doubleColumn, new HashSet<>(List.of(5.0))), metas)); - - assertFalse(canDrop(eq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(notEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(lt(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(ltEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(gt(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(gtEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(in(doubleColumn, new HashSet<>(List.of(Double.NaN))), metas)); + assertThat(canDrop(eq(doubleColumn, 5.0), metas)).isTrue(); + assertThat(canDrop(notEq(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(lt(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(ltEq(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(gt(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(gtEq(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(in(doubleColumn, new HashSet<>(List.of(5.0))), metas)) + .isTrue(); + + assertThat(canDrop(eq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(notEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(lt(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(ltEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(gt(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(gtEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(in(doubleColumn, new HashSet<>(List.of(Double.NaN))), metas)) + .isFalse(); } @Test @@ -711,15 +742,16 @@ public void testNaNDoubleMixed() { List.of(getIntColumnMeta(intStats, 177L), getDoubleColumnMeta(mixedStats, 177L)); // Non-NaN literal within range: cannot drop - assertFalse(canDrop(eq(doubleColumn, 50.0), metas)); - assertFalse(canDrop(notEq(doubleColumn, 50.0), metas)); - assertFalse(canDrop(lt(doubleColumn, 50.0), metas)); - assertFalse(canDrop(ltEq(doubleColumn, 50.0), metas)); - assertFalse(canDrop(gt(doubleColumn, 50.0), metas)); - assertFalse(canDrop(gtEq(doubleColumn, 50.0), metas)); - assertFalse(canDrop(in(doubleColumn, new HashSet<>(List.of(50.0))), metas)); - assertFalse(canDrop(lt(doubleColumn, 0.0), metas)); - assertFalse(canDrop(gt(doubleColumn, 200.0), metas)); + assertThat(canDrop(eq(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(notEq(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(lt(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(ltEq(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(gt(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(gtEq(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(in(doubleColumn, new HashSet<>(List.of(50.0))), metas)) + .isFalse(); + assertThat(canDrop(lt(doubleColumn, 0.0), metas)).isFalse(); + assertThat(canDrop(gt(doubleColumn, 200.0), metas)).isFalse(); DoubleStatistics mixedEqualStats = new DoubleStatistics(); mixedEqualStats.setMinMax(5.0, 5.0); @@ -727,16 +759,17 @@ public void testNaNDoubleMixed() { mixedEqualStats.incrementNanCount(1); List mixedEqualMetas = List.of(getIntColumnMeta(intStats, 177L), getDoubleColumnMeta(mixedEqualStats, 177L)); - assertFalse(canDrop(notEq(doubleColumn, 5.0), mixedEqualMetas)); + assertThat(canDrop(notEq(doubleColumn, 5.0), mixedEqualMetas)).isFalse(); // NaN literal: NaN values are present so cannot drop - assertFalse(canDrop(eq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(notEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(lt(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(ltEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(gt(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(gtEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(in(doubleColumn, new HashSet<>(List.of(Double.NaN))), metas)); + assertThat(canDrop(eq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(notEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(lt(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(ltEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(gt(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(gtEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(in(doubleColumn, new HashSet<>(List.of(Double.NaN))), metas)) + .isFalse(); } @Test @@ -752,12 +785,12 @@ public void testNaNDoubleMissingNaNCountIsConservative() { List metas = List.of(getIntColumnMeta(intStats, 177L), getDoubleColumnMeta(statsWithUnknownNaNs, 177L)); - assertFalse(canDrop(eq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(notEq(doubleColumn, 5.0), metas)); - assertFalse(canDrop(lt(doubleColumn, 5.0), metas)); - assertFalse(canDrop(ltEq(doubleColumn, 5.0), metas)); - assertFalse(canDrop(gt(doubleColumn, 200.0), metas)); - assertFalse(canDrop(gtEq(doubleColumn, 200.0), metas)); + assertThat(canDrop(eq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(notEq(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(lt(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(ltEq(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(gt(doubleColumn, 200.0), metas)).isFalse(); + assertThat(canDrop(gtEq(doubleColumn, 200.0), metas)).isFalse(); } @Test @@ -771,21 +804,23 @@ public void testNaNDoubleZeroNaNCount() { List metas = List.of(getIntColumnMeta(intStats, 177L), getDoubleColumnMeta(zeroNanStats, 177L)); - assertFalse(canDrop(eq(doubleColumn, 50.0), metas)); - assertFalse(canDrop(notEq(doubleColumn, 50.0), metas)); - assertFalse(canDrop(lt(doubleColumn, 50.0), metas)); - assertFalse(canDrop(ltEq(doubleColumn, 50.0), metas)); - assertFalse(canDrop(gt(doubleColumn, 50.0), metas)); - assertFalse(canDrop(gtEq(doubleColumn, 50.0), metas)); - assertFalse(canDrop(in(doubleColumn, new HashSet<>(List.of(50.0))), metas)); - - assertTrue(canDrop(eq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(notEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(lt(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(ltEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(gt(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(gtEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(in(doubleColumn, new HashSet<>(List.of(Double.NaN))), metas)); + assertThat(canDrop(eq(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(notEq(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(lt(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(ltEq(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(gt(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(gtEq(doubleColumn, 50.0), metas)).isFalse(); + assertThat(canDrop(in(doubleColumn, new HashSet<>(List.of(50.0))), metas)) + .isFalse(); + + assertThat(canDrop(eq(doubleColumn, Double.NaN), metas)).isTrue(); + assertThat(canDrop(notEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(lt(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(ltEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(gt(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(gtEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(in(doubleColumn, new HashSet<>(List.of(Double.NaN))), metas)) + .isFalse(); } @Test @@ -803,21 +838,23 @@ public void testNaNDoubleIeee754TotalOrder() { List metas = List.of(getIntColumnMeta(intStats, 177L), getDoubleColumnMetaWithType(ieee754Type, allNanStats, 177L)); - assertTrue(canDrop(eq(doubleColumn, 5.0), metas)); - assertFalse(canDrop(notEq(doubleColumn, 5.0), metas)); - assertFalse(canDrop(lt(doubleColumn, 5.0), metas)); - assertFalse(canDrop(ltEq(doubleColumn, 5.0), metas)); - assertFalse(canDrop(gt(doubleColumn, 5.0), metas)); - assertFalse(canDrop(gtEq(doubleColumn, 5.0), metas)); - assertTrue(canDrop(in(doubleColumn, new HashSet<>(List.of(5.0))), metas)); - - assertFalse(canDrop(eq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(notEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(lt(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(ltEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(gt(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(gtEq(doubleColumn, Double.NaN), metas)); - assertFalse(canDrop(in(doubleColumn, new HashSet<>(List.of(Double.NaN))), metas)); + assertThat(canDrop(eq(doubleColumn, 5.0), metas)).isTrue(); + assertThat(canDrop(notEq(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(lt(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(ltEq(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(gt(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(gtEq(doubleColumn, 5.0), metas)).isFalse(); + assertThat(canDrop(in(doubleColumn, new HashSet<>(List.of(5.0))), metas)) + .isTrue(); + + assertThat(canDrop(eq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(notEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(lt(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(ltEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(gt(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(gtEq(doubleColumn, Double.NaN), metas)).isFalse(); + assertThat(canDrop(in(doubleColumn, new HashSet<>(List.of(Double.NaN))), metas)) + .isFalse(); } // ========================= Float NaN Tests ========================= @@ -832,21 +869,22 @@ public void testNaNFloatAllNaN() { List metas = List.of(getIntColumnMeta(intStats, 177L), getFloatColumnMeta(allNanStats, 177L)); - assertTrue(canDrop(eq(floatCol, 5.0f), metas)); - assertFalse(canDrop(notEq(floatCol, 5.0f), metas)); - assertFalse(canDrop(lt(floatCol, 5.0f), metas)); - assertFalse(canDrop(ltEq(floatCol, 5.0f), metas)); - assertFalse(canDrop(gt(floatCol, 5.0f), metas)); - assertFalse(canDrop(gtEq(floatCol, 5.0f), metas)); - assertTrue(canDrop(in(floatCol, new HashSet<>(List.of(5.0f))), metas)); - - assertFalse(canDrop(eq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(notEq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(lt(floatCol, Float.NaN), metas)); - assertFalse(canDrop(ltEq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(gt(floatCol, Float.NaN), metas)); - assertFalse(canDrop(gtEq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(in(floatCol, new HashSet<>(List.of(Float.NaN))), metas)); + assertThat(canDrop(eq(floatCol, 5.0f), metas)).isTrue(); + assertThat(canDrop(notEq(floatCol, 5.0f), metas)).isFalse(); + assertThat(canDrop(lt(floatCol, 5.0f), metas)).isFalse(); + assertThat(canDrop(ltEq(floatCol, 5.0f), metas)).isFalse(); + assertThat(canDrop(gt(floatCol, 5.0f), metas)).isFalse(); + assertThat(canDrop(gtEq(floatCol, 5.0f), metas)).isFalse(); + assertThat(canDrop(in(floatCol, new HashSet<>(List.of(5.0f))), metas)).isTrue(); + + assertThat(canDrop(eq(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(notEq(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(lt(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(ltEq(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(gt(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(gtEq(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(in(floatCol, new HashSet<>(List.of(Float.NaN))), metas)) + .isFalse(); } @Test @@ -860,15 +898,15 @@ public void testNaNFloatMixed() { List metas = List.of(getIntColumnMeta(intStats, 177L), getFloatColumnMeta(mixedStats, 177L)); - assertFalse(canDrop(eq(floatCol, 50.0f), metas)); - assertFalse(canDrop(notEq(floatCol, 50.0f), metas)); - assertFalse(canDrop(lt(floatCol, 50.0f), metas)); - assertFalse(canDrop(ltEq(floatCol, 50.0f), metas)); - assertFalse(canDrop(gt(floatCol, 50.0f), metas)); - assertFalse(canDrop(gtEq(floatCol, 50.0f), metas)); - assertFalse(canDrop(in(floatCol, new HashSet<>(List.of(50.0f))), metas)); - assertFalse(canDrop(lt(floatCol, 0.0f), metas)); - assertFalse(canDrop(gt(floatCol, 200.0f), metas)); + assertThat(canDrop(eq(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(notEq(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(lt(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(ltEq(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(gt(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(gtEq(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(in(floatCol, new HashSet<>(List.of(50.0f))), metas)).isFalse(); + assertThat(canDrop(lt(floatCol, 0.0f), metas)).isFalse(); + assertThat(canDrop(gt(floatCol, 200.0f), metas)).isFalse(); FloatStatistics mixedEqualStats = new FloatStatistics(); mixedEqualStats.setMinMax(5.0f, 5.0f); @@ -876,15 +914,16 @@ public void testNaNFloatMixed() { mixedEqualStats.incrementNanCount(1); List mixedEqualMetas = List.of(getIntColumnMeta(intStats, 177L), getFloatColumnMeta(mixedEqualStats, 177L)); - assertFalse(canDrop(notEq(floatCol, 5.0f), mixedEqualMetas)); - - assertFalse(canDrop(eq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(notEq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(lt(floatCol, Float.NaN), metas)); - assertFalse(canDrop(ltEq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(gt(floatCol, Float.NaN), metas)); - assertFalse(canDrop(gtEq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(in(floatCol, new HashSet<>(List.of(Float.NaN))), metas)); + assertThat(canDrop(notEq(floatCol, 5.0f), mixedEqualMetas)).isFalse(); + + assertThat(canDrop(eq(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(notEq(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(lt(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(ltEq(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(gt(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(gtEq(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(in(floatCol, new HashSet<>(List.of(Float.NaN))), metas)) + .isFalse(); } @Test @@ -898,21 +937,22 @@ public void testNaNFloatZeroNaNCount() { List metas = List.of(getIntColumnMeta(intStats, 177L), getFloatColumnMeta(zeroNanStats, 177L)); - assertFalse(canDrop(eq(floatCol, 50.0f), metas)); - assertFalse(canDrop(notEq(floatCol, 50.0f), metas)); - assertFalse(canDrop(lt(floatCol, 50.0f), metas)); - assertFalse(canDrop(ltEq(floatCol, 50.0f), metas)); - assertFalse(canDrop(gt(floatCol, 50.0f), metas)); - assertFalse(canDrop(gtEq(floatCol, 50.0f), metas)); - assertFalse(canDrop(in(floatCol, new HashSet<>(List.of(50.0f))), metas)); - - assertTrue(canDrop(eq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(notEq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(lt(floatCol, Float.NaN), metas)); - assertFalse(canDrop(ltEq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(gt(floatCol, Float.NaN), metas)); - assertFalse(canDrop(gtEq(floatCol, Float.NaN), metas)); - assertFalse(canDrop(in(floatCol, new HashSet<>(List.of(Float.NaN))), metas)); + assertThat(canDrop(eq(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(notEq(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(lt(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(ltEq(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(gt(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(gtEq(floatCol, 50.0f), metas)).isFalse(); + assertThat(canDrop(in(floatCol, new HashSet<>(List.of(50.0f))), metas)).isFalse(); + + assertThat(canDrop(eq(floatCol, Float.NaN), metas)).isTrue(); + assertThat(canDrop(notEq(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(lt(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(ltEq(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(gt(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(gtEq(floatCol, Float.NaN), metas)).isFalse(); + assertThat(canDrop(in(floatCol, new HashSet<>(List.of(Float.NaN))), metas)) + .isFalse(); } // ========================= Float16 NaN Tests ========================= @@ -958,21 +998,23 @@ public void testNaNFloat16AllNaN() { ColumnChunkMetaData float16Meta = getFloat16ColumnMeta(allNanStats, 177L); List metas = List.of(getIntColumnMeta(intStats, 177L), float16Meta); - assertTrue(canDrop(eq(float16Column, FLOAT16_ONE), metas)); - assertFalse(canDrop(notEq(float16Column, FLOAT16_ONE), metas)); - assertFalse(canDrop(lt(float16Column, FLOAT16_ONE), metas)); - assertFalse(canDrop(ltEq(float16Column, FLOAT16_ONE), metas)); - assertFalse(canDrop(gt(float16Column, FLOAT16_ONE), metas)); - assertFalse(canDrop(gtEq(float16Column, FLOAT16_ONE), metas)); - assertTrue(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_ONE))), metas)); - - assertFalse(canDrop(eq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(notEq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(lt(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(ltEq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(gt(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(gtEq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_NAN))), metas)); + assertThat(canDrop(eq(float16Column, FLOAT16_ONE), metas)).isTrue(); + assertThat(canDrop(notEq(float16Column, FLOAT16_ONE), metas)).isFalse(); + assertThat(canDrop(lt(float16Column, FLOAT16_ONE), metas)).isFalse(); + assertThat(canDrop(ltEq(float16Column, FLOAT16_ONE), metas)).isFalse(); + assertThat(canDrop(gt(float16Column, FLOAT16_ONE), metas)).isFalse(); + assertThat(canDrop(gtEq(float16Column, FLOAT16_ONE), metas)).isFalse(); + assertThat(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_ONE))), metas)) + .isTrue(); + + assertThat(canDrop(eq(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(notEq(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(lt(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(ltEq(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(gt(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(gtEq(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_NAN))), metas)) + .isFalse(); } @Test @@ -989,21 +1031,23 @@ public void testNaNFloat16Mixed() { ColumnChunkMetaData float16Meta = getFloat16ColumnMeta(mixedStats, 177L); List metas = List.of(getIntColumnMeta(intStats, 177L), float16Meta); - assertFalse(canDrop(eq(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(notEq(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(lt(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(ltEq(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(gt(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(gtEq(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_FIFTY))), metas)); - - assertFalse(canDrop(eq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(notEq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(lt(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(ltEq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(gt(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(gtEq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_NAN))), metas)); + assertThat(canDrop(eq(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(notEq(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(lt(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(ltEq(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(gt(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(gtEq(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_FIFTY))), metas)) + .isFalse(); + + assertThat(canDrop(eq(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(notEq(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(lt(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(ltEq(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(gt(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(gtEq(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_NAN))), metas)) + .isFalse(); } @Test @@ -1020,20 +1064,22 @@ public void testNaNFloat16ZeroNaNCount() { ColumnChunkMetaData float16Meta = getFloat16ColumnMeta(zeroNanStats, 177L); List metas = List.of(getIntColumnMeta(intStats, 177L), float16Meta); - assertFalse(canDrop(eq(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(notEq(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(lt(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(ltEq(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(gt(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(gtEq(float16Column, FLOAT16_FIFTY), metas)); - assertFalse(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_FIFTY))), metas)); - - assertTrue(canDrop(eq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(notEq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(lt(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(ltEq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(gt(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(gtEq(float16Column, FLOAT16_NAN), metas)); - assertFalse(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_NAN))), metas)); + assertThat(canDrop(eq(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(notEq(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(lt(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(ltEq(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(gt(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(gtEq(float16Column, FLOAT16_FIFTY), metas)).isFalse(); + assertThat(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_FIFTY))), metas)) + .isFalse(); + + assertThat(canDrop(eq(float16Column, FLOAT16_NAN), metas)).isTrue(); + assertThat(canDrop(notEq(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(lt(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(ltEq(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(gt(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(gtEq(float16Column, FLOAT16_NAN), metas)).isFalse(); + assertThat(canDrop(in(float16Column, new HashSet<>(List.of(FLOAT16_NAN))), metas)) + .isFalse(); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/format/converter/TestParquetMetadataConverter.java b/parquet-hadoop/src/test/java/org/apache/parquet/format/converter/TestParquetMetadataConverter.java index 8d778f7b91..d65d118afc 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/format/converter/TestParquetMetadataConverter.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/format/converter/TestParquetMetadataConverter.java @@ -43,13 +43,10 @@ import static org.apache.parquet.schema.LogicalTypeAnnotation.uuidType; import static org.apache.parquet.schema.LogicalTypeAnnotation.variantType; import static org.apache.parquet.schema.MessageTypeParser.parseMessageType; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.data.Offset.offset; import com.google.common.collect.Lists; import com.google.common.collect.Sets; @@ -139,7 +136,6 @@ import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName; import org.apache.parquet.schema.Type.Repetition; import org.apache.parquet.schema.Types; -import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -163,7 +159,7 @@ public void testPageHeader() throws IOException { PageHeader pageHeader = new PageHeader(type, uncSize, compSize); writePageHeader(pageHeader, out); PageHeader readPageHeader = readPageHeader(new ByteArrayInputStream(out.toByteArray())); - assertEquals(pageHeader, readPageHeader); + assertThat(readPageHeader).isEqualTo(pageHeader); } @Test @@ -171,7 +167,7 @@ public void testSchemaConverter() { ParquetMetadataConverter parquetMetadataConverter = new ParquetMetadataConverter(); List parquetSchema = parquetMetadataConverter.toParquetSchema(Paper.schema); MessageType schema = parquetMetadataConverter.fromParquetSchema(parquetSchema, null); - assertEquals(Paper.schema, schema); + assertThat(schema).isEqualTo(Paper.schema); } @Test @@ -207,7 +203,7 @@ public void testSchemaConverterDecimal() { .setLogicalType(LogicalType.DECIMAL(new DecimalType(2, 9))) .setPrecision(9) .setScale(2)); - Assert.assertEquals(expected, schemaElements); + assertThat(schemaElements).isEqualTo(expected); } @Test @@ -228,7 +224,7 @@ private void testParquetMetadataConverterWithDictionary(ParquetMetadata parquetM // Flag should be true fmd1.row_groups.forEach(rowGroup -> rowGroup.columns.forEach(column -> { - assertTrue(column.meta_data.isSetDictionary_page_offset()); + assertThat(column.meta_data.isSetDictionary_page_offset()).isTrue(); })); ByteArrayOutputStream metaDataOutputStream = new ByteArrayOutputStream(); @@ -242,7 +238,7 @@ private void testParquetMetadataConverterWithDictionary(ParquetMetadata parquetM long dicOffsetConverted = parquetMetaDataConverted.getBlocks().get(0).getColumns().get(0).getDictionaryPageOffset(); - Assert.assertEquals(dicOffsetOriginal, dicOffsetConverted); + assertThat(dicOffsetConverted).isEqualTo(dicOffsetOriginal); } @Test @@ -254,7 +250,7 @@ public void testParquetMetadataConverterWithoutDictionary() throws IOException { // Flag should be false fmd1.row_groups.forEach(rowGroup -> rowGroup.columns.forEach(column -> { - assertFalse(column.meta_data.isSetDictionary_page_offset()); + assertThat(column.meta_data.isSetDictionary_page_offset()).isFalse(); })); ByteArrayOutputStream metaDataOutputStream = new ByteArrayOutputStream(); @@ -265,7 +261,7 @@ public void testParquetMetadataConverterWithoutDictionary() throws IOException { long dicOffsetConverted = pmd2.getBlocks().get(0).getColumns().get(0).getDictionaryPageOffset(); - Assert.assertEquals(0, dicOffsetConverted); + assertThat(dicOffsetConverted).isEqualTo(0); } @Test @@ -275,22 +271,37 @@ public void testBloomFilterOffset() throws IOException { // Without bloom filter offset FileMetaData footer = converter.toParquetMetadata(1, origMetaData); - assertFalse( - footer.getRow_groups().get(0).getColumns().get(0).getMeta_data().isSetBloom_filter_offset()); + assertThat(footer.getRow_groups() + .get(0) + .getColumns() + .get(0) + .getMeta_data() + .isSetBloom_filter_offset()) + .isFalse(); ParquetMetadata convertedMetaData = converter.fromParquetMetadata(footer); - assertTrue(convertedMetaData.getBlocks().get(0).getColumns().get(0).getBloomFilterOffset() < 0); + assertThat(convertedMetaData.getBlocks().get(0).getColumns().get(0).getBloomFilterOffset()) + .isNegative(); // With bloom filter offset origMetaData.getBlocks().get(0).getColumns().get(0).setBloomFilterOffset(1234); footer = converter.toParquetMetadata(1, origMetaData); - assertTrue( - footer.getRow_groups().get(0).getColumns().get(0).getMeta_data().isSetBloom_filter_offset()); - assertEquals( - 1234, - footer.getRow_groups().get(0).getColumns().get(0).getMeta_data().getBloom_filter_offset()); + assertThat(footer.getRow_groups() + .get(0) + .getColumns() + .get(0) + .getMeta_data() + .isSetBloom_filter_offset()) + .isTrue(); + assertThat(footer.getRow_groups() + .get(0) + .getColumns() + .get(0) + .getMeta_data() + .getBloom_filter_offset()) + .isEqualTo(1234); convertedMetaData = converter.fromParquetMetadata(footer); - assertEquals( - 1234, convertedMetaData.getBlocks().get(0).getColumns().get(0).getBloomFilterOffset()); + assertThat(convertedMetaData.getBlocks().get(0).getColumns().get(0).getBloomFilterOffset()) + .isEqualTo(1234); } @Test @@ -300,22 +311,37 @@ public void testBloomFilterLength() throws IOException { // Without bloom filter length FileMetaData footer = converter.toParquetMetadata(1, origMetaData); - assertFalse( - footer.getRow_groups().get(0).getColumns().get(0).getMeta_data().isSetBloom_filter_length()); + assertThat(footer.getRow_groups() + .get(0) + .getColumns() + .get(0) + .getMeta_data() + .isSetBloom_filter_length()) + .isFalse(); ParquetMetadata convertedMetaData = converter.fromParquetMetadata(footer); - assertTrue(convertedMetaData.getBlocks().get(0).getColumns().get(0).getBloomFilterLength() < 0); + assertThat(convertedMetaData.getBlocks().get(0).getColumns().get(0).getBloomFilterLength()) + .isNegative(); // With bloom filter length origMetaData.getBlocks().get(0).getColumns().get(0).setBloomFilterLength(1024); footer = converter.toParquetMetadata(1, origMetaData); - assertTrue( - footer.getRow_groups().get(0).getColumns().get(0).getMeta_data().isSetBloom_filter_length()); - assertEquals( - 1024, - footer.getRow_groups().get(0).getColumns().get(0).getMeta_data().getBloom_filter_length()); + assertThat(footer.getRow_groups() + .get(0) + .getColumns() + .get(0) + .getMeta_data() + .isSetBloom_filter_length()) + .isTrue(); + assertThat(footer.getRow_groups() + .get(0) + .getColumns() + .get(0) + .getMeta_data() + .getBloom_filter_length()) + .isEqualTo(1024); convertedMetaData = converter.fromParquetMetadata(footer); - assertEquals( - 1024, convertedMetaData.getBlocks().get(0).getColumns().get(0).getBloomFilterLength()); + assertThat(convertedMetaData.getBlocks().get(0).getColumns().get(0).getBloomFilterLength()) + .isEqualTo(1024); } @Test @@ -333,7 +359,7 @@ public void testLogicalTypesBackwardCompatibleWithConvertedTypes() { // where converted_types are written to the metadata, but logicalType is missing parquetSchema.get(1).setLogicalType(null); MessageType schema = parquetMetadataConverter.fromParquetSchema(parquetSchema, null); - assertEquals(expected, schema); + assertThat(schema).isEqualTo(expected); } @Test @@ -356,7 +382,7 @@ public void testIncompatibleLogicalAndConvertedTypes() { // Set converted type field to a different type to verify that in case of mismatch, it overrides logical type parquetSchema.get(1).setConverted_type(ConvertedType.JSON); MessageType actual = parquetMetadataConverter.fromParquetSchema(parquetSchema, null); - assertEquals(expected, actual); + assertThat(actual).isEqualTo(expected); } @Test @@ -402,117 +428,121 @@ public void testTimeLogicalTypes() { .named("Message"); List parquetSchema = parquetMetadataConverter.toParquetSchema(expected); MessageType schema = parquetMetadataConverter.fromParquetSchema(parquetSchema, null); - assertEquals(expected, schema); + assertThat(schema).isEqualTo(expected); } @Test public void testLogicalToConvertedTypeConversion() { ParquetMetadataConverter parquetMetadataConverter = new ParquetMetadataConverter(); - assertEquals(ConvertedType.UTF8, parquetMetadataConverter.convertToConvertedType(stringType())); - assertEquals(ConvertedType.ENUM, parquetMetadataConverter.convertToConvertedType(enumType())); - - assertEquals(ConvertedType.INT_8, parquetMetadataConverter.convertToConvertedType(intType(8, true))); - assertEquals(ConvertedType.INT_16, parquetMetadataConverter.convertToConvertedType(intType(16, true))); - assertEquals(ConvertedType.INT_32, parquetMetadataConverter.convertToConvertedType(intType(32, true))); - assertEquals(ConvertedType.INT_64, parquetMetadataConverter.convertToConvertedType(intType(64, true))); - assertEquals(ConvertedType.UINT_8, parquetMetadataConverter.convertToConvertedType(intType(8, false))); - assertEquals(ConvertedType.UINT_16, parquetMetadataConverter.convertToConvertedType(intType(16, false))); - assertEquals(ConvertedType.UINT_32, parquetMetadataConverter.convertToConvertedType(intType(32, false))); - assertEquals(ConvertedType.UINT_64, parquetMetadataConverter.convertToConvertedType(intType(64, false))); - assertEquals(ConvertedType.DECIMAL, parquetMetadataConverter.convertToConvertedType(decimalType(8, 16))); - - assertEquals( - ConvertedType.TIMESTAMP_MILLIS, - parquetMetadataConverter.convertToConvertedType(timestampType(true, MILLIS))); - assertEquals( - ConvertedType.TIMESTAMP_MICROS, - parquetMetadataConverter.convertToConvertedType(timestampType(true, MICROS))); - assertNull(parquetMetadataConverter.convertToConvertedType(timestampType(true, NANOS))); - assertEquals( - ConvertedType.TIMESTAMP_MILLIS, - parquetMetadataConverter.convertToConvertedType(timestampType(false, MILLIS))); - assertEquals( - ConvertedType.TIMESTAMP_MICROS, - parquetMetadataConverter.convertToConvertedType(timestampType(false, MICROS))); - assertNull(parquetMetadataConverter.convertToConvertedType(timestampType(false, NANOS))); - - assertEquals( - ConvertedType.TIME_MILLIS, parquetMetadataConverter.convertToConvertedType(timeType(true, MILLIS))); - assertEquals( - ConvertedType.TIME_MICROS, parquetMetadataConverter.convertToConvertedType(timeType(true, MICROS))); - assertNull(parquetMetadataConverter.convertToConvertedType(timeType(true, NANOS))); - assertEquals( - ConvertedType.TIME_MILLIS, parquetMetadataConverter.convertToConvertedType(timeType(false, MILLIS))); - assertEquals( - ConvertedType.TIME_MICROS, parquetMetadataConverter.convertToConvertedType(timeType(false, MICROS))); - assertNull(parquetMetadataConverter.convertToConvertedType(timeType(false, NANOS))); - - assertEquals(ConvertedType.DATE, parquetMetadataConverter.convertToConvertedType(dateType())); - - assertEquals( - ConvertedType.INTERVAL, - parquetMetadataConverter.convertToConvertedType( - LogicalTypeAnnotation.IntervalLogicalTypeAnnotation.getInstance())); - assertEquals(ConvertedType.JSON, parquetMetadataConverter.convertToConvertedType(jsonType())); - assertEquals(ConvertedType.BSON, parquetMetadataConverter.convertToConvertedType(bsonType())); - - assertNull(parquetMetadataConverter.convertToConvertedType(uuidType())); - - assertEquals(ConvertedType.LIST, parquetMetadataConverter.convertToConvertedType(listType())); - assertEquals(ConvertedType.MAP, parquetMetadataConverter.convertToConvertedType(mapType())); - assertEquals( - ConvertedType.MAP_KEY_VALUE, - parquetMetadataConverter.convertToConvertedType( - LogicalTypeAnnotation.MapKeyValueTypeAnnotation.getInstance())); + assertThat(parquetMetadataConverter.convertToConvertedType(stringType())) + .isEqualTo(ConvertedType.UTF8); + assertThat(parquetMetadataConverter.convertToConvertedType(enumType())).isEqualTo(ConvertedType.ENUM); + + assertThat(parquetMetadataConverter.convertToConvertedType(intType(8, true))) + .isEqualTo(ConvertedType.INT_8); + assertThat(parquetMetadataConverter.convertToConvertedType(intType(16, true))) + .isEqualTo(ConvertedType.INT_16); + assertThat(parquetMetadataConverter.convertToConvertedType(intType(32, true))) + .isEqualTo(ConvertedType.INT_32); + assertThat(parquetMetadataConverter.convertToConvertedType(intType(64, true))) + .isEqualTo(ConvertedType.INT_64); + assertThat(parquetMetadataConverter.convertToConvertedType(intType(8, false))) + .isEqualTo(ConvertedType.UINT_8); + assertThat(parquetMetadataConverter.convertToConvertedType(intType(16, false))) + .isEqualTo(ConvertedType.UINT_16); + assertThat(parquetMetadataConverter.convertToConvertedType(intType(32, false))) + .isEqualTo(ConvertedType.UINT_32); + assertThat(parquetMetadataConverter.convertToConvertedType(intType(64, false))) + .isEqualTo(ConvertedType.UINT_64); + assertThat(parquetMetadataConverter.convertToConvertedType(decimalType(8, 16))) + .isEqualTo(ConvertedType.DECIMAL); + + assertThat(parquetMetadataConverter.convertToConvertedType(timestampType(true, MILLIS))) + .isEqualTo(ConvertedType.TIMESTAMP_MILLIS); + assertThat(parquetMetadataConverter.convertToConvertedType(timestampType(true, MICROS))) + .isEqualTo(ConvertedType.TIMESTAMP_MICROS); + assertThat(parquetMetadataConverter.convertToConvertedType(timestampType(true, NANOS))) + .isNull(); + assertThat(parquetMetadataConverter.convertToConvertedType(timestampType(false, MILLIS))) + .isEqualTo(ConvertedType.TIMESTAMP_MILLIS); + assertThat(parquetMetadataConverter.convertToConvertedType(timestampType(false, MICROS))) + .isEqualTo(ConvertedType.TIMESTAMP_MICROS); + assertThat(parquetMetadataConverter.convertToConvertedType(timestampType(false, NANOS))) + .isNull(); + + assertThat(parquetMetadataConverter.convertToConvertedType(timeType(true, MILLIS))) + .isEqualTo(ConvertedType.TIME_MILLIS); + assertThat(parquetMetadataConverter.convertToConvertedType(timeType(true, MICROS))) + .isEqualTo(ConvertedType.TIME_MICROS); + assertThat(parquetMetadataConverter.convertToConvertedType(timeType(true, NANOS))) + .isNull(); + assertThat(parquetMetadataConverter.convertToConvertedType(timeType(false, MILLIS))) + .isEqualTo(ConvertedType.TIME_MILLIS); + assertThat(parquetMetadataConverter.convertToConvertedType(timeType(false, MICROS))) + .isEqualTo(ConvertedType.TIME_MICROS); + assertThat(parquetMetadataConverter.convertToConvertedType(timeType(false, NANOS))) + .isNull(); + + assertThat(parquetMetadataConverter.convertToConvertedType(dateType())).isEqualTo(ConvertedType.DATE); + + assertThat(parquetMetadataConverter.convertToConvertedType( + LogicalTypeAnnotation.IntervalLogicalTypeAnnotation.getInstance())) + .isEqualTo(ConvertedType.INTERVAL); + assertThat(parquetMetadataConverter.convertToConvertedType(jsonType())).isEqualTo(ConvertedType.JSON); + assertThat(parquetMetadataConverter.convertToConvertedType(bsonType())).isEqualTo(ConvertedType.BSON); + + assertThat(parquetMetadataConverter.convertToConvertedType(uuidType())).isNull(); + + assertThat(parquetMetadataConverter.convertToConvertedType(listType())).isEqualTo(ConvertedType.LIST); + assertThat(parquetMetadataConverter.convertToConvertedType(mapType())).isEqualTo(ConvertedType.MAP); + assertThat(parquetMetadataConverter.convertToConvertedType( + LogicalTypeAnnotation.MapKeyValueTypeAnnotation.getInstance())) + .isEqualTo(ConvertedType.MAP_KEY_VALUE); } @Test public void testEnumEquivalence() { ParquetMetadataConverter parquetMetadataConverter = new ParquetMetadataConverter(); for (org.apache.parquet.column.Encoding encoding : org.apache.parquet.column.Encoding.values()) { - assertEquals( - encoding, parquetMetadataConverter.getEncoding(parquetMetadataConverter.getEncoding(encoding))); + assertThat(parquetMetadataConverter.getEncoding(parquetMetadataConverter.getEncoding(encoding))) + .isEqualTo(encoding); } for (org.apache.parquet.format.Encoding encoding : org.apache.parquet.format.Encoding.values()) { - assertEquals( - encoding, parquetMetadataConverter.getEncoding(parquetMetadataConverter.getEncoding(encoding))); + assertThat(parquetMetadataConverter.getEncoding(parquetMetadataConverter.getEncoding(encoding))) + .isEqualTo(encoding); } for (Repetition repetition : Repetition.values()) { - assertEquals( - repetition, - parquetMetadataConverter.fromParquetRepetition( - parquetMetadataConverter.toParquetRepetition(repetition))); + assertThat(parquetMetadataConverter.fromParquetRepetition( + parquetMetadataConverter.toParquetRepetition(repetition))) + .isEqualTo(repetition); } for (FieldRepetitionType repetition : FieldRepetitionType.values()) { - assertEquals( - repetition, - parquetMetadataConverter.toParquetRepetition( - parquetMetadataConverter.fromParquetRepetition(repetition))); + assertThat(parquetMetadataConverter.toParquetRepetition( + parquetMetadataConverter.fromParquetRepetition(repetition))) + .isEqualTo(repetition); } for (PrimitiveTypeName primitiveTypeName : PrimitiveTypeName.values()) { - assertEquals( - primitiveTypeName, - parquetMetadataConverter.getPrimitive(parquetMetadataConverter.getType(primitiveTypeName))); + assertThat(parquetMetadataConverter.getPrimitive(parquetMetadataConverter.getType(primitiveTypeName))) + .isEqualTo(primitiveTypeName); } for (Type type : Type.values()) { - assertEquals(type, parquetMetadataConverter.getType(parquetMetadataConverter.getPrimitive(type))); + assertThat(parquetMetadataConverter.getType(parquetMetadataConverter.getPrimitive(type))) + .isEqualTo(type); } for (OriginalType original : OriginalType.values()) { - assertEquals( - original, - parquetMetadataConverter + assertThat(parquetMetadataConverter .getLogicalTypeAnnotation( parquetMetadataConverter.convertToConvertedType( LogicalTypeAnnotation.fromOriginalType(original, null)), null) - .toOriginalType()); + .toOriginalType()) + .isEqualTo(original); } for (ConvertedType converted : ConvertedType.values()) { - assertEquals( - converted, - parquetMetadataConverter.convertToConvertedType( - parquetMetadataConverter.getLogicalTypeAnnotation(converted, null))); + assertThat(parquetMetadataConverter.convertToConvertedType( + parquetMetadataConverter.getLogicalTypeAnnotation(converted, null))) + .isEqualTo(converted); } } @@ -554,11 +584,11 @@ private FileMetaData find(FileMetaData md, long blockStart) { } private void verifyMD(FileMetaData md, long... offsets) { - assertEquals(offsets.length, md.row_groups.size()); + assertThat(md.row_groups).hasSameSizeAs(offsets); for (int i = 0; i < offsets.length; i++) { long offset = offsets[i]; RowGroup rowGroup = md.getRow_groups().get(i); - assertEquals(offset, getOffset(rowGroup)); + assertThat(getOffset(rowGroup)).isEqualTo(offset); } } @@ -575,16 +605,13 @@ private void verifyAllFilters(FileMetaData md, long splitWidth) { FileMetaData filtered = filter(md, start, start + splitWidth); for (RowGroup rg : filtered.getRow_groups()) { long o = getOffset(rg); - if (offsetsFound.contains(o)) { - fail("found the offset twice: " + o); - } else { - offsetsFound.add(o); - } + assertThat(offsetsFound).as("found the offset twice: " + o).doesNotContain(o); + offsetsFound.add(o); } } - if (offsetsFound.size() != md.row_groups.size()) { - fail("missing row groups, " + "found: " + offsetsFound + "\nexpected " + md.getRow_groups()); - } + assertThat(offsetsFound) + .as("found: " + offsetsFound + "\nexpected " + md.getRow_groups()) + .hasSize(md.getRow_groups().size()); } private long fileSize(FileMetaData md) { @@ -701,11 +728,10 @@ public void testEncryptedFieldMetadataDebugLogging() { @Test public void testMetadataToJson() { ParquetMetadata metadata = new ParquetMetadata(null, null); - assertEquals("{\"fileMetaData\":null,\"blocks\":null}", ParquetMetadata.toJSON(metadata)); - assertEquals( - ("{\n" + " \"fileMetaData\" : null,\n" + " \"blocks\" : null\n" + "}") - .replace("\n", System.lineSeparator()), - ParquetMetadata.toPrettyJSON(metadata)); + assertThat(ParquetMetadata.toJSON(metadata)).isEqualTo("{\"fileMetaData\":null,\"blocks\":null}"); + assertThat(ParquetMetadata.toPrettyJSON(metadata)) + .isEqualTo(("{\n" + " \"fileMetaData\" : null,\n" + " \"blocks\" : null\n" + "}") + .replace("\n", System.lineSeparator())); } private ColumnChunkMetaData createColumnChunkMetaData() { @@ -745,18 +771,18 @@ public void testEncodingsCache() { parquetMetadataConverter.fromFormatEncodings(formatEncodingsCopy2); // make sure they are all semantically equal - assertEquals(expected, res1); - assertEquals(expected, res2); - assertEquals(expected, res3); + assertThat(res1).isEqualTo(expected); + assertThat(res2).isEqualTo(expected); + assertThat(res3).isEqualTo(expected); // make sure res1, res2, and res3 are actually the same cached object - assertSame(res1, res2); - assertSame(res1, res3); + assertThat(res2).isSameAs(res1); + assertThat(res3).isSameAs(res1); // make sure they are all unmodifiable (UnmodifiableSet is not public, so we have to compare on class name) - assertEquals("java.util.Collections$UnmodifiableSet", res1.getClass().getName()); - assertEquals("java.util.Collections$UnmodifiableSet", res2.getClass().getName()); - assertEquals("java.util.Collections$UnmodifiableSet", res3.getClass().getName()); + assertThat(res1.getClass().getName()).isEqualTo("java.util.Collections$UnmodifiableSet"); + assertThat(res2.getClass().getName()).isEqualTo("java.util.Collections$UnmodifiableSet"); + assertThat(res3.getClass().getName()).isEqualTo("java.util.Collections$UnmodifiableSet"); } @Test @@ -770,8 +796,8 @@ public void testEncodingsOrder() { List formatEncodings = parquetMetadataConverter.toFormatEncodings(columnEncodings); for (int i = 1; i < formatEncodings.size(); i++) { - assertTrue(formatEncodings.get(i - 1).ordinal() - < formatEncodings.get(i).ordinal()); + assertThat(formatEncodings.get(i - 1).ordinal()) + .isLessThan(formatEncodings.get(i).ordinal()); } } @@ -794,29 +820,37 @@ private void testBinaryStats(StatsHelper helper) { stats.updateStats(Binary.fromConstantByteArray(min)); stats.updateStats(Binary.fromConstantByteArray(max)); long totalLen = min.length + max.length; - Assert.assertFalse("Should not be smaller than min + max size", stats.isSmallerThan(totalLen)); - Assert.assertTrue("Should be smaller than min + max size + 1", stats.isSmallerThan(totalLen + 1)); + assertThat(stats.isSmallerThan(totalLen)) + .as("Should not be smaller than min + max size") + .isFalse(); + assertThat(stats.isSmallerThan(totalLen + 1)) + .as("Should be smaller than min + max size + 1") + .isTrue(); org.apache.parquet.format.Statistics formatStats = helper.toParquetStatistics(stats); - assertFalse("Min should not be set", formatStats.isSetMin()); - assertFalse("Max should not be set", formatStats.isSetMax()); + assertThat(formatStats.isSetMin()).as("Min should not be set").isFalse(); + assertThat(formatStats.isSetMax()).as("Max should not be set").isFalse(); if (helper == StatsHelper.V2) { - Assert.assertArrayEquals("Min_value should match", min, formatStats.getMin_value()); - Assert.assertArrayEquals("Max_value should match", max, formatStats.getMax_value()); + assertThat(formatStats.getMin_value()).as("Min_value should match").isEqualTo(min); + assertThat(formatStats.getMax_value()).as("Max_value should match").isEqualTo(max); } - Assert.assertEquals("Num nulls should match", 3004, formatStats.getNull_count()); + assertThat(formatStats.getNull_count()).as("Num nulls should match").isEqualTo(3004); // min/max are not written because the values are too large, but null count is always written stats.setMinMaxFromBytes(max, max); formatStats = helper.toParquetStatistics(stats); - Assert.assertFalse("Min should not be set", formatStats.isSetMin()); - Assert.assertFalse("Max should not be set", formatStats.isSetMax()); - Assert.assertFalse("Min_value should not be set", formatStats.isSetMin_value()); - Assert.assertFalse("Max_value should not be set", formatStats.isSetMax_value()); - Assert.assertEquals("Num nulls should match", 3004, formatStats.getNull_count()); + assertThat(formatStats.isSetMin()).as("Min should not be set").isFalse(); + assertThat(formatStats.isSetMax()).as("Max should not be set").isFalse(); + assertThat(formatStats.isSetMin_value()) + .as("Min_value should not be set") + .isFalse(); + assertThat(formatStats.isSetMax_value()) + .as("Max_value should not be set") + .isFalse(); + assertThat(formatStats.getNull_count()).as("Num nulls should match").isEqualTo(3004); Statistics roundTripStats = ParquetMetadataConverter.fromParquetStatisticsInternal( Version.FULL_VERSION, @@ -824,8 +858,12 @@ private void testBinaryStats(StatsHelper helper) { new PrimitiveType(Repetition.OPTIONAL, PrimitiveTypeName.BINARY, ""), ParquetMetadataConverter.SortOrder.SIGNED); - Assert.assertFalse("Round-trip stats should not be empty (null count is set)", roundTripStats.isEmpty()); - Assert.assertEquals("Round-trip null count should match", 3004, roundTripStats.getNumNulls()); + assertThat(roundTripStats.isEmpty()) + .as("Round-trip stats should not be empty (null count is set)") + .isFalse(); + assertThat(roundTripStats.getNumNulls()) + .as("Round-trip null count should match") + .isEqualTo(3004); } @Test @@ -842,12 +880,9 @@ public void testBinaryStatsWithTruncation() { int[] invalidLengths = {-1, 0, Integer.MAX_VALUE + 1}; for (int len : invalidLengths) { - try { - testBinaryStatsWithTruncation(len, 80, 20); - Assert.fail("Expected IllegalArgumentException but didn't happen"); - } catch (IllegalArgumentException e) { - // expected, nothing to do - } + assertThatThrownBy(() -> testBinaryStatsWithTruncation(len, 80, 20)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Truncate length should be greater than 0"); } } @@ -862,20 +897,20 @@ private void testBinaryStatsWithTruncation(int truncateLen, int minLen, int maxL org.apache.parquet.format.Statistics formatStats = metadataConverter.toParquetStatistics(stats); if (minLen + maxLen >= ParquetMetadataConverter.MAX_STATS_SIZE) { - assertNull(formatStats.getMin_value()); - assertNull(formatStats.getMax_value()); + assertThat(formatStats.getMin_value()).isNull(); + assertThat(formatStats.getMax_value()).isNull(); } else { String minString = new String(min, Charset.forName("UTF-8")); String minStatString = new String(formatStats.getMin_value(), Charset.forName("UTF-8")); - assertTrue(minStatString.compareTo(minString) <= 0); + assertThat(minStatString.compareTo(minString)).isLessThanOrEqualTo(0); String maxString = new String(max, Charset.forName("UTF-8")); String maxStatString = new String(formatStats.getMax_value(), Charset.forName("UTF-8")); - assertTrue(maxStatString.compareTo(maxString) >= 0); + assertThat(maxStatString.compareTo(maxString)).isGreaterThanOrEqualTo(0); } } private static String generateRandomString(String prefix, int length) { - assertTrue(prefix.length() <= length); + assertThat(prefix.length()).isLessThanOrEqualTo(length); StringBuilder sb = new StringBuilder(length); sb.append(prefix); for (int i = 0; i < length - prefix.length(); i++) { @@ -907,9 +942,13 @@ private void testIntegerStats(StatsHelper helper) { org.apache.parquet.format.Statistics formatStats = helper.toParquetStatistics(stats); - Assert.assertEquals("Min should match", min, BytesUtils.bytesToInt(formatStats.getMin())); - Assert.assertEquals("Max should match", max, BytesUtils.bytesToInt(formatStats.getMax())); - Assert.assertEquals("Num nulls should match", 3004, formatStats.getNull_count()); + assertThat(BytesUtils.bytesToInt(formatStats.getMin())) + .as("Min should match") + .isEqualTo(min); + assertThat(BytesUtils.bytesToInt(formatStats.getMax())) + .as("Max should match") + .isEqualTo(max); + assertThat(formatStats.getNull_count()).as("Num nulls should match").isEqualTo(3004); } @Test @@ -933,9 +972,13 @@ private void testLongStats(StatsHelper helper) { org.apache.parquet.format.Statistics formatStats = helper.toParquetStatistics(stats); - Assert.assertEquals("Min should match", min, BytesUtils.bytesToLong(formatStats.getMin())); - Assert.assertEquals("Max should match", max, BytesUtils.bytesToLong(formatStats.getMax())); - Assert.assertEquals("Num nulls should match", 3004, formatStats.getNull_count()); + assertThat(BytesUtils.bytesToLong(formatStats.getMin())) + .as("Min should match") + .isEqualTo(min); + assertThat(BytesUtils.bytesToLong(formatStats.getMax())) + .as("Max should match") + .isEqualTo(max); + assertThat(formatStats.getNull_count()).as("Num nulls should match").isEqualTo(3004); } @Test @@ -959,11 +1002,13 @@ private void testFloatStats(StatsHelper helper) { org.apache.parquet.format.Statistics formatStats = helper.toParquetStatistics(stats); - Assert.assertEquals( - "Min should match", min, Float.intBitsToFloat(BytesUtils.bytesToInt(formatStats.getMin())), 0.000001); - Assert.assertEquals( - "Max should match", max, Float.intBitsToFloat(BytesUtils.bytesToInt(formatStats.getMax())), 0.000001); - Assert.assertEquals("Num nulls should match", 3004, formatStats.getNull_count()); + assertThat(Float.intBitsToFloat(BytesUtils.bytesToInt(formatStats.getMin()))) + .as("Min should match") + .isCloseTo(min, offset(0.000001f)); + assertThat(Float.intBitsToFloat(BytesUtils.bytesToInt(formatStats.getMax()))) + .as("Max should match") + .isCloseTo(max, offset(0.000001f)); + assertThat(formatStats.getNull_count()).as("Num nulls should match").isEqualTo(3004); } @Test @@ -987,17 +1032,13 @@ private void testDoubleStats(StatsHelper helper) { org.apache.parquet.format.Statistics formatStats = helper.toParquetStatistics(stats); - Assert.assertEquals( - "Min should match", - min, - Double.longBitsToDouble(BytesUtils.bytesToLong(formatStats.getMin())), - 0.000001); - Assert.assertEquals( - "Max should match", - max, - Double.longBitsToDouble(BytesUtils.bytesToLong(formatStats.getMax())), - 0.000001); - Assert.assertEquals("Num nulls should match", 3004, formatStats.getNull_count()); + assertThat(Double.longBitsToDouble(BytesUtils.bytesToLong(formatStats.getMin()))) + .as("Min should match") + .isCloseTo(min, offset(0.000001)); + assertThat(Double.longBitsToDouble(BytesUtils.bytesToLong(formatStats.getMax()))) + .as("Max should match") + .isCloseTo(max, offset(0.000001)); + assertThat(formatStats.getNull_count()).as("Num nulls should match").isEqualTo(3004); } @Test @@ -1021,9 +1062,13 @@ private void testBooleanStats(StatsHelper helper) { org.apache.parquet.format.Statistics formatStats = helper.toParquetStatistics(stats); - Assert.assertEquals("Min should match", min, BytesUtils.bytesToBool(formatStats.getMin())); - Assert.assertEquals("Max should match", max, BytesUtils.bytesToBool(formatStats.getMax())); - Assert.assertEquals("Num nulls should match", 3004, formatStats.getNull_count()); + assertThat(BytesUtils.bytesToBool(formatStats.getMin())) + .as("Min should match") + .isEqualTo(min); + assertThat(BytesUtils.bytesToBool(formatStats.getMax())) + .as("Max should match") + .isEqualTo(max); + assertThat(formatStats.getNull_count()).as("Num nulls should match").isEqualTo(3004); } @Test @@ -1041,9 +1086,15 @@ public void testIgnoreStatsWithSignedSortOrder() { Statistics convertedStats = converter.fromParquetStatistics( Version.FULL_VERSION, StatsHelper.V1.toParquetStatistics(stats), binaryType); - Assert.assertFalse("Stats should not include min/max: " + convertedStats, convertedStats.hasNonNullValue()); - Assert.assertTrue("Stats should have null count: " + convertedStats, convertedStats.isNumNullsSet()); - Assert.assertEquals("Stats should have 3 nulls: " + convertedStats, 3L, convertedStats.getNumNulls()); + assertThat(convertedStats.hasNonNullValue()) + .as("Stats should not include min/max: " + convertedStats) + .isFalse(); + assertThat(convertedStats.isNumNullsSet()) + .as("Stats should have null count: " + convertedStats) + .isTrue(); + assertThat(convertedStats.getNumNulls()) + .as("Stats should have 3 nulls: " + convertedStats) + .isEqualTo(3L); } @Test @@ -1070,9 +1121,12 @@ private void testStillUseStatsWithSignedSortOrderIfSingleValue(StatsHelper helpe Statistics convertedStats = converter.fromParquetStatistics( Version.FULL_VERSION, ParquetMetadataConverter.toParquetStatistics(stats), binaryType); - Assert.assertFalse("Stats should not be empty: " + convertedStats, convertedStats.isEmpty()); - Assert.assertArrayEquals( - "min == max: " + convertedStats, convertedStats.getMaxBytes(), convertedStats.getMinBytes()); + assertThat(convertedStats.isEmpty()) + .as("Stats should not be empty: " + convertedStats) + .isFalse(); + assertThat(convertedStats.getMinBytes()) + .as("min == max: " + convertedStats) + .isEqualTo(convertedStats.getMaxBytes()); } @Test @@ -1103,16 +1157,20 @@ private void testUseStatsWithSignedSortOrder(StatsHelper helper) { Statistics convertedStats = converter.fromParquetStatistics(Version.FULL_VERSION, helper.toParquetStatistics(stats), binaryType); - Assert.assertFalse("Stats should not be empty", convertedStats.isEmpty()); - Assert.assertTrue(convertedStats.isNumNullsSet()); - Assert.assertEquals("Should have 3 nulls", 3, convertedStats.getNumNulls()); + assertThat(convertedStats.isEmpty()).as("Stats should not be empty").isFalse(); + assertThat(convertedStats.isNumNullsSet()).isTrue(); + assertThat(convertedStats.getNumNulls()).as("Should have 3 nulls").isEqualTo(3); if (helper == StatsHelper.V1) { - assertFalse("Min-max should be null for V1 stats", convertedStats.hasNonNullValue()); + assertThat(convertedStats.hasNonNullValue()) + .as("Min-max should be null for V1 stats") + .isFalse(); } else { - Assert.assertEquals( - "Should have correct min (unsigned sort)", Binary.fromString("A"), convertedStats.genericGetMin()); - Assert.assertEquals( - "Should have correct max (unsigned sort)", Binary.fromString("z"), convertedStats.genericGetMax()); + assertThat(convertedStats.genericGetMin()) + .as("Should have correct min (unsigned sort)") + .isEqualTo(Binary.fromString("A")); + assertThat(convertedStats.genericGetMax()) + .as("Should have correct max (unsigned sort)") + .isEqualTo(Binary.fromString("z")); } } @@ -1125,8 +1183,8 @@ public void testFloat16Stats() { stats.updateStats(toBinary(0xff, 0x7b)); String expectedMinStr = "6.097555E-5"; String expectedMaxStr = "65504.0"; - assertEquals(expectedMinStr, stats.minAsString()); - assertEquals(expectedMaxStr, stats.maxAsString()); + assertThat(stats.minAsString()).isEqualTo(expectedMinStr); + assertThat(stats.maxAsString()).isEqualTo(expectedMaxStr); } private Binary toBinary(int... bytes) { @@ -1144,29 +1202,29 @@ public void testMissingValuesFromStats() { org.apache.parquet.format.Statistics formatStats = new org.apache.parquet.format.Statistics(); Statistics stats = converter.fromParquetStatistics(Version.FULL_VERSION, formatStats, type); - assertFalse(stats.isNumNullsSet()); - assertFalse(stats.hasNonNullValue()); - assertTrue(stats.isEmpty()); - assertEquals(-1, stats.getNumNulls()); + assertThat(stats.isNumNullsSet()).isFalse(); + assertThat(stats.hasNonNullValue()).isFalse(); + assertThat(stats.isEmpty()).isTrue(); + assertThat(stats.getNumNulls()).isEqualTo(-1); formatStats.clear(); formatStats.setMin(BytesUtils.intToBytes(-100)); formatStats.setMax(BytesUtils.intToBytes(100)); stats = converter.fromParquetStatistics(Version.FULL_VERSION, formatStats, type); - assertFalse(stats.isNumNullsSet()); - assertTrue(stats.hasNonNullValue()); - assertFalse(stats.isEmpty()); - assertEquals(-1, stats.getNumNulls()); - assertEquals(-100, stats.genericGetMin()); - assertEquals(100, stats.genericGetMax()); + assertThat(stats.isNumNullsSet()).isFalse(); + assertThat(stats.hasNonNullValue()).isTrue(); + assertThat(stats.isEmpty()).isFalse(); + assertThat(stats.getNumNulls()).isEqualTo(-1); + assertThat(stats.genericGetMin()).isEqualTo(-100); + assertThat(stats.genericGetMax()).isEqualTo(100); formatStats.clear(); formatStats.setNull_count(2000); stats = converter.fromParquetStatistics(Version.FULL_VERSION, formatStats, type); - assertTrue(stats.isNumNullsSet()); - assertFalse(stats.hasNonNullValue()); - assertFalse(stats.isEmpty()); - assertEquals(2000, stats.getNumNulls()); + assertThat(stats.isNumNullsSet()).isTrue(); + assertThat(stats.hasNonNullValue()).isFalse(); + assertThat(stats.isEmpty()).isFalse(); + assertThat(stats.getNumNulls()).isEqualTo(2000); } @Test @@ -1187,10 +1245,10 @@ public void testSkippedV2Stats() { private void testSkippedV2Stats(PrimitiveType type, Object min, Object max) { Statistics stats = createStats(type, min, max); org.apache.parquet.format.Statistics statistics = ParquetMetadataConverter.toParquetStatistics(stats); - assertFalse(statistics.isSetMin()); - assertFalse(statistics.isSetMax()); - assertFalse(statistics.isSetMin_value()); - assertFalse(statistics.isSetMax_value()); + assertThat(statistics.isSetMin()).isFalse(); + assertThat(statistics.isSetMax()).isFalse(); + assertThat(statistics.isSetMin_value()).isFalse(); + assertThat(statistics.isSetMax_value()).isFalse(); } @Test @@ -1225,10 +1283,10 @@ public void testV2OnlyStats() { private void testV2OnlyStats(PrimitiveType type, Object min, Object max) { Statistics stats = createStats(type, min, max); org.apache.parquet.format.Statistics statistics = ParquetMetadataConverter.toParquetStatistics(stats); - assertFalse(statistics.isSetMin()); - assertFalse(statistics.isSetMax()); - assertEquals(ByteBuffer.wrap(stats.getMinBytes()), statistics.min_value); - assertEquals(ByteBuffer.wrap(stats.getMaxBytes()), statistics.max_value); + assertThat(statistics.isSetMin()).isFalse(); + assertThat(statistics.isSetMax()).isFalse(); + assertThat(statistics.min_value).isEqualTo(ByteBuffer.wrap(stats.getMinBytes())); + assertThat(statistics.max_value).isEqualTo(ByteBuffer.wrap(stats.getMaxBytes())); } @Test @@ -1267,10 +1325,10 @@ public void testV2StatsEqualMinMax() { private void testV2StatsEqualMinMax(PrimitiveType type, Object min, Object max) { Statistics stats = createStats(type, min, max); org.apache.parquet.format.Statistics statistics = ParquetMetadataConverter.toParquetStatistics(stats); - assertEquals(ByteBuffer.wrap(stats.getMinBytes()), statistics.min); - assertEquals(ByteBuffer.wrap(stats.getMaxBytes()), statistics.max); - assertEquals(ByteBuffer.wrap(stats.getMinBytes()), statistics.min_value); - assertEquals(ByteBuffer.wrap(stats.getMaxBytes()), statistics.max_value); + assertThat(statistics.min).isEqualTo(ByteBuffer.wrap(stats.getMinBytes())); + assertThat(statistics.max).isEqualTo(ByteBuffer.wrap(stats.getMaxBytes())); + assertThat(statistics.min_value).isEqualTo(ByteBuffer.wrap(stats.getMinBytes())); + assertThat(statistics.max_value).isEqualTo(ByteBuffer.wrap(stats.getMaxBytes())); } private static Statistics createStats(PrimitiveType type, T min, T max) { @@ -1290,8 +1348,8 @@ private static Statistics createStatsTyped(PrimitiveType type, int min, int m Statistics stats = Statistics.createStats(type); stats.updateStats(max); stats.updateStats(min); - assertEquals(min, stats.genericGetMin()); - assertEquals(max, stats.genericGetMax()); + assertThat(stats.genericGetMin()).isEqualTo(min); + assertThat(stats.genericGetMax()).isEqualTo(max); return stats; } @@ -1299,8 +1357,8 @@ private static Statistics createStatsTyped(PrimitiveType type, long min, long Statistics stats = Statistics.createStats(type); stats.updateStats(max); stats.updateStats(min); - assertEquals(min, stats.genericGetMin()); - assertEquals(max, stats.genericGetMax()); + assertThat(stats.genericGetMin()).isEqualTo(min); + assertThat(stats.genericGetMax()).isEqualTo(max); return stats; } @@ -1310,8 +1368,8 @@ private static Statistics createStatsTyped(PrimitiveType type, BigInteger min Binary maxBinary = FixedBinaryTestUtils.getFixedBinary(type, max); stats.updateStats(maxBinary); stats.updateStats(minBinary); - assertEquals(minBinary, stats.genericGetMin()); - assertEquals(maxBinary, stats.genericGetMax()); + assertThat(stats.genericGetMin()).isEqualTo(minBinary); + assertThat(stats.genericGetMax()).isEqualTo(maxBinary); return stats; } @@ -1397,9 +1455,9 @@ public void testColumnOrders() throws IOException { FileMetaData formatMetadata = converter.toParquetMetadata(1, metadata); List columnOrders = formatMetadata.getColumn_orders(); - assertEquals(3, columnOrders.size()); + assertThat(columnOrders).hasSize(3); for (org.apache.parquet.format.ColumnOrder columnOrder : columnOrders) { - assertTrue(columnOrder.isSetTYPE_ORDER()); + assertThat(columnOrder.isSetTYPE_ORDER()).isTrue(); } // Simulate that thrift got a union type that is not in the generated code @@ -1409,11 +1467,10 @@ public void testColumnOrders() throws IOException { MessageType resultSchema = converter.fromParquetMetadata(formatMetadata).getFileMetaData().getSchema(); List columns = resultSchema.getColumns(); - assertEquals(3, columns.size()); - assertEquals( - ColumnOrder.typeDefined(), columns.get(0).getPrimitiveType().columnOrder()); - assertEquals(ColumnOrder.undefined(), columns.get(1).getPrimitiveType().columnOrder()); - assertEquals(ColumnOrder.undefined(), columns.get(2).getPrimitiveType().columnOrder()); + assertThat(columns).hasSize(3); + assertThat(columns.get(0).getPrimitiveType().columnOrder()).isEqualTo(ColumnOrder.typeDefined()); + assertThat(columns.get(1).getPrimitiveType().columnOrder()).isEqualTo(ColumnOrder.undefined()); + assertThat(columns.get(2).getPrimitiveType().columnOrder()).isEqualTo(ColumnOrder.undefined()); } @Test @@ -1424,19 +1481,19 @@ public void testOffsetIndexConversion() { builder.add(22000, 12000, 100, withSizeStats ? Optional.of(22L) : Optional.empty()); OffsetIndex offsetIndex = ParquetMetadataConverter.fromParquetOffsetIndex( ParquetMetadataConverter.toParquetOffsetIndex(builder.build(100000))); - assertEquals(2, offsetIndex.getPageCount()); - assertEquals(101000, offsetIndex.getOffset(0)); - assertEquals(10000, offsetIndex.getCompressedPageSize(0)); - assertEquals(0, offsetIndex.getFirstRowIndex(0)); - assertEquals(122000, offsetIndex.getOffset(1)); - assertEquals(12000, offsetIndex.getCompressedPageSize(1)); - assertEquals(100, offsetIndex.getFirstRowIndex(1)); + assertThat(offsetIndex.getPageCount()).isEqualTo(2); + assertThat(offsetIndex.getOffset(0)).isEqualTo(101000); + assertThat(offsetIndex.getCompressedPageSize(0)).isEqualTo(10000); + assertThat(offsetIndex.getFirstRowIndex(0)).isEqualTo(0); + assertThat(offsetIndex.getOffset(1)).isEqualTo(122000); + assertThat(offsetIndex.getCompressedPageSize(1)).isEqualTo(12000); + assertThat(offsetIndex.getFirstRowIndex(1)).isEqualTo(100); if (withSizeStats) { - assertEquals(Optional.of(11L), offsetIndex.getUnencodedByteArrayDataBytes(0)); - assertEquals(Optional.of(22L), offsetIndex.getUnencodedByteArrayDataBytes(1)); + assertThat(offsetIndex.getUnencodedByteArrayDataBytes(0)).isEqualTo(Optional.of(11L)); + assertThat(offsetIndex.getUnencodedByteArrayDataBytes(1)).isEqualTo(Optional.of(22L)); } else { - assertFalse(offsetIndex.getUnencodedByteArrayDataBytes(0).isPresent()); - assertFalse(offsetIndex.getUnencodedByteArrayDataBytes(1).isPresent()); + assertThat(offsetIndex.getUnencodedByteArrayDataBytes(0)).isEmpty(); + assertThat(offsetIndex.getUnencodedByteArrayDataBytes(1)).isEmpty(); } } } @@ -1467,43 +1524,43 @@ public void testColumnIndexConversion() { org.apache.parquet.format.ColumnIndex parquetColumnIndex = ParquetMetadataConverter.toParquetColumnIndex(type, builder.build()); ColumnIndex columnIndex = ParquetMetadataConverter.fromParquetColumnIndex(type, parquetColumnIndex); - assertEquals(BoundaryOrder.ASCENDING, columnIndex.getBoundaryOrder()); - assertTrue(List.of(false, true, false).equals(columnIndex.getNullPages())); - assertTrue(List.of(16l, 111l, 0l).equals(columnIndex.getNullCounts())); - assertTrue(List.of( - ByteBuffer.wrap(BytesUtils.longToBytes(-100l)), + assertThat(columnIndex.getBoundaryOrder()).isEqualTo(BoundaryOrder.ASCENDING); + assertThat(columnIndex.getNullPages()).containsExactly(false, true, false); + assertThat(columnIndex.getNullCounts()).containsExactly(16L, 111L, 0L); + assertThat(columnIndex.getMinValues()) + .containsExactly( + ByteBuffer.wrap(BytesUtils.longToBytes(-100L)), ByteBuffer.allocate(0), - ByteBuffer.wrap(BytesUtils.longToBytes(200l))) - .equals(columnIndex.getMinValues())); - assertTrue(List.of( - ByteBuffer.wrap(BytesUtils.longToBytes(100l)), + ByteBuffer.wrap(BytesUtils.longToBytes(200L))); + assertThat(columnIndex.getMaxValues()) + .containsExactly( + ByteBuffer.wrap(BytesUtils.longToBytes(100L)), ByteBuffer.allocate(0), - ByteBuffer.wrap(BytesUtils.longToBytes(500l))) - .equals(columnIndex.getMaxValues())); - - assertNull( - "Should handle null column index", - ParquetMetadataConverter.toParquetColumnIndex( - Types.required(PrimitiveTypeName.INT32).named("test_int32"), null)); - assertNull( - "Should ignore unsupported types", - ParquetMetadataConverter.toParquetColumnIndex( - Types.required(PrimitiveTypeName.INT96).named("test_int96"), columnIndex)); - assertNull( - "Should ignore unsupported types", - ParquetMetadataConverter.fromParquetColumnIndex( + ByteBuffer.wrap(BytesUtils.longToBytes(500L))); + + assertThat(ParquetMetadataConverter.toParquetColumnIndex( + Types.required(PrimitiveTypeName.INT32).named("test_int32"), null)) + .as("Should handle null column index") + .isNull(); + assertThat(ParquetMetadataConverter.toParquetColumnIndex( + Types.required(PrimitiveTypeName.INT96).named("test_int96"), columnIndex)) + .as("Should ignore unsupported types") + .isNull(); + assertThat(ParquetMetadataConverter.fromParquetColumnIndex( Types.required(PrimitiveTypeName.FIXED_LEN_BYTE_ARRAY) .length(12) .as(OriginalType.INTERVAL) .named("test_interval"), - parquetColumnIndex)); + parquetColumnIndex)) + .as("Should ignore unsupported types") + .isNull(); if (withSizeStats) { - assertEquals(LongArrayList.of(1, 2, 3, 4, 5, 6), columnIndex.getRepetitionLevelHistogram()); - assertEquals(LongArrayList.of(6, 5, 4, 3, 2, 1), columnIndex.getDefinitionLevelHistogram()); + assertThat(columnIndex.getRepetitionLevelHistogram()).containsExactly(1L, 2L, 3L, 4L, 5L, 6L); + assertThat(columnIndex.getDefinitionLevelHistogram()).containsExactly(6L, 5L, 4L, 3L, 2L, 1L); } else { - assertEquals(LongArrayList.of(), columnIndex.getRepetitionLevelHistogram()); - assertEquals(LongArrayList.of(), columnIndex.getDefinitionLevelHistogram()); + assertThat(columnIndex.getRepetitionLevelHistogram()).isEmpty(); + assertThat(columnIndex.getDefinitionLevelHistogram()).isEmpty(); } } } @@ -1526,41 +1583,37 @@ public void testMapLogicalType() { .named("Message"); List parquetSchema = parquetMetadataConverter.toParquetSchema(expected); - assertEquals(5, parquetSchema.size()); - assertEquals(new SchemaElement("Message").setNum_children(1), parquetSchema.get(0)); - assertEquals( - new SchemaElement("testMap") + assertThat(parquetSchema).hasSize(5); + assertThat(parquetSchema.get(0)).isEqualTo(new SchemaElement("Message").setNum_children(1)); + assertThat(parquetSchema.get(1)) + .isEqualTo(new SchemaElement("testMap") .setRepetition_type(FieldRepetitionType.REQUIRED) .setNum_children(1) .setConverted_type(ConvertedType.MAP) - .setLogicalType(LogicalType.MAP(new MapType())), - parquetSchema.get(1)); + .setLogicalType(LogicalType.MAP(new MapType()))); // PARQUET-1879 ensure that LogicalType is not written (null) but ConvertedType is MAP_KEY_VALUE for // backwards-compatibility - assertEquals( - new SchemaElement("key_value") + assertThat(parquetSchema.get(2)) + .isEqualTo(new SchemaElement("key_value") .setRepetition_type(FieldRepetitionType.REPEATED) .setNum_children(2) .setConverted_type(ConvertedType.MAP_KEY_VALUE) - .setLogicalType(null), - parquetSchema.get(2)); - assertEquals( - new SchemaElement("key") + .setLogicalType(null)); + assertThat(parquetSchema.get(3)) + .isEqualTo(new SchemaElement("key") .setType(Type.BYTE_ARRAY) .setRepetition_type(FieldRepetitionType.REQUIRED) .setConverted_type(ConvertedType.UTF8) - .setLogicalType(LogicalType.STRING(new StringType())), - parquetSchema.get(3)); - assertEquals( - new SchemaElement("value") + .setLogicalType(LogicalType.STRING(new StringType()))); + assertThat(parquetSchema.get(4)) + .isEqualTo(new SchemaElement("value") .setType(Type.INT32) .setRepetition_type(FieldRepetitionType.REQUIRED) .setConverted_type(null) - .setLogicalType(null), - parquetSchema.get(4)); + .setLogicalType(null)); MessageType schema = parquetMetadataConverter.fromParquetSchema(parquetSchema, null); - assertEquals(expected, schema); + assertThat(schema).isEqualTo(expected); } @Test @@ -1629,10 +1682,11 @@ public void testVariantLogicalType() { ParquetMetadataConverter parquetMetadataConverter = new ParquetMetadataConverter(); List parquetSchema = parquetMetadataConverter.toParquetSchema(expected); MessageType schema = parquetMetadataConverter.fromParquetSchema(parquetSchema, null); - assertEquals(expected, schema); + assertThat(schema).isEqualTo(expected); LogicalTypeAnnotation logicalType = schema.getType("v").getLogicalTypeAnnotation(); - assertEquals(LogicalTypeAnnotation.variantType(specVersion), logicalType); - assertEquals(specVersion, ((LogicalTypeAnnotation.VariantLogicalTypeAnnotation) logicalType).getSpecVersion()); + assertThat(logicalType).isEqualTo(LogicalTypeAnnotation.variantType(specVersion)); + assertThat(((LogicalTypeAnnotation.VariantLogicalTypeAnnotation) logicalType).getSpecVersion()) + .isEqualTo(specVersion); } private void verifyMapMessageType(final MessageType messageType, final String keyValueName) throws IOException { @@ -1656,16 +1710,17 @@ private void verifyMapMessageType(final MessageType messageType, final String ke ParquetReader.builder(new GroupReadSupport(), file).build()) { Group group = reader.read(); - assertNotNull(group); + assertThat(group).isNotNull(); Group testMap = group.getGroup("testMap", 0); - assertNotNull(testMap); - assertEquals(5, testMap.getFieldRepetitionCount(keyValueName)); + assertThat(testMap).isNotNull(); + assertThat(testMap.getFieldRepetitionCount(keyValueName)).isEqualTo(5); for (int index = 0; index < 5; index++) { - assertEquals( - "key" + index, testMap.getGroup(keyValueName, index).getString("key", 0)); - assertEquals(100L + index, testMap.getGroup(keyValueName, index).getLong("value", 0)); + assertThat(testMap.getGroup(keyValueName, index).getString("key", 0)) + .isEqualTo("key" + index); + assertThat(testMap.getGroup(keyValueName, index).getLong("value", 0)) + .isEqualTo(100L + index); } } } @@ -1679,10 +1734,10 @@ public void testSizeStatisticsConversion() { ParquetMetadataConverter.toParquetSizeStatistics( new SizeStatistics(type, 1024, repLevelHistogram, defLevelHistogram)), type); - assertEquals(type, sizeStatistics.getType()); - assertEquals(Optional.of(1024L), sizeStatistics.getUnencodedByteArrayDataBytes()); - assertEquals(repLevelHistogram, sizeStatistics.getRepetitionLevelHistogram()); - assertEquals(defLevelHistogram, sizeStatistics.getDefinitionLevelHistogram()); + assertThat(sizeStatistics.getType()).isEqualTo(type); + assertThat(sizeStatistics.getUnencodedByteArrayDataBytes()).isEqualTo(Optional.of(1024L)); + assertThat(sizeStatistics.getRepetitionLevelHistogram()).containsExactlyElementsOf(repLevelHistogram); + assertThat(sizeStatistics.getDefinitionLevelHistogram()).containsExactlyElementsOf(defLevelHistogram); } @Test @@ -1701,12 +1756,13 @@ public void testGeometryLogicalType() { MessageType actual = parquetMetadataConverter.fromParquetSchema(parquetSchema, null); // Verify the logical type is preserved - assertEquals(schema, actual); + assertThat(actual).isEqualTo(schema); PrimitiveType primitiveType = actual.getType("geomField").asPrimitiveType(); LogicalTypeAnnotation logicalType = primitiveType.getLogicalTypeAnnotation(); - assertTrue(logicalType instanceof LogicalTypeAnnotation.GeometryLogicalTypeAnnotation); - assertEquals("EPSG:4326", ((LogicalTypeAnnotation.GeometryLogicalTypeAnnotation) logicalType).getCrs()); + assertThat(logicalType).isInstanceOf(LogicalTypeAnnotation.GeometryLogicalTypeAnnotation.class); + assertThat(((LogicalTypeAnnotation.GeometryLogicalTypeAnnotation) logicalType).getCrs()) + .isEqualTo("EPSG:4326"); } @Test @@ -1725,16 +1781,16 @@ public void testGeographyLogicalType() { MessageType actual = parquetMetadataConverter.fromParquetSchema(parquetSchema, null); // Verify the logical type is preserved - assertEquals(schema, actual); + assertThat(actual).isEqualTo(schema); PrimitiveType primitiveType = actual.getType("geogField").asPrimitiveType(); LogicalTypeAnnotation logicalType = primitiveType.getLogicalTypeAnnotation(); - assertTrue(logicalType instanceof LogicalTypeAnnotation.GeographyLogicalTypeAnnotation); + assertThat(logicalType).isInstanceOf(LogicalTypeAnnotation.GeographyLogicalTypeAnnotation.class); LogicalTypeAnnotation.GeographyLogicalTypeAnnotation geographyType = (LogicalTypeAnnotation.GeographyLogicalTypeAnnotation) logicalType; - assertEquals("EPSG:4326", geographyType.getCrs()); - assertEquals(EdgeInterpolationAlgorithm.SPHERICAL, geographyType.getAlgorithm()); + assertThat(geographyType.getCrs()).isEqualTo("EPSG:4326"); + assertThat(geographyType.getAlgorithm()).isEqualTo(EdgeInterpolationAlgorithm.SPHERICAL); } @Test @@ -1749,16 +1805,18 @@ public void testGeometryLogicalTypeWithMissingCrs() { LogicalTypeAnnotation annotation = converter.getLogicalTypeAnnotation(logicalType); // Verify the annotation is created correctly - assertNotNull("Geometry annotation should not be null", annotation); - assertTrue( - "Should be a GeometryLogicalTypeAnnotation", - annotation instanceof LogicalTypeAnnotation.GeometryLogicalTypeAnnotation); + assertThat(annotation).as("Geometry annotation should not be null").isNotNull(); + assertThat(annotation) + .as("Should be a GeometryLogicalTypeAnnotation") + .isInstanceOf(LogicalTypeAnnotation.GeometryLogicalTypeAnnotation.class); LogicalTypeAnnotation.GeometryLogicalTypeAnnotation geometryAnnotation = (LogicalTypeAnnotation.GeometryLogicalTypeAnnotation) annotation; // Default behavior should use null or empty CRS - assertNull("CRS should be null or empty when not specified", geometryAnnotation.getCrs()); + assertThat(geometryAnnotation.getCrs()) + .as("CRS should be null or empty when not specified") + .isNull(); } @Test @@ -1774,27 +1832,33 @@ public void testGeographyLogicalTypeWithMissingParameters() { LogicalTypeAnnotation annotation = converter.getLogicalTypeAnnotation(logicalType); // Verify the annotation is created correctly - assertNotNull("Geography annotation should not be null", annotation); - assertTrue( - "Should be a GeographyLogicalTypeAnnotation", - annotation instanceof LogicalTypeAnnotation.GeographyLogicalTypeAnnotation); + assertThat(annotation).as("Geography annotation should not be null").isNotNull(); + assertThat(annotation) + .as("Should be a GeographyLogicalTypeAnnotation") + .isInstanceOf(LogicalTypeAnnotation.GeographyLogicalTypeAnnotation.class); // Check that optional parameters are handled correctly LogicalTypeAnnotation.GeographyLogicalTypeAnnotation geographyAnnotation = (LogicalTypeAnnotation.GeographyLogicalTypeAnnotation) annotation; - assertNull("CRS should be null when not specified", geographyAnnotation.getCrs()); + assertThat(geographyAnnotation.getCrs()) + .as("CRS should be null when not specified") + .isNull(); // Most implementations default to LINEAR when algorithm is not specified - assertNull("Algorithm should be null when not specified", geographyAnnotation.getAlgorithm()); + assertThat(geographyAnnotation.getAlgorithm()) + .as("Algorithm should be null when not specified") + .isNull(); // Now test the round-trip conversion LogicalType roundTripType = converter.convertToLogicalType(annotation); - assertEquals("setField should be GEOGRAPHY", LogicalType._Fields.GEOGRAPHY, roundTripType.getSetField()); - assertNull( - "Round trip CRS should still be null", - roundTripType.getGEOGRAPHY().getCrs()); - assertNull( - "Round trip Algorithm should be null", - roundTripType.getGEOGRAPHY().getAlgorithm()); + assertThat(roundTripType.getSetField()) + .as("setField should be GEOGRAPHY") + .isEqualTo(LogicalType._Fields.GEOGRAPHY); + assertThat(roundTripType.getGEOGRAPHY().getCrs()) + .as("Round trip CRS should still be null") + .isNull(); + assertThat(roundTripType.getGEOGRAPHY().getAlgorithm()) + .as("Round trip Algorithm should be null") + .isNull(); } @Test @@ -1810,16 +1874,17 @@ public void testGeographyLogicalTypeWithAlgorithmButNoCrs() { LogicalTypeAnnotation annotation = converter.getLogicalTypeAnnotation(logicalType); // Verify the annotation is created correctly - Assert.assertNotNull("Geography annotation should not be null", annotation); + assertThat(annotation).as("Geography annotation should not be null").isNotNull(); LogicalTypeAnnotation.GeographyLogicalTypeAnnotation geographyAnnotation = (LogicalTypeAnnotation.GeographyLogicalTypeAnnotation) annotation; // CRS should be null/empty but algorithm should be set - assertNull("CRS should be null or empty", geographyAnnotation.getCrs()); - assertEquals( - "Algorithm should be SPHERICAL", - EdgeInterpolationAlgorithm.SPHERICAL, - geographyAnnotation.getAlgorithm()); + assertThat(geographyAnnotation.getCrs()) + .as("CRS should be null or empty") + .isNull(); + assertThat(geographyAnnotation.getAlgorithm()) + .as("Algorithm should be SPHERICAL") + .isEqualTo(EdgeInterpolationAlgorithm.SPHERICAL); } @Test @@ -1848,27 +1913,29 @@ public void testGeospatialStatisticsConversion() { GeospatialStatistics thriftStats = converter.toParquetGeospatialStatistics(origStats); // Verify conversion to Thrift - assertNotNull("Thrift GeospatialStatistics should not be null", thriftStats); - assertTrue("BoundingBox should be set", thriftStats.isSetBbox()); - assertTrue("Geospatial types should be set", thriftStats.isSetGeospatial_types()); + assertThat(thriftStats) + .as("Thrift GeospatialStatistics should not be null") + .isNotNull(); + assertThat(thriftStats.isSetBbox()).as("BoundingBox should be set").isTrue(); + assertThat(thriftStats.isSetGeospatial_types()) + .as("Geospatial types should be set") + .isTrue(); // Check BoundingBox values BoundingBox thriftBbox = thriftStats.getBbox(); - assertEquals(1.0, thriftBbox.getXmin(), 0.0001); - assertEquals(2.0, thriftBbox.getXmax(), 0.0001); - assertEquals(3.0, thriftBbox.getYmin(), 0.0001); - assertEquals(4.0, thriftBbox.getYmax(), 0.0001); - assertEquals(5.0, thriftBbox.getZmin(), 0.0001); - assertEquals(6.0, thriftBbox.getZmax(), 0.0001); - assertEquals(7.0, thriftBbox.getMmin(), 0.0001); - assertEquals(8.0, thriftBbox.getMmax(), 0.0001); + assertThat(thriftBbox.getXmin()).isCloseTo(1.0, offset(0.0001)); + assertThat(thriftBbox.getXmax()).isCloseTo(2.0, offset(0.0001)); + assertThat(thriftBbox.getYmin()).isCloseTo(3.0, offset(0.0001)); + assertThat(thriftBbox.getYmax()).isCloseTo(4.0, offset(0.0001)); + assertThat(thriftBbox.getZmin()).isCloseTo(5.0, offset(0.0001)); + assertThat(thriftBbox.getZmax()).isCloseTo(6.0, offset(0.0001)); + assertThat(thriftBbox.getMmin()).isCloseTo(7.0, offset(0.0001)); + assertThat(thriftBbox.getMmax()).isCloseTo(8.0, offset(0.0001)); // Check geospatial types List thriftTypes = thriftStats.getGeospatial_types(); - assertEquals(3, thriftTypes.size()); - assertTrue(thriftTypes.contains(1)); - assertTrue(thriftTypes.contains(2)); - assertTrue(thriftTypes.contains(3)); + assertThat(thriftTypes).hasSize(3); + assertThat(thriftTypes).contains(1, 2, 3); // Create primitive geometry type for conversion back LogicalTypeAnnotation geometryAnnotation = LogicalTypeAnnotation.geometryType("EPSG:4326"); @@ -1880,27 +1947,31 @@ public void testGeospatialStatisticsConversion() { ParquetMetadataConverter.fromParquetStatistics(thriftStats, geometryType); // Verify conversion from Thrift - assertNotNull("Converted GeospatialStatistics should not be null", convertedStats); - assertNotNull("BoundingBox should not be null", convertedStats.getBoundingBox()); - assertNotNull("GeospatialTypes should not be null", convertedStats.getGeospatialTypes()); + assertThat(convertedStats) + .as("Converted GeospatialStatistics should not be null") + .isNotNull(); + assertThat(convertedStats.getBoundingBox()) + .as("BoundingBox should not be null") + .isNotNull(); + assertThat(convertedStats.getGeospatialTypes()) + .as("GeospatialTypes should not be null") + .isNotNull(); // Check BoundingBox values org.apache.parquet.column.statistics.geospatial.BoundingBox convertedBbox = convertedStats.getBoundingBox(); - assertEquals(1.0, convertedBbox.getXMin(), 0.0001); - assertEquals(2.0, convertedBbox.getXMax(), 0.0001); - assertEquals(3.0, convertedBbox.getYMin(), 0.0001); - assertEquals(4.0, convertedBbox.getYMax(), 0.0001); - assertEquals(5.0, convertedBbox.getZMin(), 0.0001); - assertEquals(6.0, convertedBbox.getZMax(), 0.0001); - assertEquals(7.0, convertedBbox.getMMin(), 0.0001); - assertEquals(8.0, convertedBbox.getMMax(), 0.0001); + assertThat(convertedBbox.getXMin()).isCloseTo(1.0, offset(0.0001)); + assertThat(convertedBbox.getXMax()).isCloseTo(2.0, offset(0.0001)); + assertThat(convertedBbox.getYMin()).isCloseTo(3.0, offset(0.0001)); + assertThat(convertedBbox.getYMax()).isCloseTo(4.0, offset(0.0001)); + assertThat(convertedBbox.getZMin()).isCloseTo(5.0, offset(0.0001)); + assertThat(convertedBbox.getZMax()).isCloseTo(6.0, offset(0.0001)); + assertThat(convertedBbox.getMMin()).isCloseTo(7.0, offset(0.0001)); + assertThat(convertedBbox.getMMax()).isCloseTo(8.0, offset(0.0001)); // Check geospatial types Set convertedTypes = convertedStats.getGeospatialTypes().getTypes(); - assertEquals(3, convertedTypes.size()); - assertTrue(convertedTypes.contains(1)); - assertTrue(convertedTypes.contains(2)); - assertTrue(convertedTypes.contains(3)); + assertThat(convertedTypes).hasSize(3); + assertThat(convertedTypes).contains(1, 2, 3); } @Test @@ -1917,9 +1988,13 @@ public void testGeospatialStatisticsWithNullBoundingBox() { GeospatialStatistics thriftStats = converter.toParquetGeospatialStatistics(origStats); // Verify conversion to Thrift - assertNotNull("Thrift GeospatialStatistics should not be null", thriftStats); - assertFalse("BoundingBox should not be set", thriftStats.isSetBbox()); - assertTrue("Geospatial types should be set", thriftStats.isSetGeospatial_types()); + assertThat(thriftStats) + .as("Thrift GeospatialStatistics should not be null") + .isNotNull(); + assertThat(thriftStats.isSetBbox()).as("BoundingBox should not be set").isFalse(); + assertThat(thriftStats.isSetGeospatial_types()) + .as("Geospatial types should be set") + .isTrue(); // Create primitive geometry type for conversion back LogicalTypeAnnotation geometryAnnotation = LogicalTypeAnnotation.geometryType("EPSG:4326"); @@ -1931,9 +2006,15 @@ public void testGeospatialStatisticsWithNullBoundingBox() { ParquetMetadataConverter.fromParquetStatistics(thriftStats, geometryType); // Verify conversion from Thrift - assertNotNull("Converted GeospatialStatistics should not be null", convertedStats); - assertNull("BoundingBox should be null", convertedStats.getBoundingBox()); - assertNotNull("GeospatialTypes should not be null", convertedStats.getGeospatialTypes()); + assertThat(convertedStats) + .as("Converted GeospatialStatistics should not be null") + .isNotNull(); + assertThat(convertedStats.getBoundingBox()) + .as("BoundingBox should be null") + .isNull(); + assertThat(convertedStats.getGeospatialTypes()) + .as("GeospatialTypes should not be null") + .isNotNull(); } @Test @@ -1957,7 +2038,7 @@ public void testInvalidBoundingBox() { // Convert to Thrift format - should return null for invalid bbox GeospatialStatistics thriftStats = converter.toParquetGeospatialStatistics(origStats); - assertNull("Should return null for invalid BoundingBox", thriftStats); + assertThat(thriftStats).as("Should return null for invalid BoundingBox").isNull(); } @Test @@ -1972,11 +2053,13 @@ public void testEdgeInterpolationAlgorithmConversion() { org.apache.parquet.column.schema.EdgeInterpolationAlgorithm.SPHERICAL; org.apache.parquet.column.schema.EdgeInterpolationAlgorithm actual = ParquetMetadataConverter.toParquetEdgeInterpolationAlgorithm(thriftAlgo); - assertEquals(expected, actual); + assertThat(actual).isEqualTo(expected); // Test with null - assertNull(ParquetMetadataConverter.fromParquetEdgeInterpolationAlgorithm(null)); - assertNull(ParquetMetadataConverter.toParquetEdgeInterpolationAlgorithm(null)); + assertThat(ParquetMetadataConverter.fromParquetEdgeInterpolationAlgorithm(null)) + .isNull(); + assertThat(ParquetMetadataConverter.toParquetEdgeInterpolationAlgorithm(null)) + .isNull(); } @Test @@ -1997,19 +2080,17 @@ public void testIEEE754TotalOrderColumnOrder() throws IOException { FileMetaData formatMetadata = converter.toParquetMetadata(1, metadata); List columnOrders = formatMetadata.getColumn_orders(); - assertEquals(2, columnOrders.size()); + assertThat(columnOrders).hasSize(2); for (org.apache.parquet.format.ColumnOrder columnOrder : columnOrders) { - assertTrue(columnOrder.isSetIEEE_754_TOTAL_ORDER()); + assertThat(columnOrder.isSetIEEE_754_TOTAL_ORDER()).isTrue(); } MessageType resultSchema = converter.fromParquetMetadata(formatMetadata).getFileMetaData().getSchema(); - assertEquals( - ColumnOrder.ieee754TotalOrder(), - resultSchema.getType("float_ieee754").asPrimitiveType().columnOrder()); - assertEquals( - ColumnOrder.ieee754TotalOrder(), - resultSchema.getType("double_ieee754").asPrimitiveType().columnOrder()); + assertThat(resultSchema.getType("float_ieee754").asPrimitiveType().columnOrder()) + .isEqualTo(ColumnOrder.ieee754TotalOrder()); + assertThat(resultSchema.getType("double_ieee754").asPrimitiveType().columnOrder()) + .isEqualTo(ColumnOrder.ieee754TotalOrder()); } @Test @@ -2036,15 +2117,10 @@ public void testNestedColumnOrdersUseLeafOrder() throws IOException { MessageType resultSchema = converter.fromParquetMetadata(formatMetadata).getFileMetaData().getSchema(); List columns = resultSchema.getColumns(); - assertEquals(3, columns.size()); - assertEquals( - ColumnOrder.ieee754TotalOrder(), - columns.get(0).getPrimitiveType().columnOrder()); - assertEquals( - ColumnOrder.typeDefined(), columns.get(1).getPrimitiveType().columnOrder()); - assertEquals( - ColumnOrder.ieee754TotalOrder(), - columns.get(2).getPrimitiveType().columnOrder()); + assertThat(columns).hasSize(3); + assertThat(columns.get(0).getPrimitiveType().columnOrder()).isEqualTo(ColumnOrder.ieee754TotalOrder()); + assertThat(columns.get(1).getPrimitiveType().columnOrder()).isEqualTo(ColumnOrder.typeDefined()); + assertThat(columns.get(2).getPrimitiveType().columnOrder()).isEqualTo(ColumnOrder.ieee754TotalOrder()); } @Test @@ -2057,13 +2133,13 @@ public void testStatisticsNanCountRoundTripFloat() { stats.updateStats(Float.NaN); org.apache.parquet.format.Statistics formatStats = ParquetMetadataConverter.toParquetStatistics(stats); - assertTrue("nan_count should be set", formatStats.isSetNan_count()); - assertEquals(2, formatStats.getNan_count()); + assertThat(formatStats.isSetNan_count()).as("nan_count should be set").isTrue(); + assertThat(formatStats.getNan_count()).isEqualTo(2); Statistics roundTrip = ParquetMetadataConverter.fromParquetStatisticsInternal( Version.FULL_VERSION, formatStats, type, ParquetMetadataConverter.SortOrder.SIGNED); - assertTrue(roundTrip.isNanCountSet()); - assertEquals(2, roundTrip.getNanCount()); + assertThat(roundTrip.isNanCountSet()).isTrue(); + assertThat(roundTrip.getNanCount()).isEqualTo(2); } @Test @@ -2075,13 +2151,13 @@ public void testStatisticsNanCountRoundTripDouble() { stats.updateStats(3.0); org.apache.parquet.format.Statistics formatStats = ParquetMetadataConverter.toParquetStatistics(stats); - assertTrue("nan_count should be set", formatStats.isSetNan_count()); - assertEquals(1, formatStats.getNan_count()); + assertThat(formatStats.isSetNan_count()).as("nan_count should be set").isTrue(); + assertThat(formatStats.getNan_count()).isEqualTo(1); Statistics roundTrip = ParquetMetadataConverter.fromParquetStatisticsInternal( Version.FULL_VERSION, formatStats, type, ParquetMetadataConverter.SortOrder.SIGNED); - assertTrue(roundTrip.isNanCountSet()); - assertEquals(1, roundTrip.getNanCount()); + assertThat(roundTrip.isNanCountSet()).isTrue(); + assertThat(roundTrip.getNanCount()).isEqualTo(1); } @Test @@ -2097,13 +2173,13 @@ public void testStatisticsNanCountRoundTripFloat16() { stats.updateStats(Binary.fromConstantByteArray(new byte[] {0x00, 0x7E})); org.apache.parquet.format.Statistics formatStats = ParquetMetadataConverter.toParquetStatistics(stats); - assertTrue("nan_count should be set", formatStats.isSetNan_count()); - assertEquals(1, formatStats.getNan_count()); + assertThat(formatStats.isSetNan_count()).as("nan_count should be set").isTrue(); + assertThat(formatStats.getNan_count()).isEqualTo(1); Statistics roundTrip = ParquetMetadataConverter.fromParquetStatisticsInternal( Version.FULL_VERSION, formatStats, type, ParquetMetadataConverter.SortOrder.SIGNED); - assertTrue(roundTrip.isNanCountSet()); - assertEquals(1, roundTrip.getNanCount()); + assertThat(roundTrip.isNanCountSet()).isTrue(); + assertThat(roundTrip.getNanCount()).isEqualTo(1); } @Test @@ -2114,13 +2190,15 @@ public void testStatisticsNanCountZeroRoundTrip() { stats.updateStats(2.0f); org.apache.parquet.format.Statistics formatStats = ParquetMetadataConverter.toParquetStatistics(stats); - assertTrue("nan_count should be set even when zero", formatStats.isSetNan_count()); - assertEquals(0, formatStats.getNan_count()); + assertThat(formatStats.isSetNan_count()) + .as("nan_count should be set even when zero") + .isTrue(); + assertThat(formatStats.getNan_count()).isEqualTo(0); Statistics roundTrip = ParquetMetadataConverter.fromParquetStatisticsInternal( Version.FULL_VERSION, formatStats, type, ParquetMetadataConverter.SortOrder.SIGNED); - assertTrue(roundTrip.isNanCountSet()); - assertEquals(0, roundTrip.getNanCount()); + assertThat(roundTrip.isNanCountSet()).isTrue(); + assertThat(roundTrip.getNanCount()).isEqualTo(0); } @Test @@ -2151,12 +2229,14 @@ public void testColumnIndexNanCountsRoundTrip() { ColumnIndex columnIndex = builder.build(); org.apache.parquet.format.ColumnIndex parquetColumnIndex = ParquetMetadataConverter.toParquetColumnIndex(type, columnIndex); - assertNotNull(parquetColumnIndex); - assertNotNull("nan_counts should be set", parquetColumnIndex.getNan_counts()); - assertEquals(List.of(1L, 0L, 0L), parquetColumnIndex.getNan_counts()); + assertThat(parquetColumnIndex).isNotNull(); + assertThat(parquetColumnIndex.getNan_counts()) + .as("nan_counts should be set") + .isNotNull(); + assertThat(parquetColumnIndex.getNan_counts()).containsExactly(1L, 0L, 0L); ColumnIndex roundTrip = ParquetMetadataConverter.fromParquetColumnIndex(type, parquetColumnIndex); - assertNotNull(roundTrip); - assertEquals(List.of(1L, 0L, 0L), roundTrip.getNanCounts()); + assertThat(roundTrip).isNotNull(); + assertThat(roundTrip.getNanCounts()).containsExactly(1L, 0L, 0L); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/DeprecatedInputFormatTest.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/DeprecatedInputFormatTest.java index 0b446e665c..d72173ed45 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/DeprecatedInputFormatTest.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/DeprecatedInputFormatTest.java @@ -19,8 +19,7 @@ package org.apache.parquet.hadoop; import static java.lang.Thread.sleep; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.BufferedReader; import java.io.File; @@ -254,9 +253,7 @@ public void testCombineParquetInputFormat() throws Exception { while ((line = br.readLine()) != null) { s.add(line.split("\t")[1]); } - assertEquals(s.size(), 2); - assertTrue(s.contains("hello")); - assertTrue(s.contains("world")); + assertThat(s).containsExactlyInAnyOrder("hello", "world"); } FileUtils.deleteDirectory(inputDir); @@ -266,28 +263,19 @@ public void testCombineParquetInputFormat() throws Exception { @Test public void testReadWriteWithCountDeprecated() throws Exception { runMapReduceJob(CompressionCodecName.GZIP); - assertTrue(mapRedJob - .getCounters() - .getGroup("parquet") - .getCounterForName("bytesread") - .getValue() - > 0L); - assertTrue(mapRedJob - .getCounters() - .getGroup("parquet") - .getCounterForName("bytestotal") - .getValue() - > 0L); - assertTrue(mapRedJob - .getCounters() - .getGroup("parquet") - .getCounterForName("bytesread") - .getValue() - == mapRedJob - .getCounters() - .getGroup("parquet") - .getCounterForName("bytestotal") - .getValue()); + long bytesRead = mapRedJob + .getCounters() + .getGroup("parquet") + .getCounterForName("bytesread") + .getValue(); + long bytesTotal = mapRedJob + .getCounters() + .getGroup("parquet") + .getCounterForName("bytestotal") + .getValue(); + assertThat(bytesRead).isPositive(); + assertThat(bytesTotal).isPositive(); + assertThat(bytesRead).isEqualTo(bytesTotal); // not testing the time read counter since it could be zero due to the size of data is too small } @@ -297,27 +285,24 @@ public void testReadWriteWithoutCounter() throws Exception { jobConf.set("parquet.benchmark.bytes.total", "false"); jobConf.set("parquet.benchmark.bytes.read", "false"); runMapReduceJob(CompressionCodecName.GZIP); - assertEquals( - mapRedJob + assertThat(mapRedJob .getCounters() .getGroup("parquet") .getCounterForName("bytesread") - .getValue(), - 0L); - assertEquals( - mapRedJob + .getValue()) + .isZero(); + assertThat(mapRedJob .getCounters() .getGroup("parquet") .getCounterForName("bytestotal") - .getValue(), - 0L); - assertEquals( - mapRedJob + .getValue()) + .isZero(); + assertThat(mapRedJob .getCounters() .getGroup("parquet") .getCounterForName("timeread") - .getValue(), - 0L); + .getValue()) + .isZero(); } private void waitForJob(Job job) throws InterruptedException, IOException { diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestAdaptiveBlockSplitBloomFiltering.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestAdaptiveBlockSplitBloomFiltering.java index d88d9928a5..50af0b6941 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestAdaptiveBlockSplitBloomFiltering.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestAdaptiveBlockSplitBloomFiltering.java @@ -19,7 +19,7 @@ package org.apache.parquet.hadoop; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import org.apache.hadoop.conf.Configuration; @@ -72,7 +72,7 @@ public void checkBloomFilterSize() throws IOException { // expectedNVD=8192], // [byteSize=16384, expectedNVD=13500], [byteSize=32768, expectedNVD=27000] ...... // number of distinct values is less than 100, so the byteSize should be less than 2048. - assertTrue(bitsetSize <= 2048); + assertThat(bitsetSize).isLessThanOrEqualTo(2048); }); }); } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestBloomFiltering.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestBloomFiltering.java index 4ca75c347a..d4a4365c54 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestBloomFiltering.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestBloomFiltering.java @@ -28,9 +28,7 @@ import static org.apache.parquet.filter2.predicate.FilterApi.longColumn; import static org.apache.parquet.filter2.predicate.FilterApi.or; import static org.apache.parquet.hadoop.ParquetFileWriter.Mode.OVERWRITE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import java.nio.file.Files; @@ -256,7 +254,9 @@ private static void assertContains(Stream expected, List

expectedFilter, FilterPredicate actualFilter) @@ -264,7 +264,7 @@ private void assertCorrectFiltering(Predicate expectedFilt // Check with only bloom filter based filtering List result = readUsers(actualFilter, false, true); - assertTrue("Bloom filtering should drop some row groups", result.size() < DATA.size()); + assertThat(result).as("Bloom filtering should drop some row groups").hasSizeLessThan(DATA.size()); LOGGER.info( "{}/{} records read; filtering ratio: {}%", result.size(), DATA.size(), 100 * result.size() / DATA.size()); @@ -275,7 +275,7 @@ private void assertCorrectFiltering(Predicate expectedFilt // Check with all the filtering filtering to ensure the result contains exactly the required values result = readUsers(actualFilter, true, false); - assertEquals(DATA.stream().filter(expectedFilter).collect(Collectors.toList()), result); + assertThat(result).isEqualTo(DATA.stream().filter(expectedFilter).collect(Collectors.toList())); } protected static FileEncryptionProperties getFileEncryptionProperties() { @@ -456,7 +456,7 @@ public void checkBloomFilterSize() throws IOException { int bitsetSize = bloomFilterReader.readBloomFilter(column).getBitsetSize(); // when setting nvd to a fixed value 10000L, bitsetSize will always be 16384 - assertEquals(16384, bitsetSize); + assertThat(bitsetSize).isEqualTo(16384); }); }); } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestByteStreamSplitConfiguration.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestByteStreamSplitConfiguration.java index a756d167a4..3f1f2d756a 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestByteStreamSplitConfiguration.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestByteStreamSplitConfiguration.java @@ -18,9 +18,7 @@ */ package org.apache.parquet.hadoop; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.apache.hadoop.conf.Configuration; import org.apache.parquet.column.ParquetProperties; @@ -31,22 +29,21 @@ public class TestByteStreamSplitConfiguration { public void testDefault() throws Exception { Configuration conf = new Configuration(); // default should be false - assertEquals( - ParquetProperties.DEFAULT_IS_BYTE_STREAM_SPLIT_ENABLED, - ParquetOutputFormat.getByteStreamSplitEnabled(conf)); + assertThat(ParquetOutputFormat.getByteStreamSplitEnabled(conf)) + .isEqualTo(ParquetProperties.DEFAULT_IS_BYTE_STREAM_SPLIT_ENABLED); } @Test public void testSetTrue() throws Exception { Configuration conf = new Configuration(); conf.setBoolean(ParquetOutputFormat.ENABLE_BYTE_STREAM_SPLIT, true); - assertTrue(ParquetOutputFormat.getByteStreamSplitEnabled(conf)); + assertThat(ParquetOutputFormat.getByteStreamSplitEnabled(conf)).isTrue(); } @Test public void testSetFalse() throws Exception { Configuration conf = new Configuration(); conf.setBoolean(ParquetOutputFormat.ENABLE_BYTE_STREAM_SPLIT, false); - assertFalse(ParquetOutputFormat.getByteStreamSplitEnabled(conf)); + assertThat(ParquetOutputFormat.getByteStreamSplitEnabled(conf)).isFalse(); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageReadStore.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageReadStore.java index 42d753b292..c5355d85d7 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageReadStore.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageReadStore.java @@ -20,8 +20,7 @@ import static org.apache.parquet.column.Encoding.PLAIN; import static org.apache.parquet.column.Encoding.RLE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.nio.ByteBuffer; import java.util.Collections; @@ -89,12 +88,11 @@ public void closeReleasesReleaserEvenWhenReaderThrows() throws Exception { storeReleaser.releaseLater(storeAllocator.allocate(8)); store.setReleaser(storeReleaser); - try { - store.close(); - throw new AssertionError("Expected close() to propagate the reader failure"); - } catch (RuntimeException e) { - assertSame(releaseFailure, e.getCause()); - } + assertThatThrownBy(store::close) + .isInstanceOf(RuntimeException.class) + .hasMessage("Unable to close resource") + .cause() + .isSameAs(releaseFailure); } } @@ -112,18 +110,12 @@ public void closeReportsBothReaderAndReleaserFailures() { storeReleaser.releaseLater(throwingReleaserAllocator.allocate(8)); store.setReleaser(storeReleaser); - try { - store.close(); - throw new AssertionError("Expected close() to propagate the failures"); - } catch (RuntimeException e) { - // Readers are released before the releaser, so the reader failure is the primary (root) cause and the - // releaser failure is attached to it as a suppressed exception, ensuring both are reported. - Throwable root = e.getCause(); - assertSame(readerFailure, root); - Throwable[] suppressed = root.getSuppressed(); - assertEquals(1, suppressed.length); - assertSame(releaserFailure, suppressed[0]); - } + assertThatThrownBy(store::close) + .isInstanceOf(RuntimeException.class) + .hasMessage("Unable to close resource") + .cause() + .isSameAs(readerFailure) + .hasSuppressedException(releaserFailure); } private static ByteBufferAllocator throwingAllocator(RuntimeException releaseFailure) { diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageWriteStore.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageWriteStore.java index bd7bbf4846..34ffe11089 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageWriteStore.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageWriteStore.java @@ -31,11 +31,8 @@ import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.FLOAT; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT32; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; @@ -223,29 +220,26 @@ public void test(Configuration config, ByteBufferAllocator allocator) throws Exc PageReadStore rowGroup = reader.readNextRowGroup(); PageReader pageReader = rowGroup.getPageReader(col); DataPageV2 page = (DataPageV2) pageReader.readPage(); - assertEquals(rowCount, page.getRowCount()); - assertEquals(nullCount, page.getNullCount()); - assertEquals(valueCount, page.getValueCount()); - assertEquals(d, intValue(page.getDefinitionLevels())); - assertEquals(r, intValue(page.getRepetitionLevels())); - assertEquals(dataEncoding, page.getDataEncoding()); - assertEquals(v, intValue(page.getData())); + assertThat(page.getRowCount()).isEqualTo(rowCount); + assertThat(page.getNullCount()).isEqualTo(nullCount); + assertThat(page.getValueCount()).isEqualTo(valueCount); + assertThat(intValue(page.getDefinitionLevels())).isEqualTo(d); + assertThat(intValue(page.getRepetitionLevels())).isEqualTo(r); + assertThat(page.getDataEncoding()).isEqualTo(dataEncoding); + assertThat(intValue(page.getData())).isEqualTo(v); // Checking column/offset indexes for the one page ColumnChunkMetaData column = footer.getBlocks().get(0).getColumns().get(0); ColumnIndex columnIndex = reader.readColumnIndex(column); - assertArrayEquals( - statistics.getMinBytes(), columnIndex.getMinValues().get(0).array()); - assertArrayEquals( - statistics.getMaxBytes(), columnIndex.getMaxValues().get(0).array()); - assertEquals( - statistics.getNumNulls(), columnIndex.getNullCounts().get(0).longValue()); - assertFalse(columnIndex.getNullPages().get(0)); + assertThat(columnIndex.getMinValues().get(0).array()).isEqualTo(statistics.getMinBytes()); + assertThat(columnIndex.getMaxValues().get(0).array()).isEqualTo(statistics.getMaxBytes()); + assertThat(columnIndex.getNullCounts().get(0).longValue()).isEqualTo(statistics.getNumNulls()); + assertThat(columnIndex.getNullPages().get(0)).isFalse(); OffsetIndex offsetIndex = reader.readOffsetIndex(column); - assertEquals(1, offsetIndex.getPageCount()); - assertEquals(pageSize, offsetIndex.getCompressedPageSize(0)); - assertEquals(0, offsetIndex.getFirstRowIndex(0)); - assertEquals(pageOffset, offsetIndex.getOffset(0)); + assertThat(offsetIndex.getPageCount()).isEqualTo(1); + assertThat(offsetIndex.getCompressedPageSize(0)).isEqualTo(pageSize); + assertThat(offsetIndex.getFirstRowIndex(0)).isEqualTo(0); + assertThat(offsetIndex.getOffset(0)).isEqualTo(pageOffset); reader.close(); } @@ -326,8 +320,8 @@ public void perColumnCodecDefaultUsedWhenNotSet() throws Exception { Map codecs = writeAndReadCodecs(schema, SNAPPY, props); - assertEquals(SNAPPY, codecs.get("col_a")); - assertEquals(SNAPPY, codecs.get("col_b")); + assertThat(codecs.get("col_a")).isEqualTo(SNAPPY); + assertThat(codecs.get("col_b")).isEqualTo(SNAPPY); } @Test @@ -339,8 +333,8 @@ public void perColumnCodecOverridesDefaultForOneColumn() throws Exception { Map codecs = writeAndReadCodecs(schema, SNAPPY, props); - assertEquals(ZSTD, codecs.get("col_a")); - assertEquals(SNAPPY, codecs.get("col_b")); + assertThat(codecs.get("col_a")).isEqualTo(ZSTD); + assertThat(codecs.get("col_b")).isEqualTo(SNAPPY); } @Test @@ -354,8 +348,8 @@ public void perColumnCodecAllColumnsOverridden() throws Exception { Map codecs = writeAndReadCodecs(schema, SNAPPY, props); - assertEquals(ZSTD, codecs.get("col_a")); - assertEquals(GZIP, codecs.get("col_b")); + assertThat(codecs.get("col_a")).isEqualTo(ZSTD); + assertThat(codecs.get("col_b")).isEqualTo(GZIP); } @Test @@ -369,8 +363,8 @@ public void perColumnLevelWithCodecRoundTrip() throws Exception { Map codecs = writeAndReadCodecs(schema, SNAPPY, props); - assertEquals(ZSTD, codecs.get("col_a")); - assertEquals(SNAPPY, codecs.get("col_b")); + assertThat(codecs.get("col_a")).isEqualTo(ZSTD); + assertThat(codecs.get("col_b")).isEqualTo(SNAPPY); } @Test @@ -381,9 +375,9 @@ public void perColumnLevelInvalidZstdLevelThrows() throws Exception { .withCompressionLevel("col_a", 23) .build(); - BadConfigurationException ex = - assertThrows(BadConfigurationException.class, () -> writeAndReadCodecs(schema, SNAPPY, props)); - assertTrue(ex.getMessage().contains("23")); + assertThatThrownBy(() -> writeAndReadCodecs(schema, SNAPPY, props)) + .isInstanceOf(BadConfigurationException.class) + .hasMessageContaining("23"); } @Test @@ -394,9 +388,9 @@ public void perColumnLevelInvalidGzipLevelThrows() throws Exception { .withCompressionLevel("col_a", 10) .build(); - BadConfigurationException ex = - assertThrows(BadConfigurationException.class, () -> writeAndReadCodecs(schema, SNAPPY, props)); - assertTrue(ex.getMessage().contains("10")); + assertThatThrownBy(() -> writeAndReadCodecs(schema, SNAPPY, props)) + .isInstanceOf(BadConfigurationException.class) + .hasMessageContaining("10"); } private Map writeAndReadCodecs( diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnIndexFiltering.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnIndexFiltering.java index 81883fb45e..fe80cca045 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnIndexFiltering.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnIndexFiltering.java @@ -41,9 +41,7 @@ import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64; import static org.apache.parquet.schema.Types.optional; import static org.apache.parquet.schema.Types.required; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import java.io.Serializable; @@ -315,7 +313,9 @@ private static void assertContains(Stream expected, List actual) { exp = expIt.next(); } } - assertFalse("Not all expected elements are in the actual list. E.g.: " + exp, expIt.hasNext()); + assertThat(expIt) + .as("Not all expected elements are in the actual list. E.g.: " + exp) + .isExhausted(); } private void assertCorrectFiltering(Predicate expectedFilter, FilterPredicate actualFilter) @@ -323,7 +323,7 @@ private void assertCorrectFiltering(Predicate expectedFilter, FilterPredic // Check with only column index based filtering List result = readUsers(actualFilter, false); - assertTrue("Column-index filtering should drop some pages", result.size() < DATA.size()); + assertThat(result).as("Column-index filtering should drop some pages").hasSizeLessThan(DATA.size()); LOGGER.info( "{}/{} records read; filtering ratio: {}%", result.size(), DATA.size(), 100 * result.size() / DATA.size()); @@ -334,7 +334,7 @@ private void assertCorrectFiltering(Predicate expectedFilter, FilterPredic // Check with all the filtering filtering to ensure the result contains exactly the required values result = readUsers(actualFilter, true); - assertEquals(DATA.stream().filter(expectedFilter).collect(Collectors.toList()), result); + assertThat(result).isEqualTo(DATA.stream().filter(expectedFilter).collect(Collectors.toList())); } @BeforeClass @@ -449,28 +449,28 @@ record -> ("anderson".equals(record.getName()) @Test public void testNoFiltering() throws IOException { // Column index filtering with no-op filter - assertEquals(DATA, readUsers(FilterCompat.NOOP, false)); - assertEquals(DATA, readUsers(FilterCompat.NOOP, true)); + assertThat(readUsers(FilterCompat.NOOP, false)).isEqualTo(DATA); + assertThat(readUsers(FilterCompat.NOOP, true)).isEqualTo(DATA); // Column index filtering with null filter - assertEquals(DATA, readUsers((Filter) null, false)); - assertEquals(DATA, readUsers((Filter) null, true)); + assertThat(readUsers((Filter) null, false)).isEqualTo(DATA); + assertThat(readUsers((Filter) null, true)).isEqualTo(DATA); // Column index filtering turned off - assertEquals( - DATA.stream().filter(user -> user.getId() == 1234).collect(Collectors.toList()), - readUsers(eq(longColumn("id"), 1234l), true, false)); - assertEquals( - DATA.stream().filter(user -> "miller".equals(user.getName())).collect(Collectors.toList()), - readUsers(eq(binaryColumn("name"), Binary.fromString("miller")), true, false)); - assertEquals( - DATA.stream().filter(user -> user.getName() == null).collect(Collectors.toList()), - readUsers(eq(binaryColumn("name"), null), true, false)); + assertThat(readUsers(eq(longColumn("id"), 1234l), true, false)) + .isEqualTo(DATA.stream().filter(user -> user.getId() == 1234).collect(Collectors.toList())); + assertThat(readUsers(eq(binaryColumn("name"), Binary.fromString("miller")), true, false)) + .isEqualTo(DATA.stream() + .filter(user -> "miller".equals(user.getName())) + .collect(Collectors.toList())); + assertThat(readUsers(eq(binaryColumn("name"), null), true, false)) + .isEqualTo(DATA.stream().filter(user -> user.getName() == null).collect(Collectors.toList())); // Every filtering mechanism turned off - assertEquals(DATA, readUsers(eq(longColumn("id"), 1234l), false, false)); - assertEquals(DATA, readUsers(eq(binaryColumn("name"), Binary.fromString("miller")), false, false)); - assertEquals(DATA, readUsers(eq(binaryColumn("name"), null), false, false)); + assertThat(readUsers(eq(longColumn("id"), 1234l), false, false)).isEqualTo(DATA); + assertThat(readUsers(eq(binaryColumn("name"), Binary.fromString("miller")), false, false)) + .isEqualTo(DATA); + assertThat(readUsers(eq(binaryColumn("name"), null), false, false)).isEqualTo(DATA); } @Test @@ -606,7 +606,8 @@ record -> !(NameStartsWithVowel.isStartingWithVowel(record.getName()) || record. @Test public void testFilteringWithMissingColumns() throws IOException { // Missing column filter is always true - assertEquals(DATA, readUsers(notEq(binaryColumn("not-existing-binary"), Binary.EMPTY), true)); + assertThat(readUsers(notEq(binaryColumn("not-existing-binary"), Binary.EMPTY), true)) + .isEqualTo(DATA); assertCorrectFiltering( record -> record.getId() == 1234, and(eq(longColumn("id"), 1234l), eq(longColumn("not-existing-long"), null))); @@ -617,7 +618,7 @@ record -> "miller".equals(record.getName()), invert(userDefined(binaryColumn("not-existing-binary"), NameStartsWithVowel.class)))); // Missing column filter is always false - assertEquals(emptyList(), readUsers(lt(longColumn("not-existing-long"), 0l), true)); + assertThat(readUsers(lt(longColumn("not-existing-long"), 0l), true)).isEqualTo(emptyList()); assertCorrectFiltering( record -> "miller".equals(record.getName()), or( @@ -631,22 +632,19 @@ record -> record.getId() == 1234, @Test public void testFilteringWithProjection() throws IOException { // All rows shall be retrieved because all values in column 'name' shall be handled as null values - assertEquals( - DATA.stream().map(user -> user.cloneWithName(null)).collect(toList()), - readUsersWithProjection( - FilterCompat.get(eq(binaryColumn("name"), null)), SCHEMA_WITHOUT_NAME, true, true)); + assertThat(readUsersWithProjection( + FilterCompat.get(eq(binaryColumn("name"), null)), SCHEMA_WITHOUT_NAME, true, true)) + .isEqualTo(DATA.stream().map(user -> user.cloneWithName(null)).collect(toList())); // Column index filter shall drop all pages because all values in column 'name' shall be handled as null values - assertEquals( - emptyList(), - readUsersWithProjection( - FilterCompat.get(notEq(binaryColumn("name"), null)), SCHEMA_WITHOUT_NAME, false, true)); - assertEquals( - emptyList(), - readUsersWithProjection( + assertThat(readUsersWithProjection( + FilterCompat.get(notEq(binaryColumn("name"), null)), SCHEMA_WITHOUT_NAME, false, true)) + .isEqualTo(emptyList()); + assertThat(readUsersWithProjection( FilterCompat.get(userDefined(binaryColumn("name"), NameStartsWithVowel.class)), SCHEMA_WITHOUT_NAME, false, - true)); + true)) + .isEqualTo(emptyList()); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestDataPageChecksums.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestDataPageChecksums.java index 5ee2379050..502d180ff6 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestDataPageChecksums.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestDataPageChecksums.java @@ -20,11 +20,8 @@ package org.apache.parquet.hadoop; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT32; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.File; import java.io.IOException; @@ -488,13 +485,15 @@ private void testCorruptedPage(ParquetProperties.WriterVersion version) throws I PageReadStore pageReadStore = reader.readNextRowGroup(); DataPage colAPage1 = readNextPage(colADesc, pageReadStore); - assertFalse( - "Data in page was not corrupted", Arrays.equals(getPageBytes(colAPage1), colAPage1Bytes)); + assertThat(getPageBytes(colAPage1)) + .as("Data in page was not corrupted") + .isNotEqualTo(colAPage1Bytes); readNextPage(colADesc, pageReadStore); readNextPage(colBDesc, pageReadStore); DataPage colBPage2 = readNextPage(colBDesc, pageReadStore); - assertFalse( - "Data in page was not corrupted", Arrays.equals(getPageBytes(colBPage2), colBPage2Bytes)); + assertThat(getPageBytes(colBPage2)) + .as("Data in page was not corrupted") + .isNotEqualTo(colBPage2Bytes); } // Now we enable checksum verification, the corruption should be detected @@ -716,7 +715,9 @@ private DataPage readNextPage(ColumnDescriptor colDesc, PageReadStore pageReadSt * Compare the extracted (decompressed) bytes to the reference bytes */ private void assertCorrectContent(byte[] pageBytes, byte[] referenceBytes) { - assertArrayEquals("Read page content was different from expected page content", referenceBytes, pageBytes); + assertThat(pageBytes) + .as("Read page content was different from expected page content") + .isEqualTo(referenceBytes); } private byte[] getPageBytes(DataPage page) throws IOException { @@ -738,21 +739,20 @@ private byte[] getPageBytes(DataPage page) throws IOException { * check that the crc's are identical. */ private void assertCrcSetAndCorrect(Page page, byte[] referenceBytes) { - assertTrue("Checksum was not set in page", page.getCrc().isPresent()); + assertThat(page.getCrc()).as("Checksum was not set in page").isPresent(); int crcFromPage = page.getCrc().getAsInt(); crc.reset(); crc.update(referenceBytes); - assertEquals( - "Checksum found in page did not match calculated reference checksum", - crc.getValue(), - (long) crcFromPage & 0xffffffffL); + assertThat((long) crcFromPage & 0xffffffffL) + .as("Checksum found in page did not match calculated reference checksum") + .isEqualTo(crc.getValue()); } /** * Verify that the crc is not set */ private void assertCrcNotSet(Page page) { - assertFalse("Checksum was set in page", page.getCrc().isPresent()); + assertThat(page.getCrc()).as("Checksum was set in page").isEmpty(); } /** @@ -760,14 +760,8 @@ private void assertCrcNotSet(Page page) { * if the read succeeds (no exception was thrown ), verify that the checksum was not set. */ private void assertVerificationFailed(ParquetFileReader reader) { - try { - reader.readNextRowGroup(); - fail("Expected checksum verification exception to be thrown"); - } catch (Exception e) { - assertTrue("Thrown exception is of incorrect type", e instanceof ParquetDecodingException); - assertTrue( - "Did not catch checksum verification ParquetDecodingException", - e.getMessage().contains("CRC checksum verification failed")); - } + assertThatThrownBy(reader::readNextRowGroup) + .isInstanceOf(ParquetDecodingException.class) + .hasMessageContaining("CRC checksum verification failed"); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestDirectCodecFactory.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestDirectCodecFactory.java index e4be00947a..f7ebc9f35e 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestDirectCodecFactory.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestDirectCodecFactory.java @@ -25,6 +25,8 @@ import static org.apache.parquet.hadoop.metadata.CompressionCodecName.SNAPPY; import static org.apache.parquet.hadoop.metadata.CompressionCodecName.UNCOMPRESSED; import static org.apache.parquet.hadoop.metadata.CompressionCodecName.ZSTD; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.IOException; import java.nio.ByteBuffer; @@ -43,7 +45,6 @@ import org.apache.parquet.compression.CompressionCodecFactory.BytesInputCompressor; import org.apache.parquet.compression.CompressionCodecFactory.BytesInputDecompressor; import org.apache.parquet.hadoop.metadata.CompressionCodecName; -import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -88,9 +89,9 @@ private void test(int size, CompressionCodecName codec, boolean useOnHeapCompres if (codec == LZ4_RAW) { // Hadoop codecs support direct decompressors only if the related native libraries are available. // This is not the case for our CI so let's rely on LZ4_RAW where the implementation is our own. - Assert.assertTrue( - String.format("The hadoop codec %s should support direct decompression", codec), - directDecompressor instanceof DirectCodecFactory.FullDirectDecompressor); + assertThat(directDecompressor) + .as(String.format("The hadoop codec %s should support direct decompression", codec)) + .isInstanceOf(DirectCodecFactory.FullDirectDecompressor.class); } final BytesInput directCompressed; @@ -156,16 +157,16 @@ private static void validateDecompress( b.position(shift); outBuf.position(shift); d.decompress(b, (int) compressed.size(), outBuf, size); - Assert.assertEquals( - "Input buffer position mismatch for codec " + codec, - compressed.size() + shift, - b.position()); - Assert.assertEquals( - "Output buffer position mismatch for codec " + codec, size + shift, outBuf.position()); + assertThat(b.position()) + .as("Input buffer position mismatch for codec " + codec) + .isEqualTo(compressed.size() + shift); + assertThat(outBuf.position()) + .as("Output buffer position mismatch for codec " + codec) + .isEqualTo(size + shift); for (int i = 0; i < size; i++) { - Assert.assertTrue( - String.format("Data didn't match at %d, while testing codec %s", i, codec), - outBuf.get(shift + i) == rawBuf.get(i)); + assertThat(outBuf.get(shift + i)) + .as(String.format("Data didn't match at %d, while testing codec %s", i, codec)) + .isEqualTo(rawBuf.get(i)); } } finally { allocator.release(b); @@ -181,8 +182,9 @@ private static void validateDecompress( b.put(buf); b.flip(); final BytesInput input = d.decompress(BytesInput.from(b), size); - Assert.assertArrayEquals( - String.format("While testing codec %s", codec), input.toByteArray(), rawArr); + assertThat(rawArr) + .as(String.format("While testing codec %s", codec)) + .isEqualTo(input.toByteArray()); } finally { allocator.release(b); } @@ -191,7 +193,9 @@ private static void validateDecompress( case ON_HEAP: { final byte[] buf = compressed.toByteArray(); final BytesInput input = d.decompress(BytesInput.from(buf), size); - Assert.assertArrayEquals(String.format("While testing codec %s", codec), input.toByteArray(), rawArr); + assertThat(rawArr) + .as(String.format("While testing codec %s", codec)) + .isEqualTo(input.toByteArray()); break; } } @@ -199,19 +203,10 @@ private static void validateDecompress( @Test public void createDirectFactoryWithHeapAllocatorFails() { - String errorMsg = - "Test failed, creation of a direct codec factory should have failed when passed a non-direct allocator."; - try { - CodecFactory.createDirectCodecFactory(new Configuration(), new HeapByteBufferAllocator(), 0); - throw new RuntimeException(errorMsg); - } catch (IllegalStateException ex) { - // indicates successful completion of the test - Assert.assertTrue( - "Missing expected error message.", - ex.getMessage().contains("A DirectCodecFactory requires a direct buffer allocator be provided.")); - } catch (Exception ex) { - throw new RuntimeException(errorMsg + " Failed with the wrong error."); - } + assertThatThrownBy(() -> + CodecFactory.createDirectCodecFactory(new Configuration(), new HeapByteBufferAllocator(), 0)) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("A DirectCodecFactory requires a direct buffer allocator be provided."); } @Test @@ -268,8 +263,8 @@ public void cachingKeysGzip() { CompressionCodec codec_2_2 = codecFactory_2.getCodec(CompressionCodecName.GZIP); CompressionCodec codec_5_1 = codecFactory_5.getCodec(CompressionCodecName.GZIP); - Assert.assertEquals(codec_2_1, codec_2_2); - Assert.assertNotEquals(codec_2_1, codec_5_1); + assertThat(codec_2_2).isEqualTo(codec_2_1); + assertThat(codec_2_1).isNotEqualTo(codec_5_1); } @Test @@ -287,8 +282,8 @@ public void cachingKeysZstd() { CompressionCodec codec_2_2 = codecFactory_2.getCodec(CompressionCodecName.ZSTD); CompressionCodec codec_5_1 = codecFactory_5.getCodec(CompressionCodecName.ZSTD); - Assert.assertEquals(codec_2_1, codec_2_2); - Assert.assertNotEquals(codec_2_1, codec_5_1); + assertThat(codec_2_2).isEqualTo(codec_2_1); + assertThat(codec_2_1).isNotEqualTo(codec_5_1); } @Test @@ -296,7 +291,7 @@ public void leveledCompressorCachedForSameLevel() { CodecFactory factory = new CodecFactory(new Configuration(), pageSize); BytesInputCompressor c1 = factory.getCompressor(ZSTD, 3); BytesInputCompressor c2 = factory.getCompressor(ZSTD, 3); - Assert.assertSame("Same codec+level should return the cached instance", c1, c2); + assertThat(c2).as("Same codec+level should return the cached instance").isSameAs(c1); factory.release(); } @@ -305,7 +300,9 @@ public void leveledCompressorDiffersByLevel() { CodecFactory factory = new CodecFactory(new Configuration(), pageSize); BytesInputCompressor c1 = factory.getCompressor(ZSTD, 1); BytesInputCompressor c3 = factory.getCompressor(ZSTD, 3); - Assert.assertNotSame("Different levels should return different compressor instances", c1, c3); + assertThat(c3) + .as("Different levels should return different compressor instances") + .isNotSameAs(c1); factory.release(); } @@ -314,8 +311,9 @@ public void leveledCacheIsolatedFromNoLevelCache() { CodecFactory factory = new CodecFactory(new Configuration(), pageSize); BytesInputCompressor noLevel = factory.getCompressor(ZSTD); BytesInputCompressor withLevel = factory.getCompressor(ZSTD, 3); - Assert.assertNotSame( - "Level-aware and no-level compressors should use separate cache entries", noLevel, withLevel); + assertThat(withLevel) + .as("Level-aware and no-level compressors should use separate cache entries") + .isNotSameAs(noLevel); factory.release(); } @@ -323,7 +321,7 @@ public void leveledCacheIsolatedFromNoLevelCache() { public void leveledUncompressedReturnsNoOp() { CodecFactory factory = new CodecFactory(new Configuration(), pageSize); BytesInputCompressor comp = factory.getCompressor(UNCOMPRESSED, 5); - Assert.assertSame(CodecFactory.NO_OP_COMPRESSOR, comp); + assertThat(comp).isSameAs(CodecFactory.NO_OP_COMPRESSOR); factory.release(); } @@ -331,8 +329,8 @@ public void leveledUncompressedReturnsNoOp() { public void leveledSnappyIgnoresLevel() { CodecFactory factory = new CodecFactory(new Configuration(), pageSize); BytesInputCompressor comp = factory.getCompressor(SNAPPY, 99); - Assert.assertNotNull(comp); - Assert.assertEquals(SNAPPY, comp.getCodecName()); + assertThat(comp).isNotNull(); + assertThat(comp.getCodecName()).isEqualTo(SNAPPY); factory.release(); } @@ -340,9 +338,9 @@ public void leveledSnappyIgnoresLevel() { public void leveledGzipInvalidLevelThrows() { CodecFactory factory = new CodecFactory(new Configuration(), pageSize); try { - BadConfigurationException ex = - Assert.assertThrows(BadConfigurationException.class, () -> factory.getCompressor(GZIP, 99)); - Assert.assertTrue(ex.getMessage().contains("99")); + assertThatThrownBy(() -> factory.getCompressor(GZIP, 99)) + .isInstanceOf(BadConfigurationException.class) + .hasMessageContaining("99"); } finally { factory.release(); } @@ -353,8 +351,12 @@ public void leveledGzipBoundaryLevelsValid() { CodecFactory factory = new CodecFactory(new Configuration(), pageSize); for (int level : new int[] {-1, 0, 1, 9}) { BytesInputCompressor comp = factory.getCompressor(GZIP, level); - Assert.assertNotNull("Compressor should not be null for GZIP level " + level, comp); - Assert.assertEquals("Codec name should be GZIP for level " + level, GZIP, comp.getCodecName()); + assertThat(comp) + .as("Compressor should not be null for GZIP level " + level) + .isNotNull(); + assertThat(comp.getCodecName()) + .as("Codec name should be GZIP for level " + level) + .isEqualTo(GZIP); } factory.release(); } @@ -367,7 +369,7 @@ public void leveledZstdRoundTrip() throws IOException { for (int level : new int[] {-5, 0, 1, 3, 10, 22}) { BytesInput compressed = factory.getCompressor(ZSTD, level).compress(BytesInput.from(original)); byte[] result = decompressor.decompress(compressed, original.length).toByteArray(); - Assert.assertArrayEquals("Round-trip failed at ZSTD level " + level, original, result); + assertThat(result).as("Round-trip failed at ZSTD level " + level).isEqualTo(original); } factory.release(); } @@ -380,7 +382,7 @@ public void leveledGzipRoundTrip() throws IOException { for (int level : new int[] {1, 5, 9}) { BytesInput compressed = factory.getCompressor(GZIP, level).compress(BytesInput.from(original)); byte[] result = decompressor.decompress(compressed, original.length).toByteArray(); - Assert.assertArrayEquals("Round-trip failed at GZIP level " + level, original, result); + assertThat(result).as("Round-trip failed at GZIP level " + level).isEqualTo(original); } factory.release(); } @@ -391,30 +393,27 @@ public void directFactoryLeveledZstdRoundTrip() throws IOException { CodecFactory direct = CodecFactory.createDirectCodecFactory(new Configuration(), new DirectByteBufferAllocator(), pageSize); try { - // Sanity: the heap factory's leveled path yields a HeapBytesCompressor. - Assert.assertTrue( - "heap factory should produce a HeapBytesCompressor", - heap.getCompressor(ZSTD, 3) instanceof CodecFactory.HeapBytesCompressor); + assertThat(heap.getCompressor(ZSTD, 3)) + .as("heap factory should produce a HeapBytesCompressor") + .isInstanceOf(CodecFactory.HeapBytesCompressor.class); // The direct factory must not fall back to the heap/Hadoop path for leveled ZSTD/SNAPPY. BytesInputCompressor directZstd = direct.getCompressor(ZSTD, 3); - Assert.assertFalse( - "direct factory ZSTD(level) should not fall back to HeapBytesCompressor", - directZstd instanceof CodecFactory.HeapBytesCompressor); - Assert.assertEquals(ZSTD, directZstd.getCodecName()); - Assert.assertEquals( - "leveled ZSTD should use the same direct compressor type as the no-level path", - direct.getCompressor(ZSTD).getClass(), - directZstd.getClass()); + assertThat(directZstd) + .as("direct factory ZSTD(level) should not fall back to HeapBytesCompressor") + .isNotInstanceOf(CodecFactory.HeapBytesCompressor.class); + assertThat(directZstd.getCodecName()).isEqualTo(ZSTD); + assertThat(directZstd.getClass()) + .as("leveled ZSTD should use the same direct compressor type as the no-level path") + .isEqualTo(direct.getCompressor(ZSTD).getClass()); BytesInputCompressor directSnappy = direct.getCompressor(SNAPPY, 5); - Assert.assertFalse( - "direct factory SNAPPY(level) should not fall back to HeapBytesCompressor", - directSnappy instanceof CodecFactory.HeapBytesCompressor); - Assert.assertEquals( - "leveled SNAPPY should use the same direct compressor type as the no-level path", - direct.getCompressor(SNAPPY).getClass(), - directSnappy.getClass()); + assertThat(directSnappy) + .as("direct factory SNAPPY(level) should not fall back to HeapBytesCompressor") + .isNotInstanceOf(CodecFactory.HeapBytesCompressor.class); + assertThat(directSnappy.getClass()) + .as("leveled SNAPPY should use the same direct compressor type as the no-level path") + .isEqualTo(direct.getCompressor(SNAPPY).getClass()); // The direct ZSTD level path must compress/decompress correctly at each level. byte[] original = "hello parquet per-column zstd direct compression".getBytes(StandardCharsets.UTF_8); @@ -426,7 +425,9 @@ public void directFactoryLeveledZstdRoundTrip() throws IOException { byte[] result = decompressor .decompress(BytesInput.from(compressed), original.length) .toByteArray(); - Assert.assertArrayEquals("Direct ZSTD round-trip failed at level " + level, original, result); + assertThat(result) + .as("Direct ZSTD round-trip failed at level " + level) + .isEqualTo(original); } } finally { heap.release(); @@ -439,7 +440,9 @@ public void directFactoryInvalidZstdLevelThrows() { CodecFactory direct = CodecFactory.createDirectCodecFactory(new Configuration(), new DirectByteBufferAllocator(), pageSize); try { - Assert.assertThrows(BadConfigurationException.class, () -> direct.getCompressor(ZSTD, 23)); + assertThatThrownBy(() -> direct.getCompressor(ZSTD, 23)) + .isInstanceOf(BadConfigurationException.class) + .hasMessageContaining("23"); } finally { direct.release(); } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestIndexCache.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestIndexCache.java index 551ae30e62..afeb055436 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestIndexCache.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestIndexCache.java @@ -23,6 +23,8 @@ import static org.apache.parquet.schema.Type.Repetition.OPTIONAL; import static org.apache.parquet.schema.Type.Repetition.REPEATED; import static org.apache.parquet.schema.Type.Repetition.REQUIRED; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.IOException; import java.nio.file.Paths; @@ -42,7 +44,6 @@ import org.apache.parquet.schema.GroupType; import org.apache.parquet.schema.MessageType; import org.apache.parquet.schema.PrimitiveType; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -80,7 +81,7 @@ public void testNoneCacheStrategy() throws IOException { ParquetReadOptions options = ParquetReadOptions.builder().build(); ParquetFileReader fileReader = new ParquetFileReader(new LocalInputFile(Paths.get(file)), options); IndexCache indexCache = IndexCache.create(fileReader, new HashSet<>(), IndexCache.CacheStrategy.NONE, false); - Assert.assertTrue(indexCache instanceof NoneIndexCache); + assertThat(indexCache).isInstanceOf(NoneIndexCache.class); List blocks = fileReader.getFooter().getBlocks(); for (BlockMetaData blockMetaData : blocks) { indexCache.setBlockMetadata(blockMetaData); @@ -88,10 +89,9 @@ public void testNoneCacheStrategy() throws IOException { validateColumnIndex(fileReader.readColumnIndex(chunk), indexCache.getColumnIndex(chunk)); validateOffsetIndex(fileReader.readOffsetIndex(chunk), indexCache.getOffsetIndex(chunk)); - Assert.assertEquals( - "BloomFilter should match", - fileReader.readBloomFilter(chunk), - indexCache.getBloomFilter(chunk)); + assertThat(indexCache.getBloomFilter(chunk)) + .as("BloomFilter should match") + .isEqualTo(fileReader.readBloomFilter(chunk)); } } } @@ -110,11 +110,11 @@ public void testPrefetchCacheStrategy() throws IOException { columns.add(ColumnPath.fromDotString("Links.Forward")); IndexCache indexCache = IndexCache.create(fileReader, columns, IndexCache.CacheStrategy.PREFETCH_BLOCK, false); - Assert.assertTrue(indexCache instanceof PrefetchIndexCache); + assertThat(indexCache).isInstanceOf(PrefetchIndexCache.class); validPrecacheIndexCache(fileReader, indexCache, columns, false); indexCache = IndexCache.create(fileReader, columns, IndexCache.CacheStrategy.PREFETCH_BLOCK, true); - Assert.assertTrue(indexCache instanceof PrefetchIndexCache); + assertThat(indexCache).isInstanceOf(PrefetchIndexCache.class); validPrecacheIndexCache(fileReader, indexCache, columns, true); } @@ -139,16 +139,21 @@ private static void validPrecacheIndexCache( validateColumnIndex(fileReader.readColumnIndex(chunk), indexCache.getColumnIndex(chunk)); validateOffsetIndex(fileReader.readOffsetIndex(chunk), indexCache.getOffsetIndex(chunk)); - Assert.assertEquals( - "BloomFilter should match", - fileReader.readBloomFilter(chunk), - indexCache.getBloomFilter(chunk)); + assertThat(indexCache.getBloomFilter(chunk)) + .as("BloomFilter should match") + .isEqualTo(fileReader.readBloomFilter(chunk)); if (freeCacheAfterGet) { - Assert.assertThrows(IllegalStateException.class, () -> indexCache.getColumnIndex(chunk)); - Assert.assertThrows(IllegalStateException.class, () -> indexCache.getOffsetIndex(chunk)); + assertThatThrownBy(() -> indexCache.getColumnIndex(chunk)) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("Not found cached ColumnIndex"); + assertThatThrownBy(() -> indexCache.getOffsetIndex(chunk)) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("Not found cached OffsetIndex"); if (columns.contains(chunk.getPath())) { - Assert.assertThrows(IllegalStateException.class, () -> indexCache.getBloomFilter(chunk)); + assertThatThrownBy(() -> indexCache.getBloomFilter(chunk)) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("Not found cached BloomFilter"); } } } @@ -157,25 +162,25 @@ private static void validPrecacheIndexCache( private static void validateColumnIndex(ColumnIndex expected, ColumnIndex target) { if (expected == null) { - Assert.assertEquals("ColumnIndex should should equal", expected, target); + assertThat(target).as("ColumnIndex should should equal").isEqualTo(expected); } else { - Assert.assertNotNull("ColumnIndex should not be null", target); - Assert.assertEquals(expected.getClass(), target.getClass()); - Assert.assertEquals(expected.getMinValues(), target.getMinValues()); - Assert.assertEquals(expected.getMaxValues(), target.getMaxValues()); - Assert.assertEquals(expected.getBoundaryOrder(), target.getBoundaryOrder()); - Assert.assertEquals(expected.getNullCounts(), target.getNullCounts()); - Assert.assertEquals(expected.getNullPages(), target.getNullPages()); + assertThat(target).as("ColumnIndex should not be null").isNotNull(); + assertThat(target.getClass()).isEqualTo(expected.getClass()); + assertThat(target.getMinValues()).containsExactlyElementsOf(expected.getMinValues()); + assertThat(target.getMaxValues()).containsExactlyElementsOf(expected.getMaxValues()); + assertThat(target.getBoundaryOrder()).isEqualTo(expected.getBoundaryOrder()); + assertThat(target.getNullCounts()).containsExactlyElementsOf(expected.getNullCounts()); + assertThat(target.getNullPages()).containsExactlyElementsOf(expected.getNullPages()); } } private static void validateOffsetIndex(OffsetIndex expected, OffsetIndex target) { if (expected == null) { - Assert.assertEquals("OffsetIndex should should equal", expected, target); + assertThat(target).as("OffsetIndex should should equal").isEqualTo(expected); } else { - Assert.assertNotNull("OffsetIndex should not be null", target); - Assert.assertEquals(expected.getClass(), target.getClass()); - Assert.assertEquals(expected.toString(), target.toString()); + assertThat(target).as("OffsetIndex should not be null").isNotNull(); + assertThat(target.getClass()).isEqualTo(expected.getClass()); + assertThat(target).asString().isEqualTo(expected.toString()); } } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormat.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormat.java index 40bd9b0ee3..d757b8ae9a 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormat.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormat.java @@ -27,10 +27,8 @@ import static org.apache.parquet.filter2.predicate.FilterApi.not; import static org.apache.parquet.filter2.predicate.FilterApi.notEq; import static org.apache.parquet.filter2.predicate.FilterApi.or; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import com.google.common.io.Files; @@ -101,26 +99,18 @@ public void setUp() { @Test public void testThrowExceptionWhenMaxSplitSizeIsSmallerThanMinSplitSize() throws IOException { - try { - generateSplitByMinMaxSize(50, 49); - fail("should throw exception when max split size is smaller than the min split size"); - } catch (ParquetDecodingException e) { - assertEquals( - "maxSplitSize and minSplitSize should be positive and max should be greater or equal to the minSplitSize: maxSplitSize = 49; minSplitSize is 50", - e.getMessage()); - } + assertThatThrownBy(() -> generateSplitByMinMaxSize(50, 49)) + .isInstanceOf(ParquetDecodingException.class) + .hasMessage( + "maxSplitSize and minSplitSize should be positive and max should be greater or equal to the minSplitSize: maxSplitSize = 49; minSplitSize is 50"); } @Test public void testThrowExceptionWhenMaxSplitSizeIsNegative() throws IOException { - try { - generateSplitByMinMaxSize(-100, -50); - fail("should throw exception when max split size is negative"); - } catch (ParquetDecodingException e) { - assertEquals( - "maxSplitSize and minSplitSize should be positive and max should be greater or equal to the minSplitSize: maxSplitSize = -50; minSplitSize is -100", - e.getMessage()); - } + assertThatThrownBy(() -> generateSplitByMinMaxSize(-100, -50)) + .isInstanceOf(ParquetDecodingException.class) + .hasMessage( + "maxSplitSize and minSplitSize should be positive and max should be greater or equal to the minSplitSize: maxSplitSize = -50; minSplitSize is -100"); } @Test @@ -130,17 +120,17 @@ public void testGetFilter() throws IOException { Configuration conf = new Configuration(); ParquetInputFormat.setFilterPredicate(conf, p); Filter read = ParquetInputFormat.getFilter(conf); - assertTrue(read instanceof FilterPredicateCompat); - assertEquals(p, ((FilterPredicateCompat) read).getFilterPredicate()); + assertThat(read).isInstanceOf(FilterPredicateCompat.class); + assertThat(((FilterPredicateCompat) read).getFilterPredicate()).isEqualTo(p); conf = new Configuration(); ParquetInputFormat.setFilterPredicate(conf, not(p)); read = ParquetInputFormat.getFilter(conf); - assertTrue(read instanceof FilterPredicateCompat); - assertEquals( - and(notEq(intColumn, 7), notEq(intColumn, 12)), ((FilterPredicateCompat) read).getFilterPredicate()); + assertThat(read).isInstanceOf(FilterPredicateCompat.class); + assertThat(((FilterPredicateCompat) read).getFilterPredicate()) + .isEqualTo(and(notEq(intColumn, 7), notEq(intColumn, 12))); - assertEquals(FilterCompat.NOOP, ParquetInputFormat.getFilter(new Configuration())); + assertThat(ParquetInputFormat.getFilter(new Configuration())).isEqualTo(FilterCompat.NOOP); } /* @@ -314,27 +304,20 @@ public void testOnlyOneKindOfFilterSupported() throws Exception { IntColumn foo = intColumn("foo"); FilterPredicate p = or(eq(foo, 10), eq(foo, 11)); - Job job = new Job(); - - Configuration conf = job.getConfiguration(); - ParquetInputFormat.setUnboundRecordFilter(job, DummyUnboundRecordFilter.class); - try { - ParquetInputFormat.setFilterPredicate(conf, p); - fail("this should throw"); - } catch (IllegalArgumentException e) { - assertEquals("You cannot provide a FilterPredicate after providing an UnboundRecordFilter", e.getMessage()); - } - - job = new Job(); - conf = job.getConfiguration(); - - ParquetInputFormat.setFilterPredicate(conf, p); - try { - ParquetInputFormat.setUnboundRecordFilter(job, DummyUnboundRecordFilter.class); - fail("this should throw"); - } catch (IllegalArgumentException e) { - assertEquals("You cannot provide an UnboundRecordFilter after providing a FilterPredicate", e.getMessage()); - } + Job jobWithUnboundFilter = new Job(); + Configuration confWithUnboundFilter = jobWithUnboundFilter.getConfiguration(); + ParquetInputFormat.setUnboundRecordFilter(jobWithUnboundFilter, DummyUnboundRecordFilter.class); + assertThatThrownBy(() -> ParquetInputFormat.setFilterPredicate(confWithUnboundFilter, p)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("You cannot provide a FilterPredicate after providing an UnboundRecordFilter"); + + Job jobWithPredicate = new Job(); + Configuration confWithPredicate = jobWithPredicate.getConfiguration(); + ParquetInputFormat.setFilterPredicate(confWithPredicate, p); + assertThatThrownBy(() -> + ParquetInputFormat.setUnboundRecordFilter(jobWithPredicate, DummyUnboundRecordFilter.class)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("You cannot provide an UnboundRecordFilter after providing a FilterPredicate"); } public static BlockMetaData makeBlockFromStats(IntStatistics stats, long valueCount) { @@ -363,9 +346,10 @@ public void testFooterCacheValueIsCurrent() throws IOException, InterruptedExcep FileSystem fs = FileSystem.getLocal(new Configuration()); ParquetInputFormat.FootersCacheValue cacheValue = getDummyCacheValue(tempFile, fs); - assertTrue(tempFile.setLastModified(tempFile.lastModified() + 5000)); - assertFalse(cacheValue.isCurrent( - new ParquetInputFormat.FileStatusWrapper(fs.getFileStatus(new Path(tempFile.getAbsolutePath()))))); + assertThat(tempFile.setLastModified(tempFile.lastModified() + 5000)).isTrue(); + assertThat(cacheValue.isCurrent(new ParquetInputFormat.FileStatusWrapper( + fs.getFileStatus(new Path(tempFile.getAbsolutePath()))))) + .isFalse(); } @Test @@ -374,14 +358,14 @@ public void testFooterCacheValueIsNewer() throws IOException { FileSystem fs = FileSystem.getLocal(new Configuration()); ParquetInputFormat.FootersCacheValue cacheValue = getDummyCacheValue(tempFile, fs); - assertTrue(cacheValue.isNewerThan(null)); - assertFalse(cacheValue.isNewerThan(cacheValue)); + assertThat(cacheValue.isNewerThan(null)).isTrue(); + assertThat(cacheValue.isNewerThan(cacheValue)).isFalse(); - assertTrue(tempFile.setLastModified(tempFile.lastModified() + 5000)); + assertThat(tempFile.setLastModified(tempFile.lastModified() + 5000)).isTrue(); ParquetInputFormat.FootersCacheValue newerCacheValue = getDummyCacheValue(tempFile, fs); - assertTrue(newerCacheValue.isNewerThan(cacheValue)); - assertFalse(cacheValue.isNewerThan(newerCacheValue)); + assertThat(newerCacheValue.isNewerThan(cacheValue)).isTrue(); + assertThat(cacheValue.isNewerThan(newerCacheValue)).isFalse(); } @Test @@ -417,7 +401,7 @@ public void testGetFootersReturnsInPredictableOrder() throws IOException { for (int i = 0; i < numFiles; i++) { Footer footer = footers.get(i); File file = new File(tempDir, String.format("part-%05d.parquet", i)); - assertEquals(file.toURI().toString(), footer.getFile().toString()); + assertThat(footer.getFile()).asString().isEqualTo(file.toURI().toString()); } } @@ -464,7 +448,7 @@ private ParquetInputFormat.FootersCacheValue getDummyCacheValue(File file, FileS ParquetMetadata mockMetadata = mock(ParquetMetadata.class); ParquetInputFormat.FootersCacheValue cacheValue = new ParquetInputFormat.FootersCacheValue(statusWrapper, new Footer(path, mockMetadata)); - assertTrue(cacheValue.isCurrent(statusWrapper)); + assertThat(cacheValue.isCurrent(statusWrapper)).isTrue(); return cacheValue; } @@ -504,35 +488,36 @@ private List generateSplitByDeprecatedConstructor(long min, l } private void shouldSplitStartBe(List splits, long... offsets) { - assertEquals(message(splits), offsets.length, splits.size()); + assertThat(splits).as(message(splits)).hasSameSizeAs(offsets); for (int i = 0; i < offsets.length; i++) { - assertEquals(message(splits) + i, offsets[i], splits.get(i).getStart()); + assertThat(splits.get(i).getStart()).as(message(splits) + i).isEqualTo(offsets[i]); } } private void shouldSplitBlockSizeBe(List splits, int... sizes) { - assertEquals(message(splits), sizes.length, splits.size()); + assertThat(splits).as(message(splits)).hasSameSizeAs(sizes); for (int i = 0; i < sizes.length; i++) { - assertEquals(message(splits) + i, sizes[i], splits.get(i).getRowGroupOffsets().length); + assertThat(splits.get(i).getRowGroupOffsets().length) + .as(message(splits) + i) + .isEqualTo(sizes[i]); } } private void shouldSplitLocationBe(List splits, int... locations) throws IOException { - assertEquals(message(splits), locations.length, splits.size()); + assertThat(splits).as(message(splits)).hasSameSizeAs(locations); for (int i = 0; i < locations.length; i++) { int loc = locations[i]; ParquetInputSplit split = splits.get(i); - assertEquals( - message(splits) + i, - "[foo" + loc + ".datanode, bar" + loc + ".datanode]", - Arrays.toString(split.getLocations())); + assertThat(Arrays.toString(split.getLocations())) + .as(message(splits) + i) + .isEqualTo("[foo" + loc + ".datanode, bar" + loc + ".datanode]"); } } private void shouldOneSplitRowGroupOffsetBe(ParquetInputSplit split, int... rowGroupOffsets) { - assertEquals(split.toString(), rowGroupOffsets.length, split.getRowGroupOffsets().length); + assertThat(split.getRowGroupOffsets()).hasSameSizeAs(rowGroupOffsets); for (int i = 0; i < rowGroupOffsets.length; i++) { - assertEquals(split.toString(), rowGroupOffsets[i], split.getRowGroupOffsets()[i]); + assertThat(split.getRowGroupOffsets()[i]).as(split.toString()).isEqualTo(rowGroupOffsets[i]); } } @@ -541,9 +526,9 @@ private String message(List splits) { } private void shouldSplitLengthBe(List splits, int... lengths) { - assertEquals(message(splits), lengths.length, splits.size()); + assertThat(splits).as(message(splits)).hasSameSizeAs(lengths); for (int i = 0; i < lengths.length; i++) { - assertEquals(message(splits) + i, lengths[i], splits.get(i).getLength()); + assertThat(splits.get(i).getLength()).as(message(splits) + i).isEqualTo(lengths[i]); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormatColumnProjection.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormatColumnProjection.java index 4fbf9d2df4..5fa8cf2b20 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormatColumnProjection.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormatColumnProjection.java @@ -21,6 +21,8 @@ import static java.lang.Thread.sleep; import static org.apache.parquet.schema.OriginalType.UTF8; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.BINARY; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assumptions.assumeThat; import java.io.File; import java.io.FileOutputStream; @@ -46,8 +48,6 @@ import org.apache.parquet.io.api.Binary; import org.apache.parquet.schema.MessageType; import org.apache.parquet.schema.Types; -import org.junit.Assert; -import org.junit.Assume; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -123,8 +123,7 @@ public TestInputFormatColumnProjection(boolean readType) { @Test public void testProjectionSize() throws Exception { - Assume.assumeTrue( // only run this test for Hadoop 2 - org.apache.hadoop.mapreduce.JobContext.class.isInterface()); + assumeThat(org.apache.hadoop.mapreduce.JobContext.class.isInterface()).isTrue(); File inputFile = temp.newFile(); FileOutputStream out = new FileOutputStream(inputFile); @@ -195,10 +194,10 @@ public void testProjectionSize() throws Exception { bytesRead = Reader.bytesReadCounter.getValue(); } - Assert.assertTrue( - "Should read (" + bytesRead + " bytes)" + " less than 10% of the input file size (" + bytesWritten - + ")", - bytesRead < (bytesWritten / 10)); + assertThat(bytesRead) + .as("Should read (" + bytesRead + " bytes)" + " less than 10% of the input file size (" + bytesWritten + + ")") + .isLessThan(bytesWritten / 10); } private void waitForJob(Job job) throws Exception { diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputOutputFormatWithPadding.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputOutputFormatWithPadding.java index 3a578449d2..f4895d2207 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputOutputFormatWithPadding.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputOutputFormatWithPadding.java @@ -21,6 +21,7 @@ import static java.lang.Thread.sleep; import static org.apache.parquet.schema.OriginalType.UTF8; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.BINARY; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.FileOutputStream; @@ -48,7 +49,6 @@ import org.apache.parquet.io.api.Binary; import org.apache.parquet.schema.MessageType; import org.apache.parquet.schema.Types; -import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -157,7 +157,9 @@ public void testBasicBehaviorWithPadding() throws Exception { ParquetMetadata footer = ParquetFileReader.readFooter( conf, new Path(parquetFile.toString()), ParquetMetadataConverter.NO_FILTER); for (BlockMetaData block : footer.getBlocks()) { - Assert.assertTrue("Block should start at a multiple of the block size", block.getStartingPos() % 1024 == 0); + assertThat(block.getStartingPos() % 1024) + .as("Block should start at a multiple of the block size") + .isZero(); } { @@ -175,14 +177,14 @@ public void testBasicBehaviorWithPadding() throws Exception { } File dataFile = getDataFile(outputFolder); - Assert.assertNotNull("Should find a data file", dataFile); + assertThat(dataFile).as("Should find a data file").isNotNull(); StringBuilder contentBuilder = new StringBuilder(); for (String line : Files.readAllLines(dataFile.toPath(), StandardCharsets.UTF_8)) { contentBuilder.append(line); } String reconstructed = contentBuilder.toString(); - Assert.assertEquals("Should match written file content", FILE_CONTENT, reconstructed); + assertThat(reconstructed).as("Should match written file content").isEqualTo(FILE_CONTENT); HadoopOutputFile.getBlockFileSystems().remove("file"); } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadByteStreamSplit.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadByteStreamSplit.java index 73ae799226..c08fedd1f8 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadByteStreamSplit.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadByteStreamSplit.java @@ -19,10 +19,7 @@ package org.apache.parquet.hadoop; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import org.apache.hadoop.fs.Path; @@ -46,32 +43,32 @@ public void testReadFloats() throws IOException { ParquetReader.builder(new GroupReadSupport(), floatsFile).build()) { for (int i = 0; i < expectRows; ++i) { Group group = reader.read(); - assertNotNull(group); + assertThat(group).isNotNull(); float fval = group.getFloat("f32", 0); double dval = group.getDouble("f64", 0); // Values are from the normal distribution - assertTrue(Math.abs(fval) < 4.0); - assertTrue(Math.abs(dval) < 4.0); + assertThat(Math.abs(fval)).isLessThan(4.0f); + assertThat(Math.abs(dval)).isLessThan(4.0); switch (i) { case 0: - assertEquals(1.7640524f, fval, 0.0); - assertEquals(-1.3065268517353166, dval, 0.0); + assertThat(fval).isEqualTo(1.7640524f); + assertThat(dval).isEqualTo(-1.3065268517353166); break; case 1: - assertEquals(0.4001572f, fval, 0.0); - assertEquals(1.658130679618188, dval, 0.0); + assertThat(fval).isEqualTo(0.4001572f); + assertThat(dval).isEqualTo(1.658130679618188); break; case expectRows - 2: - assertEquals(-0.39944902f, fval, 0.0); - assertEquals(-0.9301565025243212, dval, 0.0); + assertThat(fval).isEqualTo(-0.39944902f); + assertThat(dval).isEqualTo(-0.9301565025243212); break; case expectRows - 1: - assertEquals(0.37005588f, fval, 0.0); - assertEquals(-0.17858909208732915, dval, 0.0); + assertThat(fval).isEqualTo(0.37005588f); + assertThat(dval).isEqualTo(-0.17858909208732915); break; } } - assertNull(reader.read()); + assertThat(reader.read()).isNull(); } } @@ -80,12 +77,12 @@ private void compareColumnValues(Path path, int expectRows, String leftCol, Stri ParquetReader.builder(new GroupReadSupport(), path).build()) { for (int i = 0; i < expectRows; ++i) { SimpleGroup group = (SimpleGroup) reader.read(); - assertNotNull(group); + assertThat(group).isNotNull(); Object left = group.getObject(leftCol, 0); Object right = group.getObject(rightCol, 0); - assertEquals(left, right); + assertThat(right).isEqualTo(left); } - assertNull(reader.read()); + assertThat(reader.read()).isNull(); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadFloat16.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadFloat16.java index 9ae3cfe297..0a47185230 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadFloat16.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadFloat16.java @@ -19,9 +19,7 @@ package org.apache.parquet.hadoop; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import org.apache.hadoop.conf.Configuration; @@ -61,25 +59,24 @@ public void testInterOpReadFloat16NonZerosAndNansParquetFiles() throws IOExcepti ColumnChunkMetaData column = reader.getFooter().getBlocks().get(0).getColumns().get(0); - assertArrayEquals( - new byte[] {0x00, (byte) 0xc0}, column.getStatistics().getMinBytes()); + assertThat(column.getStatistics().getMinBytes()).isEqualTo(new byte[] {0x00, (byte) 0xc0}); // 0x40 equals @ in ASCII - assertArrayEquals(new byte[] {0x00, 0x40}, column.getStatistics().getMaxBytes()); + assertThat(column.getStatistics().getMaxBytes()).isEqualTo(new byte[] {0x00, (byte) 0x40}); } try (ParquetReader reader = ParquetReader.builder(new GroupReadSupport(), filePath).build()) { for (int i = 0; i < expectRows; ++i) { Group group = reader.read(); - if (group == null) { - fail("Should not reach end of file before " + expectRows + " rows"); - } + assertThat(group) + .as("Should not reach end of file before " + expectRows + " rows") + .isNotNull(); if (group.getFieldRepetitionCount(0) != 0) { // Check if the field is not null - assertEquals(c0ExpectValues[i], group.getBinary(0, 0)); + assertThat(group.getBinary(0, 0)).isEqualTo(c0ExpectValues[i]); } else { // Check if the field is null - assertEquals(0, i); + assertThat(i).isEqualTo(0); } } } @@ -101,24 +98,23 @@ public void testInterOpReadFloat16ZerosAndNansParquetFiles() throws IOException ColumnChunkMetaData column = reader.getFooter().getBlocks().get(0).getColumns().get(0); - assertArrayEquals( - new byte[] {0x00, (byte) 0x80}, column.getStatistics().getMinBytes()); - assertArrayEquals(new byte[] {0x00, 0x00}, column.getStatistics().getMaxBytes()); + assertThat(column.getStatistics().getMinBytes()).isEqualTo(new byte[] {0x00, (byte) 0x80}); + assertThat(column.getStatistics().getMaxBytes()).isEqualTo(new byte[] {0x00, 0x00}); } try (ParquetReader reader = ParquetReader.builder(new GroupReadSupport(), filePath).build()) { for (int i = 0; i < expectRows; ++i) { Group group = reader.read(); - if (group == null) { - fail("Should not reach end of file before " + expectRows + " rows"); - } + assertThat(group) + .as("Should not reach end of file before " + expectRows + " rows") + .isNotNull(); if (group.getFieldRepetitionCount(0) != 0) { // Check if the field is not null - assertEquals(c0ExpectValues[i], group.getBinary(0, 0)); + assertThat(group.getBinary(0, 0)).isEqualTo(c0ExpectValues[i]); } else { // Check if the field is null - assertEquals(0, i); + assertThat(i).isEqualTo(0); } } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadFloatingPointNanCount.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadFloatingPointNanCount.java index 52226b07c2..f3ffd57263 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadFloatingPointNanCount.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadFloatingPointNanCount.java @@ -19,10 +19,7 @@ package org.apache.parquet.hadoop; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import java.nio.ByteBuffer; @@ -112,7 +109,7 @@ private static void verifyFile(Path file, Configuration conf, Scenario... scenar .withConf(conf) .build()) { List blocks = reader.getFooter().getBlocks(); - assertEquals(scenarios.length, blocks.size()); + assertThat(blocks).hasSameSizeAs(scenarios); // Verify read values int rowId = 0; @@ -124,16 +121,16 @@ private static void verifyFile(Path file, Configuration conf, Scenario... scenar assertDoubleValue(expectDoubles.get(rowId), group.getDouble("double_ieee754", 0)); assertDoubleValue(expectDoubles.get(rowId), group.getDouble("double_typedef", 0)); - assertEquals(expectFloat16s.get(rowId), group.getBinary("float16_ieee754", 0)); - assertEquals(expectFloat16s.get(rowId), group.getBinary("float16_typedef", 0)); + assertThat(group.getBinary("float16_ieee754", 0)).isEqualTo(expectFloat16s.get(rowId)); + assertThat(group.getBinary("float16_typedef", 0)).isEqualTo(expectFloat16s.get(rowId)); rowId++; } - assertEquals(10 * scenarios.length, rowId); + assertThat(rowId).isEqualTo(10 * scenarios.length); // Verify stats for (int rg = 0; rg < blocks.size(); rg++) { BlockMetaData block = blocks.get(rg); - assertEquals(10L, block.getRowCount()); + assertThat(block.getRowCount()).isEqualTo(10L); for (ColumnChunkMetaData column : block.getColumns()) { verifyStats(scenarios[rg], column); verifyColumnIndex(reader, scenarios[rg], column); @@ -145,7 +142,7 @@ private static void verifyFile(Path file, Configuration conf, Scenario... scenar private static void verifyStats(Scenario scenario, ColumnChunkMetaData column) { String name = column.getPath().toDotString(); Statistics stats = column.getStatistics(); - assertTrue(stats.isNanCountSet()); + assertThat(stats.isNanCountSet()).isTrue(); if (name.contains("float16")) { verifyFloat16Stats(scenario, name, (BinaryStatistics) stats); @@ -158,111 +155,110 @@ private static void verifyStats(Scenario scenario, ColumnChunkMetaData column) { private static void verifyFloatStats(Scenario scenario, String name, FloatStatistics stats) { if (scenario == Scenario.NO_NAN) { - assertEquals(0L, stats.getNanCount()); - assertEquals(-2f, stats.getMin(), 0f); - assertEquals(5f, stats.getMax(), 0f); + assertThat(stats.getNanCount()).isEqualTo(0L); + assertThat(stats.getMin()).isEqualTo(-2f); + assertThat(stats.getMax()).isEqualTo(5f); return; } if (scenario == Scenario.MIXED_NAN) { - assertEquals(4L, stats.getNanCount()); + assertThat(stats.getNanCount()).isEqualTo(4L); if (isIeee(name)) { - assertEquals(-2f, stats.getMin(), 0f); - assertEquals(3f, stats.getMax(), 0f); + assertThat(stats.getMin()).isEqualTo(-2f); + assertThat(stats.getMax()).isEqualTo(3f); } return; } if (scenario == Scenario.ALL_NAN) { - assertEquals(10L, stats.getNanCount()); + assertThat(stats.getNanCount()).isEqualTo(10L); if (isIeee(name)) { - assertEquals(0xffffffff, Float.floatToRawIntBits(stats.getMin())); - assertEquals(0x7fffffff, Float.floatToRawIntBits(stats.getMax())); + assertThat(Float.floatToRawIntBits(stats.getMin())).isEqualTo(0xffffffff); + assertThat(Float.floatToRawIntBits(stats.getMax())).isEqualTo(0x7fffffff); } return; } if (scenario == Scenario.ZERO_MIN) { - assertEquals(0L, stats.getNanCount()); - assertEquals(isIeee(name) ? 0x00000000 : 0x80000000, Float.floatToRawIntBits(stats.getMin())); - assertEquals(5f, stats.getMax(), 0f); + assertThat(stats.getNanCount()).isEqualTo(0L); + assertThat(Float.floatToRawIntBits(stats.getMin())).isEqualTo(isIeee(name) ? 0x00000000 : 0x80000000); + assertThat(stats.getMax()).isEqualTo(5f); return; } - assertEquals(0L, stats.getNanCount()); - assertEquals(-5f, stats.getMin(), 0f); - assertEquals(isIeee(name) ? 0x80000000 : 0x00000000, Float.floatToRawIntBits(stats.getMax())); + assertThat(stats.getNanCount()).isEqualTo(0L); + assertThat(stats.getMin()).isEqualTo(-5f); + assertThat(Float.floatToRawIntBits(stats.getMax())).isEqualTo(isIeee(name) ? 0x80000000 : 0x00000000); } private static void verifyDoubleStats(Scenario scenario, String name, DoubleStatistics stats) { if (scenario == Scenario.NO_NAN) { - assertEquals(0L, stats.getNanCount()); - assertEquals(-2d, stats.getMin(), 0d); - assertEquals(5d, stats.getMax(), 0d); + assertThat(stats.getNanCount()).isEqualTo(0L); + assertThat(stats.getMin()).isEqualTo(-2d); + assertThat(stats.getMax()).isEqualTo(5d); return; } if (scenario == Scenario.MIXED_NAN) { - assertEquals(4L, stats.getNanCount()); + assertThat(stats.getNanCount()).isEqualTo(4L); if (isIeee(name)) { - assertEquals(-2d, stats.getMin(), 0d); - assertEquals(3d, stats.getMax(), 0d); + assertThat(stats.getMin()).isEqualTo(-2d); + assertThat(stats.getMax()).isEqualTo(3d); } return; } if (scenario == Scenario.ALL_NAN) { - assertEquals(10L, stats.getNanCount()); + assertThat(stats.getNanCount()).isEqualTo(10L); if (isIeee(name)) { - assertEquals(0xffffffffffffffffL, Double.doubleToRawLongBits(stats.getMin())); - assertEquals(0x7fffffffffffffffL, Double.doubleToRawLongBits(stats.getMax())); + assertThat(Double.doubleToRawLongBits(stats.getMin())).isEqualTo(0xffffffffffffffffL); + assertThat(Double.doubleToRawLongBits(stats.getMax())).isEqualTo(0x7fffffffffffffffL); } return; } if (scenario == Scenario.ZERO_MIN) { - assertEquals(0L, stats.getNanCount()); - assertEquals( - isIeee(name) ? 0x0000000000000000L : 0x8000000000000000L, - Double.doubleToRawLongBits(stats.getMin())); - assertEquals(5d, stats.getMax(), 0d); + assertThat(stats.getNanCount()).isEqualTo(0L); + assertThat(Double.doubleToRawLongBits(stats.getMin())) + .isEqualTo(isIeee(name) ? 0x0000000000000000L : 0x8000000000000000L); + assertThat(stats.getMax()).isEqualTo(5d); return; } - assertEquals(0L, stats.getNanCount()); - assertEquals(-5d, stats.getMin(), 0d); - assertEquals( - isIeee(name) ? 0x8000000000000000L : 0x0000000000000000L, Double.doubleToRawLongBits(stats.getMax())); + assertThat(stats.getNanCount()).isEqualTo(0L); + assertThat(stats.getMin()).isEqualTo(-5d); + assertThat(Double.doubleToRawLongBits(stats.getMax())) + .isEqualTo(isIeee(name) ? 0x8000000000000000L : 0x0000000000000000L); } private static void verifyFloat16Stats(Scenario scenario, String name, BinaryStatistics stats) { if (scenario == Scenario.NO_NAN) { short min = stats.genericGetMin().get2BytesLittleEndian(); short max = stats.genericGetMax().get2BytesLittleEndian(); - assertEquals(0L, stats.getNanCount()); - assertEquals((short) 0xc000, min); - assertEquals((short) 0x4500, max); + assertThat(stats.getNanCount()).isEqualTo(0L); + assertThat(min).isEqualTo((short) 0xc000); + assertThat(max).isEqualTo((short) 0x4500); return; } if (scenario == Scenario.MIXED_NAN) { - assertEquals(4L, stats.getNanCount()); + assertThat(stats.getNanCount()).isEqualTo(4L); if (isIeee(name)) { short min = stats.genericGetMin().get2BytesLittleEndian(); short max = stats.genericGetMax().get2BytesLittleEndian(); - assertEquals((short) 0xc000, min); - assertEquals((short) 0x4200, max); + assertThat(min).isEqualTo((short) 0xc000); + assertThat(max).isEqualTo((short) 0x4200); } return; } if (scenario == Scenario.ALL_NAN) { - assertEquals(10L, stats.getNanCount()); + assertThat(stats.getNanCount()).isEqualTo(10L); if (isIeee(name)) { short min = stats.genericGetMin().get2BytesLittleEndian(); short max = stats.genericGetMax().get2BytesLittleEndian(); - assertEquals((short) 0xffff, min); - assertEquals((short) 0x7fff, max); + assertThat(min).isEqualTo((short) 0xffff); + assertThat(max).isEqualTo((short) 0x7fff); } return; } @@ -270,23 +266,23 @@ private static void verifyFloat16Stats(Scenario scenario, String name, BinarySta if (scenario == Scenario.ZERO_MIN) { short min = stats.genericGetMin().get2BytesLittleEndian(); short max = stats.genericGetMax().get2BytesLittleEndian(); - assertEquals(0L, stats.getNanCount()); - assertEquals((short) (isIeee(name) ? 0x0000 : 0x8000), min); - assertEquals((short) 0x4500, max); + assertThat(stats.getNanCount()).isEqualTo(0L); + assertThat(min).isEqualTo((short) (isIeee(name) ? 0x0000 : 0x8000)); + assertThat(max).isEqualTo((short) 0x4500); return; } - assertEquals(0L, stats.getNanCount()); + assertThat(stats.getNanCount()).isEqualTo(0L); if (isIeee(name)) { short min = stats.genericGetMin().get2BytesLittleEndian(); short max = stats.genericGetMax().get2BytesLittleEndian(); - assertEquals((short) 0xc500, min); - assertEquals((short) 0x8000, max); + assertThat(min).isEqualTo((short) 0xc500); + assertThat(max).isEqualTo((short) 0x8000); } else { short min = stats.genericGetMin().get2BytesLittleEndian(); short max = stats.genericGetMax().get2BytesLittleEndian(); - assertEquals((short) 0xc500, min); - assertEquals((short) 0x0000, max); + assertThat(min).isEqualTo((short) 0xc500); + assertThat(max).isEqualTo((short) 0x0000); } } @@ -299,18 +295,17 @@ private static void verifyColumnIndex(ParquetFileReader reader, Scenario scenari ColumnIndex columnIndex = reader.readColumnIndex(column); if (!ieee && hasNaN) { // TypeDefinedOrder + NaN => page index is intentionally invalidated. - assertNull(columnIndex); + assertThat(columnIndex).isNull(); return; } - assertNotNull(columnIndex); - assertNotNull(columnIndex.getNanCounts()); - assertEquals(1, columnIndex.getNanCounts().size()); - assertEquals( - expectedNanCount(scenario), (long) columnIndex.getNanCounts().get(0)); + assertThat(columnIndex).isNotNull(); + assertThat(columnIndex.getNanCounts()).isNotNull(); + assertThat(columnIndex.getNanCounts()).hasSize(1); + assertThat((long) columnIndex.getNanCounts().get(0)).isEqualTo(expectedNanCount(scenario)); - assertEquals(1, columnIndex.getMinValues().size()); - assertEquals(1, columnIndex.getMaxValues().size()); + assertThat(columnIndex.getMinValues()).hasSize(1); + assertThat(columnIndex.getMaxValues()).hasSize(1); ByteBuffer min = columnIndex.getMinValues().get(0).order(ByteOrder.LITTLE_ENDIAN); ByteBuffer max = columnIndex.getMaxValues().get(0).order(ByteOrder.LITTLE_ENDIAN); @@ -342,17 +337,17 @@ private static void verifyFloat16ColumnIndexBounds( short minV = min.getShort(0); short maxV = max.getShort(0); if (scenario == Scenario.ALL_NAN) { - assertEquals((short) 0xffff, minV); - assertEquals((short) 0x7fff, maxV); + assertThat(minV).isEqualTo((short) 0xffff); + assertThat(maxV).isEqualTo((short) 0x7fff); } else if (scenario == Scenario.MIXED_NAN || scenario == Scenario.NO_NAN) { - assertEquals((short) 0xc000, minV); - assertEquals((short) (scenario == Scenario.MIXED_NAN ? 0x4200 : 0x4500), maxV); + assertThat(minV).isEqualTo((short) 0xc000); + assertThat(maxV).isEqualTo((short) (scenario == Scenario.MIXED_NAN ? 0x4200 : 0x4500)); } else if (scenario == Scenario.ZERO_MIN) { - assertEquals((short) (ieee ? 0x0000 : 0x8000), minV); - assertEquals((short) 0x4500, maxV); + assertThat(minV).isEqualTo((short) (ieee ? 0x0000 : 0x8000)); + assertThat(maxV).isEqualTo((short) 0x4500); } else { - assertEquals((short) 0xc500, minV); - assertEquals((short) (ieee ? 0x8000 : 0x0000), maxV); + assertThat(minV).isEqualTo((short) 0xc500); + assertThat(maxV).isEqualTo((short) (ieee ? 0x8000 : 0x0000)); } } @@ -360,17 +355,17 @@ private static void verifyDoubleColumnIndexBounds(Scenario scenario, boolean iee long minV = min.getLong(0); long maxV = max.getLong(0); if (scenario == Scenario.ALL_NAN) { - assertEquals(0xffffffffffffffffL, minV); - assertEquals(0x7fffffffffffffffL, maxV); + assertThat(minV).isEqualTo(0xffffffffffffffffL); + assertThat(maxV).isEqualTo(0x7fffffffffffffffL); } else if (scenario == Scenario.MIXED_NAN || scenario == Scenario.NO_NAN) { - assertEquals(Double.doubleToRawLongBits(-2d), minV); - assertEquals(Double.doubleToRawLongBits(scenario == Scenario.MIXED_NAN ? 3d : 5d), maxV); + assertThat(minV).isEqualTo(Double.doubleToRawLongBits(-2d)); + assertThat(maxV).isEqualTo(Double.doubleToRawLongBits(scenario == Scenario.MIXED_NAN ? 3d : 5d)); } else if (scenario == Scenario.ZERO_MIN) { - assertEquals(Double.doubleToRawLongBits(ieee ? 0d : -0d), minV); - assertEquals(Double.doubleToRawLongBits(5d), maxV); + assertThat(minV).isEqualTo(Double.doubleToRawLongBits(ieee ? 0d : -0d)); + assertThat(maxV).isEqualTo(Double.doubleToRawLongBits(5d)); } else { - assertEquals(Double.doubleToRawLongBits(-5d), minV); - assertEquals(Double.doubleToRawLongBits(ieee ? -0d : 0d), maxV); + assertThat(minV).isEqualTo(Double.doubleToRawLongBits(-5d)); + assertThat(maxV).isEqualTo(Double.doubleToRawLongBits(ieee ? -0d : 0d)); } } @@ -378,17 +373,17 @@ private static void verifyFloatColumnIndexBounds(Scenario scenario, boolean ieee int minV = min.getInt(0); int maxV = max.getInt(0); if (scenario == Scenario.ALL_NAN) { - assertEquals(0xffffffff, minV); - assertEquals(0x7fffffff, maxV); + assertThat(minV).isEqualTo(0xffffffff); + assertThat(maxV).isEqualTo(0x7fffffff); } else if (scenario == Scenario.MIXED_NAN || scenario == Scenario.NO_NAN) { - assertEquals(Float.floatToRawIntBits(-2f), minV); - assertEquals(Float.floatToRawIntBits(scenario == Scenario.MIXED_NAN ? 3f : 5f), maxV); + assertThat(minV).isEqualTo(Float.floatToRawIntBits(-2f)); + assertThat(maxV).isEqualTo(Float.floatToRawIntBits(scenario == Scenario.MIXED_NAN ? 3f : 5f)); } else if (scenario == Scenario.ZERO_MIN) { - assertEquals(Float.floatToRawIntBits(ieee ? 0f : -0f), minV); - assertEquals(Float.floatToRawIntBits(5f), maxV); + assertThat(minV).isEqualTo(Float.floatToRawIntBits(ieee ? 0f : -0f)); + assertThat(maxV).isEqualTo(Float.floatToRawIntBits(5f)); } else { - assertEquals(Float.floatToRawIntBits(-5f), minV); - assertEquals(Float.floatToRawIntBits(ieee ? -0f : 0f), maxV); + assertThat(minV).isEqualTo(Float.floatToRawIntBits(-5f)); + assertThat(maxV).isEqualTo(Float.floatToRawIntBits(ieee ? -0f : 0f)); } } @@ -397,11 +392,11 @@ private static boolean isIeee(String columnName) { } private static void assertFloatValue(float expected, float actual) { - assertEquals(Float.floatToRawIntBits(expected), Float.floatToRawIntBits(actual)); + assertThat(Float.floatToRawIntBits(actual)).isEqualTo(Float.floatToRawIntBits(expected)); } private static void assertDoubleValue(double expected, double actual) { - assertEquals(Double.doubleToRawLongBits(expected), Double.doubleToRawLongBits(actual)); + assertThat(Double.doubleToRawLongBits(actual)).isEqualTo(Double.doubleToRawLongBits(expected)); } private static List concatFloatValues(Scenario... scenarios) { diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInteropBloomFilter.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInteropBloomFilter.java index 66e86ce2b7..8e2e473c68 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInteropBloomFilter.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInteropBloomFilter.java @@ -19,10 +19,8 @@ package org.apache.parquet.hadoop; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; import java.io.IOException; import java.util.List; @@ -41,7 +39,6 @@ import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData; import org.apache.parquet.hadoop.util.HadoopInputFile; import org.apache.parquet.io.api.Binary; -import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,10 +87,8 @@ public void testReadDataIndexBloomParquetFiles() throws IOException { ParquetReader.builder(new GroupReadSupport(), filePath).build()) { for (int i = 0; i < expectedRowCount; ++i) { Group group = reader.read(); - if (group == null) { - fail("Should not reach end of file"); - } - assertEquals(expectedValues[i], group.getString(0, 0)); + assertThat(group).as("Should not reach end of file").isNotNull(); + assertThat(group.getString(0, 0)).isEqualTo(expectedValues[i]); } } @@ -101,30 +96,29 @@ public void testReadDataIndexBloomParquetFiles() throws IOException { HadoopInputFile.fromPath(filePath, new Configuration()), ParquetReadOptions.builder().build()); List blocks = reader.getRowGroups(); - blocks.forEach(block -> { - try { - assertEquals(14, block.getRowCount()); - ColumnChunkMetaData idMeta = block.getColumns().get(0); - BloomFilter bloomFilter = reader.readBloomFilter(idMeta); - Assert.assertNotNull(bloomFilter); - assertEquals(192, idMeta.getBloomFilterOffset()); - assertEquals(-1, idMeta.getBloomFilterLength()); - for (int i = 0; i < expectedRowCount; ++i) { - assertTrue(bloomFilter.findHash(bloomFilter.hash(Binary.fromString(expectedValues[i])))); - } - for (int i = 0; i < unexpectedValues.length; ++i) { - assertFalse(bloomFilter.findHash(bloomFilter.hash(Binary.fromString(unexpectedValues[i])))); - } - assertEquals(152, idMeta.getTotalSize()); - assertEquals(163, idMeta.getTotalUncompressedSize()); - assertEquals(181, idMeta.getOffsetIndexReference().getOffset()); - assertEquals(11, idMeta.getOffsetIndexReference().getLength()); - assertEquals(156, idMeta.getColumnIndexReference().getOffset()); - assertEquals(25, idMeta.getColumnIndexReference().getLength()); - } catch (IOException e) { - fail("Should not throw exception: " + e.getMessage()); - } - }); + blocks.forEach(block -> assertThatCode(() -> { + assertThat(block.getRowCount()).isEqualTo(14); + ColumnChunkMetaData idMeta = block.getColumns().get(0); + BloomFilter bloomFilter = reader.readBloomFilter(idMeta); + assertThat(bloomFilter).isNotNull(); + assertThat(idMeta.getBloomFilterOffset()).isEqualTo(192); + assertThat(idMeta.getBloomFilterLength()).isEqualTo(-1); + for (int i = 0; i < expectedRowCount; ++i) { + assertThat(bloomFilter.findHash(bloomFilter.hash(Binary.fromString(expectedValues[i])))) + .isTrue(); + } + for (int i = 0; i < unexpectedValues.length; ++i) { + assertThat(bloomFilter.findHash(bloomFilter.hash(Binary.fromString(unexpectedValues[i])))) + .isFalse(); + } + assertThat(idMeta.getTotalSize()).isEqualTo(152); + assertThat(idMeta.getTotalUncompressedSize()).isEqualTo(163); + assertThat(idMeta.getOffsetIndexReference().getOffset()).isEqualTo(181); + assertThat(idMeta.getOffsetIndexReference().getLength()).isEqualTo(11); + assertThat(idMeta.getColumnIndexReference().getOffset()).isEqualTo(156); + assertThat(idMeta.getColumnIndexReference().getLength()).isEqualTo(25); + }) + .doesNotThrowAnyException()); } @Test @@ -158,10 +152,8 @@ public void testReadDataIndexBloomWithLengthParquetFiles() throws IOException { ParquetReader.builder(new GroupReadSupport(), filePath).build()) { for (int i = 0; i < expectedRowCount; ++i) { Group group = reader.read(); - if (group == null) { - fail("Should not reach end of file"); - } - assertEquals(expectedValues[i], group.getString(0, 0)); + assertThat(group).as("Should not reach end of file").isNotNull(); + assertThat(group.getString(0, 0)).isEqualTo(expectedValues[i]); } } @@ -169,30 +161,29 @@ public void testReadDataIndexBloomWithLengthParquetFiles() throws IOException { HadoopInputFile.fromPath(filePath, new Configuration()), ParquetReadOptions.builder().build()); List blocks = reader.getRowGroups(); - blocks.forEach(block -> { - try { - assertEquals(14, block.getRowCount()); - ColumnChunkMetaData idMeta = block.getColumns().get(0); - BloomFilter bloomFilter = reader.readBloomFilter(idMeta); - Assert.assertNotNull(bloomFilter); - assertEquals(253, idMeta.getBloomFilterOffset()); - assertEquals(2064, idMeta.getBloomFilterLength()); - for (int i = 0; i < expectedRowCount; ++i) { - assertTrue(bloomFilter.findHash(bloomFilter.hash(Binary.fromString(expectedValues[i])))); - } - for (int i = 0; i < unexpectedValues.length; ++i) { - assertFalse(bloomFilter.findHash(bloomFilter.hash(Binary.fromString(unexpectedValues[i])))); - } - assertEquals(199, idMeta.getTotalSize()); - assertEquals(199, idMeta.getTotalUncompressedSize()); - assertEquals(2342, idMeta.getOffsetIndexReference().getOffset()); - assertEquals(11, idMeta.getOffsetIndexReference().getLength()); - assertEquals(2317, idMeta.getColumnIndexReference().getOffset()); - assertEquals(25, idMeta.getColumnIndexReference().getLength()); - } catch (Exception e) { - fail("Should not throw exception: " + e.getMessage()); - } - }); + blocks.forEach(block -> assertThatCode(() -> { + assertThat(block.getRowCount()).isEqualTo(14); + ColumnChunkMetaData idMeta = block.getColumns().get(0); + BloomFilter bloomFilter = reader.readBloomFilter(idMeta); + assertThat(bloomFilter).isNotNull(); + assertThat(idMeta.getBloomFilterOffset()).isEqualTo(253); + assertThat(idMeta.getBloomFilterLength()).isEqualTo(2064); + for (int i = 0; i < expectedRowCount; ++i) { + assertThat(bloomFilter.findHash(bloomFilter.hash(Binary.fromString(expectedValues[i])))) + .isTrue(); + } + for (int i = 0; i < unexpectedValues.length; ++i) { + assertThat(bloomFilter.findHash(bloomFilter.hash(Binary.fromString(unexpectedValues[i])))) + .isFalse(); + } + assertThat(idMeta.getTotalSize()).isEqualTo(199); + assertThat(idMeta.getTotalUncompressedSize()).isEqualTo(199); + assertThat(idMeta.getOffsetIndexReference().getOffset()).isEqualTo(2342); + assertThat(idMeta.getOffsetIndexReference().getLength()).isEqualTo(11); + assertThat(idMeta.getColumnIndexReference().getOffset()).isEqualTo(2317); + assertThat(idMeta.getColumnIndexReference().getLength()).isEqualTo(25); + }) + .doesNotThrowAnyException()); } private Path downloadInterOpFiles(Path rootPath, String fileName, OkHttpClient httpClient) throws IOException { diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestLargeColumnChunk.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestLargeColumnChunk.java index 4fcc5e9f1c..83c733b3fc 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestLargeColumnChunk.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestLargeColumnChunk.java @@ -27,8 +27,7 @@ import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64; import static org.apache.parquet.schema.Types.buildMessage; import static org.apache.parquet.schema.Types.required; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import java.util.Random; @@ -119,10 +118,10 @@ public void validateAllData() throws IOException { ParquetReader.builder(new GroupReadSupport(), file).build()) { for (long id = 0; id < ROW_COUNT; ++id) { Group group = reader.read(); - assertEquals(id, group.getLong(ID_INDEX, 0)); - assertEquals(nextBinary(random), group.getBinary(DATA_INDEX, 0)); + assertThat(group.getLong(ID_INDEX, 0)).isEqualTo(id); + assertThat(group.getBinary(DATA_INDEX, 0)).isEqualTo(nextBinary(random)); } - assertNull("No more record should be read", reader.read()); + assertThat(reader.read()).as("No more record should be read").isNull(); } } @@ -132,14 +131,14 @@ public void validateFiltering() throws IOException { .withFilter(FilterCompat.get(eq(binaryColumn("data"), VALUE_IN_DATA))) .build()) { Group group = reader.read(); - assertEquals(ID_OF_FILTERED_DATA, group.getLong(ID_INDEX, 0)); - assertEquals(VALUE_IN_DATA, group.getBinary(DATA_INDEX, 0)); - assertNull("No more record should be read", reader.read()); + assertThat(group.getLong(ID_INDEX, 0)).isEqualTo(ID_OF_FILTERED_DATA); + assertThat(group.getBinary(DATA_INDEX, 0)).isEqualTo(VALUE_IN_DATA); + assertThat(reader.read()).as("No more record should be read").isNull(); } try (ParquetReader reader = ParquetReader.builder(new GroupReadSupport(), file) .withFilter(FilterCompat.get(eq(binaryColumn("data"), VALUE_NOT_IN_DATA))) .build()) { - assertNull("No record should be read", reader.read()); + assertThat(reader.read()).as("No record should be read").isNull(); } } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestLruCache.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestLruCache.java index 36514c8b7e..ead7a9aff4 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestLruCache.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestLruCache.java @@ -18,8 +18,7 @@ */ package org.apache.parquet.hadoop; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; @@ -59,14 +58,14 @@ public void testMaxSize() { SimpleValue oldValue = new SimpleValue(true, true); cache.put(oldKey, oldValue); - assertEquals(oldValue, cache.getCurrentValue(oldKey)); - assertEquals(1, cache.size()); + assertThat(cache.getCurrentValue(oldKey)).isEqualTo(oldValue); + assertThat(cache.size()).isOne(); SimpleValue newValue = new SimpleValue(true, true); cache.put(newKey, newValue); - assertNull(cache.getCurrentValue(oldKey)); - assertEquals(newValue, cache.getCurrentValue(newKey)); - assertEquals(1, cache.size()); + assertThat(cache.getCurrentValue(oldKey)).isNull(); + assertThat(cache.getCurrentValue(newKey)).isEqualTo(newValue); + assertThat(cache.size()).isOne(); } @Test @@ -77,8 +76,9 @@ public void testOlderValueIsIgnored() { SimpleValue notAsCurrentValue = new SimpleValue(true, false); cache.put(DEFAULT_KEY, currentValue); cache.put(DEFAULT_KEY, notAsCurrentValue); - assertEquals( - "The existing value in the cache was overwritten", currentValue, cache.getCurrentValue(DEFAULT_KEY)); + assertThat(cache.getCurrentValue(DEFAULT_KEY)) + .as("The existing value in the cache was overwritten") + .isEqualTo(currentValue); } @Test @@ -87,8 +87,8 @@ public void testOutdatedValueIsIgnored() { SimpleValue outdatedValue = new SimpleValue(false, true); cache.put(DEFAULT_KEY, outdatedValue); - assertEquals(0, cache.size()); - assertNull(cache.getCurrentValue(DEFAULT_KEY)); + assertThat(cache.size()).isZero(); + assertThat(cache.getCurrentValue(DEFAULT_KEY)).isNull(); } @Test @@ -98,13 +98,12 @@ public void testCurrentValueOverwritesExisting() { SimpleValue currentValue = new SimpleValue(true, true); SimpleValue notAsCurrentValue = new SimpleValue(true, false); cache.put(DEFAULT_KEY, notAsCurrentValue); - assertEquals(1, cache.size()); + assertThat(cache.size()).isOne(); cache.put(DEFAULT_KEY, currentValue); - assertEquals(1, cache.size()); - assertEquals( - "The existing value in the cache was NOT overwritten", - currentValue, - cache.getCurrentValue(DEFAULT_KEY)); + assertThat(cache.size()).isOne(); + assertThat(cache.getCurrentValue(DEFAULT_KEY)) + .as("The existing value in the cache was NOT overwritten") + .isEqualTo(currentValue); } @Test @@ -113,12 +112,14 @@ public void testGetOutdatedValueReturnsNull() { SimpleValue value = new SimpleValue(true, true); cache.put(DEFAULT_KEY, value); - assertEquals(1, cache.size()); - assertEquals(value, cache.getCurrentValue(DEFAULT_KEY)); + assertThat(cache.size()).isOne(); + assertThat(cache.getCurrentValue(DEFAULT_KEY)).isEqualTo(value); value.setCurrent(false); - assertNull("The value should not be current anymore", cache.getCurrentValue(DEFAULT_KEY)); - assertEquals(0, cache.size()); + assertThat(cache.getCurrentValue(DEFAULT_KEY)) + .as("The value should not be current anymore") + .isNull(); + assertThat(cache.size()).isZero(); } @Test @@ -127,13 +128,13 @@ public void testRemove() { SimpleValue value = new SimpleValue(true, true); cache.put(DEFAULT_KEY, value); - assertEquals(1, cache.size()); - assertEquals(value, cache.getCurrentValue(DEFAULT_KEY)); + assertThat(cache.size()).isOne(); + assertThat(cache.getCurrentValue(DEFAULT_KEY)).isEqualTo(value); // remove the only value - assertEquals(value, cache.remove(DEFAULT_KEY)); - assertNull(cache.getCurrentValue(DEFAULT_KEY)); - assertEquals(0, cache.size()); + assertThat(cache.remove(DEFAULT_KEY)).isEqualTo(value); + assertThat(cache.getCurrentValue(DEFAULT_KEY)).isNull(); + assertThat(cache.size()).isZero(); } @Test @@ -145,13 +146,13 @@ public void testClear() { SimpleValue value = new SimpleValue(true, true); cache.put(key1, value); cache.put(key2, value); - assertEquals(value, cache.getCurrentValue(key1)); - assertEquals(value, cache.getCurrentValue(key2)); - assertEquals(2, cache.size()); + assertThat(cache.getCurrentValue(key1)).isEqualTo(value); + assertThat(cache.getCurrentValue(key2)).isEqualTo(value); + assertThat(cache.size()).isEqualTo(2); cache.clear(); - assertNull(cache.getCurrentValue(key1)); - assertNull(cache.getCurrentValue(key2)); - assertEquals(0, cache.size()); + assertThat(cache.getCurrentValue(key1)).isNull(); + assertThat(cache.getCurrentValue(key2)).isNull(); + assertThat(cache.size()).isZero(); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMemoryManager.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMemoryManager.java index ae0c398f11..aaad5fb167 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMemoryManager.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMemoryManager.java @@ -18,6 +18,9 @@ */ package org.apache.parquet.hadoop; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import java.io.File; import java.lang.management.ManagementFactory; import java.util.Set; @@ -27,7 +30,6 @@ import org.apache.parquet.hadoop.example.GroupWriteSupport; import org.apache.parquet.hadoop.metadata.CompressionCodecName; import org.apache.parquet.schema.MessageTypeParser; -import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -66,10 +68,10 @@ public void testMemoryManagerUpperLimit() { // this value tends to change a little between setup and tests, so this // validates that it is within 15% of the expected value long poolSize = ParquetOutputFormat.getMemoryManager().getTotalMemoryPool(); - Assert.assertTrue( - "Pool size should be within 15% of the expected value" + " (expected = " + expectedPoolSize - + " actual = " + poolSize + ")", - Math.abs(expectedPoolSize - poolSize) < (long) (expectedPoolSize * 0.15)); + assertThat(Math.abs(expectedPoolSize - poolSize)) + .as("Pool size should be within 15% of the expected value" + " (expected = " + expectedPoolSize + + " actual = " + poolSize + ")") + .isLessThan((long) (expectedPoolSize * 0.15)); } @Test @@ -78,35 +80,52 @@ public void testMemoryManager() throws Exception { long rowGroupSize = poolSize / 2; conf.setLong(ParquetOutputFormat.BLOCK_SIZE, rowGroupSize); - Assert.assertTrue("Pool should hold 2 full row groups", (2 * rowGroupSize) <= poolSize); - Assert.assertTrue("Pool should not hold 3 full row groups", poolSize < (3 * rowGroupSize)); + assertThat(2 * rowGroupSize).as("Pool should hold 2 full row groups").isLessThanOrEqualTo(poolSize); + assertThat(poolSize).as("Pool should not hold 3 full row groups").isLessThan(3 * rowGroupSize); - Assert.assertEquals("Allocations should start out at 0", 0, getTotalAllocation()); + assertThat(getTotalAllocation()).as("Allocations should start out at 0").isEqualTo(0); RecordWriter writer1 = createWriter(1); - Assert.assertTrue("Allocations should never exceed pool size", getTotalAllocation() <= poolSize); - Assert.assertEquals("First writer should be limited by row group size", rowGroupSize, getTotalAllocation()); + assertThat(getTotalAllocation()) + .as("Allocations should never exceed pool size") + .isLessThanOrEqualTo(poolSize); + assertThat(getTotalAllocation()) + .as("First writer should be limited by row group size") + .isEqualTo(rowGroupSize); RecordWriter writer2 = createWriter(2); - Assert.assertTrue("Allocations should never exceed pool size", getTotalAllocation() <= poolSize); - Assert.assertEquals( - "Second writer should be limited by row group size", 2 * rowGroupSize, getTotalAllocation()); + assertThat(getTotalAllocation()) + .as("Allocations should never exceed pool size") + .isLessThanOrEqualTo(poolSize); + assertThat(getTotalAllocation()) + .as("Second writer should be limited by row group size") + .isEqualTo(2 * rowGroupSize); RecordWriter writer3 = createWriter(3); - Assert.assertTrue("Allocations should never exceed pool size", getTotalAllocation() <= poolSize); + assertThat(getTotalAllocation()) + .as("Allocations should never exceed pool size") + .isLessThanOrEqualTo(poolSize); writer1.close(null); - Assert.assertTrue("Allocations should never exceed pool size", getTotalAllocation() <= poolSize); - Assert.assertEquals( - "Allocations should be increased to the row group size", 2 * rowGroupSize, getTotalAllocation()); + assertThat(getTotalAllocation()) + .as("Allocations should never exceed pool size") + .isLessThanOrEqualTo(poolSize); + assertThat(getTotalAllocation()) + .as("Allocations should be increased to the row group size") + .isEqualTo(2 * rowGroupSize); writer2.close(null); - Assert.assertTrue("Allocations should never exceed pool size", getTotalAllocation() <= poolSize); - Assert.assertEquals( - "Allocations should be increased to the row group size", rowGroupSize, getTotalAllocation()); + assertThat(getTotalAllocation()) + .as("Allocations should never exceed pool size") + .isLessThanOrEqualTo(poolSize); + assertThat(getTotalAllocation()) + .as("Allocations should be increased to the row group size") + .isEqualTo(rowGroupSize); writer3.close(null); - Assert.assertEquals("Allocations should be increased to the row group size", 0, getTotalAllocation()); + assertThat(getTotalAllocation()) + .as("Allocations should be increased to the row group size") + .isEqualTo(0); } @Test @@ -116,20 +135,18 @@ public void testReallocationCallback() throws Exception { long rowGroupSize = poolSize / 2; conf.setLong(ParquetOutputFormat.BLOCK_SIZE, rowGroupSize); - Assert.assertTrue("Pool should hold 2 full row groups", (2 * rowGroupSize) <= poolSize); - Assert.assertTrue("Pool should not hold 3 full row groups", poolSize < (3 * rowGroupSize)); + assertThat(2 * rowGroupSize).as("Pool should hold 2 full row groups").isLessThanOrEqualTo(poolSize); + assertThat(poolSize).as("Pool should not hold 3 full row groups").isLessThan(3 * rowGroupSize); Runnable callback = () -> counter++; // first-time registration should succeed ParquetOutputFormat.getMemoryManager().registerScaleCallBack("increment-test-counter", callback); - try { - ParquetOutputFormat.getMemoryManager().registerScaleCallBack("increment-test-counter", callback); - Assert.fail("Duplicated registering callback should throw duplicates exception."); - } catch (IllegalArgumentException e) { - // expected - } + assertThatThrownBy(() -> ParquetOutputFormat.getMemoryManager() + .registerScaleCallBack("increment-test-counter", callback)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("The callBackName increment-test-counter is duplicated and has been registered already."); // hit the limit once and clean up RecordWriter writer1 = createWriter(1); @@ -140,11 +157,10 @@ public void testReallocationCallback() throws Exception { writer3.close(null); // Verify Callback mechanism - Assert.assertEquals("Allocations should be adjusted once", 1, counter); - Assert.assertEquals( - "Should not allow duplicate callbacks", - 1, - ParquetOutputFormat.getMemoryManager().getScaleCallBacks().size()); + assertThat(counter).as("Allocations should be adjusted once").isEqualTo(1); + assertThat(ParquetOutputFormat.getMemoryManager().getScaleCallBacks()) + .as("Should not allow duplicate callbacks") + .hasSize(1); } @Rule diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMergeMetadataFiles.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMergeMetadataFiles.java index 847074c147..06a3922ff9 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMergeMetadataFiles.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMergeMetadataFiles.java @@ -19,10 +19,8 @@ package org.apache.parquet.hadoop; import static org.apache.parquet.schema.MessageTypeParser.parseMessageType; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.File; import java.io.IOException; @@ -162,23 +160,20 @@ public void testMergeMetadataFiles() throws Exception { ParquetMetadata meta2 = ParquetFileReader.readFooter(info.conf, info.metaPath2, ParquetMetadataConverter.NO_FILTER); - assertTrue(commonMeta1.getBlocks().isEmpty()); - assertTrue(commonMeta2.getBlocks().isEmpty()); - assertEquals( - commonMeta1.getFileMetaData().getSchema(), - commonMeta2.getFileMetaData().getSchema()); + assertThat(commonMeta1.getBlocks()).isEmpty(); + assertThat(commonMeta2.getBlocks()).isEmpty(); + assertThat(commonMeta2.getFileMetaData().getSchema()) + .isEqualTo(commonMeta1.getFileMetaData().getSchema()); - assertFalse(meta1.getBlocks().isEmpty()); - assertFalse(meta2.getBlocks().isEmpty()); - assertEquals( - meta1.getFileMetaData().getSchema(), meta2.getFileMetaData().getSchema()); + assertThat(meta1.getBlocks()).isNotEmpty(); + assertThat(meta2.getBlocks()).isNotEmpty(); + assertThat(meta2.getFileMetaData().getSchema()) + .isEqualTo(meta1.getFileMetaData().getSchema()); - assertEquals( - commonMeta1.getFileMetaData().getKeyValueMetaData(), - commonMeta2.getFileMetaData().getKeyValueMetaData()); - assertEquals( - meta1.getFileMetaData().getKeyValueMetaData(), - meta2.getFileMetaData().getKeyValueMetaData()); + assertThat(commonMeta2.getFileMetaData().getKeyValueMetaData()) + .isEqualTo(commonMeta1.getFileMetaData().getKeyValueMetaData()); + assertThat(meta2.getFileMetaData().getKeyValueMetaData()) + .isEqualTo(meta1.getFileMetaData().getKeyValueMetaData()); // test file serialization Path mergedOut = new Path(new File(temp.getRoot(), "merged_meta").getAbsolutePath()); @@ -193,24 +188,19 @@ public void testMergeMetadataFiles() throws Exception { ParquetFileReader.readFooter(info.conf, mergedCommonOut, ParquetMetadataConverter.NO_FILTER); // ideally we'd assert equality here, but BlockMetaData and it's references don't implement equals - assertEquals( - meta1.getBlocks().size() + meta2.getBlocks().size(), - mergedMeta.getBlocks().size()); - assertTrue(mergedCommonMeta.getBlocks().isEmpty()); - - assertEquals( - meta1.getFileMetaData().getSchema(), - mergedMeta.getFileMetaData().getSchema()); - assertEquals( - commonMeta1.getFileMetaData().getSchema(), - mergedCommonMeta.getFileMetaData().getSchema()); - - assertEquals( - meta1.getFileMetaData().getKeyValueMetaData(), - mergedMeta.getFileMetaData().getKeyValueMetaData()); - assertEquals( - commonMeta1.getFileMetaData().getKeyValueMetaData(), - mergedCommonMeta.getFileMetaData().getKeyValueMetaData()); + assertThat(mergedMeta.getBlocks()) + .hasSize(meta1.getBlocks().size() + meta2.getBlocks().size()); + assertThat(mergedCommonMeta.getBlocks()).isEmpty(); + + assertThat(mergedMeta.getFileMetaData().getSchema()) + .isEqualTo(meta1.getFileMetaData().getSchema()); + assertThat(mergedCommonMeta.getFileMetaData().getSchema()) + .isEqualTo(commonMeta1.getFileMetaData().getSchema()); + + assertThat(mergedMeta.getFileMetaData().getKeyValueMetaData()) + .isEqualTo(meta1.getFileMetaData().getKeyValueMetaData()); + assertThat(mergedCommonMeta.getFileMetaData().getKeyValueMetaData()) + .isEqualTo(commonMeta1.getFileMetaData().getKeyValueMetaData()); } @Test @@ -220,29 +210,14 @@ public void testThrowsWhenIncompatible() throws Exception { Path mergedOut = new Path(new File(temp.getRoot(), "merged_meta").getAbsolutePath()); Path mergedCommonOut = new Path(new File(temp.getRoot(), "merged_common_meta").getAbsolutePath()); - try { - ParquetFileWriter.writeMergedMetadataFile(List.of(info.metaPath1, info.metaPath2), mergedOut, info.conf); - fail("this should throw"); - } catch (RuntimeException e) { - boolean eq1 = - e.getMessage().equals("could not merge metadata: key schema_num has conflicting values: [2, 1]"); - boolean eq2 = - e.getMessage().equals("could not merge metadata: key schema_num has conflicting values: [1, 2]"); + assertThatThrownBy(() -> ParquetFileWriter.writeMergedMetadataFile( + List.of(info.metaPath1, info.metaPath2), mergedOut, info.conf)) + .isInstanceOf(RuntimeException.class) + .hasMessageContaining("could not merge metadata: key schema_num has conflicting values"); - assertEquals(eq1 || eq2, true); - } - - try { - ParquetFileWriter.writeMergedMetadataFile( - List.of(info.commonMetaPath1, info.commonMetaPath2), mergedCommonOut, info.conf); - fail("this should throw"); - } catch (RuntimeException e) { - boolean eq1 = - e.getMessage().equals("could not merge metadata: key schema_num has conflicting values: [2, 1]"); - boolean eq2 = - e.getMessage().equals("could not merge metadata: key schema_num has conflicting values: [1, 2]"); - - assertEquals(eq1 || eq2, true); - } + assertThatThrownBy(() -> ParquetFileWriter.writeMergedMetadataFile( + List.of(info.commonMetaPath1, info.commonMetaPath2), mergedCommonOut, info.conf)) + .isInstanceOf(RuntimeException.class) + .hasMessageContaining("could not merge metadata: key schema_num has conflicting values"); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMultipleWriteRead.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMultipleWriteRead.java index 982ea23adf..9bde506d5c 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMultipleWriteRead.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestMultipleWriteRead.java @@ -32,7 +32,7 @@ import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.BINARY; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT32; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import com.google.common.io.Files; import java.io.IOException; @@ -161,7 +161,7 @@ private void validateFile(Path file, List data) throws IOException { try (ParquetReader reader = ParquetReader.builder(new GroupReadSupport(), file).build()) { for (Group group : data) { - assertEquals(group.toString(), reader.read().toString()); + assertThat(reader.read()).asString().isEqualTo(group.toString()); } } } @@ -171,7 +171,7 @@ private void validateFile(Path file, Filter filter, Stream data) throws I .withFilter(filter) .build()) { for (Iterator it = data.iterator(); it.hasNext(); ) { - assertEquals(it.next().toString(), reader.read().toString()); + assertThat(reader.read()).asString().isEqualTo(it.next().toString()); } } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderMaxMessageSize.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderMaxMessageSize.java index 7b6088e58a..0d26fb6150 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderMaxMessageSize.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderMaxMessageSize.java @@ -18,7 +18,8 @@ */ package org.apache.parquet.hadoop; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.File; import java.io.IOException; @@ -95,9 +96,9 @@ public void testReadFileWithManyColumns() throws IOException { ParquetFileReader.open(HadoopInputFile.fromPath(TEST_FILE, readConf), options)) { ParquetMetadata metadata = reader.getFooter(); - assertNotNull(metadata); - assertEquals(schema, metadata.getFileMetaData().getSchema()); - assertTrue(metadata.getBlocks().size() > 0); + assertThat(metadata).isNotNull(); + assertThat(metadata.getFileMetaData().getSchema()).isEqualTo(schema); + assertThat(metadata.getBlocks()).isNotEmpty(); } } @@ -114,8 +115,8 @@ public void testReadNormalFileWithDefaultConfig() throws IOException { ParquetFileReader.open(HadoopInputFile.fromPath(TEST_FILE, readConf), options)) { ParquetMetadata metadata = reader.getFooter(); - assertNotNull(metadata); - assertEquals(1, metadata.getBlocks().get(0).getRowCount()); + assertThat(metadata).isNotNull(); + assertThat(metadata.getBlocks().get(0).getRowCount()).isEqualTo(1); } } @@ -123,25 +124,21 @@ public void testReadNormalFileWithDefaultConfig() throws IOException { * Test that insufficient max message size produces error */ @Test - public void testInsufficientMaxMessageSizeError() throws IOException { + public void testInsufficientMaxMessageSizeError() { // Try to read with very small max message size Configuration readConf = new Configuration(); readConf.setInt("parquet.thrift.string.size.limit", 1); // Only 1 byte ParquetReadOptions options = HadoopReadOptions.builder(readConf).build(); - try (ParquetFileReader reader = - ParquetFileReader.open(HadoopInputFile.fromPath(TEST_FILE, readConf), options)) { - fail("Should have thrown Message size exceeds limit due to MaxMessageSize"); - } catch (IOException e) { - e.printStackTrace(); - assertTrue( - "Error should mention TTransportException", - e.getMessage().contains("Message size exceeds limit") - || e.getCause().getMessage().contains("Message size exceeds limit") - || e.getMessage().contains("MaxMessageSize reached") - || e.getCause().getMessage().contains("MaxMessageSize reached")); - } + assertThatThrownBy(() -> { + try (ParquetFileReader reader = + ParquetFileReader.open(HadoopInputFile.fromPath(TEST_FILE, readConf), options)) { + reader.getFooter(); + } + }) + .isInstanceOf(IOException.class) + .hasMessageMatching("(?s).*(Message size exceeds limit|MaxMessageSize reached).*"); } /** @@ -157,8 +154,8 @@ public void testReadAcceptsMinusOneAsDefaultMaxMessageSize() throws IOException try (ParquetFileReader reader = ParquetFileReader.open(HadoopInputFile.fromPath(TEST_FILE, readConf), options)) { ParquetMetadata metadata = reader.getFooter(); - assertNotNull(metadata); - assertEquals(schema, metadata.getFileMetaData().getSchema()); + assertThat(metadata).isNotNull(); + assertThat(metadata.getFileMetaData().getSchema()).isEqualTo(schema); } } @@ -172,23 +169,18 @@ public void testReadRejectsInvalidNegativeMaxMessageSize() throws IOException { assertRejectsNonPositiveMaxMessageSize(-5); } - private void assertRejectsNonPositiveMaxMessageSize(int maxMessageSize) throws IOException { + private void assertRejectsNonPositiveMaxMessageSize(int maxMessageSize) { Configuration readConf = new Configuration(); readConf.setInt("parquet.thrift.string.size.limit", maxMessageSize); ParquetReadOptions options = HadoopReadOptions.builder(readConf).build(); - try (ParquetFileReader reader = - ParquetFileReader.open(HadoopInputFile.fromPath(TEST_FILE, readConf), options)) { - fail("Expected failure for non-positive max message size: " + maxMessageSize); - } catch (RuntimeException | IOException e) { - String message = e.getMessage() == null ? "" : e.getMessage(); - String causeMessage = e.getCause() == null || e.getCause().getMessage() == null - ? "" - : e.getCause().getMessage(); - assertTrue( - "Expected 'Max message size must be positive' in " + message + " / " + causeMessage, - message.contains("Max message size must be positive") - || causeMessage.contains("Max message size must be positive")); - } + assertThatThrownBy(() -> { + try (ParquetFileReader reader = + ParquetFileReader.open(HadoopInputFile.fromPath(TEST_FILE, readConf), options)) { + reader.getFooter(); + } + }) + .isInstanceOf(NumberFormatException.class) + .hasMessage("Max message size must be positive: " + maxMessageSize); } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderRowRanges.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderRowRanges.java index 72fdd37180..47e1f115dd 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderRowRanges.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderRowRanges.java @@ -19,9 +19,8 @@ package org.apache.parquet.hadoop; import static org.apache.parquet.hadoop.ParquetFileWriter.Mode.OVERWRITE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.File; import java.io.IOException; @@ -85,13 +84,13 @@ private ParquetFileReader openReader() throws IOException { @Test public void getRowRangesWithoutFilterCoversAllRows() throws IOException { try (ParquetFileReader reader = openReader()) { - assertEquals(1, reader.getRowGroups().size()); + assertThat(reader.getRowGroups()).hasSize(1); BlockMetaData block = reader.getRowGroups().get(0); RowRanges ranges = reader.getRowRanges(0); - assertEquals(block.getRowCount(), ranges.rowCount()); - assertTrue(ranges.isOverlapping(0L, block.getRowCount() - 1)); + assertThat(ranges.rowCount()).isEqualTo(block.getRowCount()); + assertThat(ranges.isOverlapping(0L, block.getRowCount() - 1)).isTrue(); } } @@ -99,8 +98,12 @@ public void getRowRangesWithoutFilterCoversAllRows() throws IOException { public void getRowRangesRejectsOutOfRangeBlockIndex() throws IOException { try (ParquetFileReader reader = openReader()) { int blockCount = reader.getRowGroups().size(); - assertThrows(IllegalArgumentException.class, () -> reader.getRowRanges(-1)); - assertThrows(IllegalArgumentException.class, () -> reader.getRowRanges(blockCount)); + assertThatThrownBy(() -> reader.getRowRanges(-1)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Invalid block index"); + assertThatThrownBy(() -> reader.getRowRanges(blockCount)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Invalid block index"); } } } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileWriter.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileWriter.java index ca03ef4db8..26fc9c0c3d 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileWriter.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileWriter.java @@ -33,13 +33,10 @@ import static org.apache.parquet.schema.Type.Repetition.OPTIONAL; import static org.apache.parquet.schema.Type.Repetition.REPEATED; import static org.apache.parquet.schema.Type.Repetition.REQUIRED; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assumptions.assumeThat; import java.io.File; import java.io.IOException; @@ -50,7 +47,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.concurrent.Callable; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FileStatus; @@ -109,7 +105,6 @@ import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName; import org.apache.parquet.schema.Types; import org.junit.After; -import org.junit.Assume; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -227,22 +222,11 @@ public void testWriteMode() throws Exception { "message m { required group a {required binary b;} required group " + "c { required int64 d; }}"); Configuration conf = new Configuration(); - ParquetFileWriter writer = null; - boolean exceptionThrown = false; Path path = new Path(testFile.toURI()); - try { - writer = createWriter(conf, schema, path); - } catch (IOException ioe1) { - exceptionThrown = true; - } - assertTrue(exceptionThrown); - exceptionThrown = false; - try { - writer = createWriter(conf, schema, path, OVERWRITE); - } catch (IOException ioe2) { - exceptionThrown = true; - } - assertTrue(!exceptionThrown); + assertThatThrownBy(() -> createWriter(conf, schema, path)) + .isInstanceOf(IOException.class) + .hasMessageContaining("already exists"); + assertThatCode(() -> createWriter(conf, schema, path, OVERWRITE)).doesNotThrowAnyException(); testFile.delete(); } @@ -288,23 +272,23 @@ public void testWriteRead() throws Exception { w.close(); ParquetMetadata readFooter = ParquetFileReader.readFooter(configuration, path); - assertEquals("footer: " + readFooter, 2, readFooter.getBlocks().size()); + assertThat(readFooter.getBlocks()).as("footer: " + readFooter).hasSize(2); BlockMetaData rowGroup = readFooter.getBlocks().get(0); - assertEquals(c1Ends - c1Starts, rowGroup.getColumns().get(0).getTotalSize()); - assertEquals(c2Ends - c2Starts, rowGroup.getColumns().get(1).getTotalSize()); - assertEquals(c2Ends - c1Starts, rowGroup.getTotalByteSize()); + assertThat(rowGroup.getColumns().get(0).getTotalSize()).isEqualTo(c1Ends - c1Starts); + assertThat(rowGroup.getColumns().get(1).getTotalSize()).isEqualTo(c2Ends - c2Starts); + assertThat(rowGroup.getTotalByteSize()).isEqualTo(c2Ends - c1Starts); - assertEquals(c1Starts, rowGroup.getColumns().get(0).getStartingPos()); - assertEquals(0, rowGroup.getColumns().get(0).getDictionaryPageOffset()); - assertEquals(c1p1Starts, rowGroup.getColumns().get(0).getFirstDataPageOffset()); - assertEquals(c2Starts, rowGroup.getColumns().get(1).getStartingPos()); - assertEquals(c2Starts, rowGroup.getColumns().get(1).getDictionaryPageOffset()); - assertEquals(c2p1Starts, rowGroup.getColumns().get(1).getFirstDataPageOffset()); + assertThat(rowGroup.getColumns().get(0).getStartingPos()).isEqualTo(c1Starts); + assertThat(rowGroup.getColumns().get(0).getDictionaryPageOffset()).isEqualTo(0); + assertThat(rowGroup.getColumns().get(0).getFirstDataPageOffset()).isEqualTo(c1p1Starts); + assertThat(rowGroup.getColumns().get(1).getStartingPos()).isEqualTo(c2Starts); + assertThat(rowGroup.getColumns().get(1).getDictionaryPageOffset()).isEqualTo(c2Starts); + assertThat(rowGroup.getColumns().get(1).getFirstDataPageOffset()).isEqualTo(c2p1Starts); HashSet expectedEncoding = new HashSet(); expectedEncoding.add(PLAIN); expectedEncoding.add(BIT_PACKED); - assertEquals(expectedEncoding, rowGroup.getColumns().get(0).getEncodings()); + assertThat(rowGroup.getColumns().get(0).getEncodings()).isEqualTo(expectedEncoding); { // read first block of col #1 try (ParquetFileReader r = new ParquetFileReader( @@ -314,10 +298,10 @@ public void testWriteRead() throws Exception { List.of(rowGroup), List.of(SCHEMA.getColumnDescription(PATH1)))) { PageReadStore pages = r.readNextRowGroup(); - assertEquals(3, pages.getRowCount()); + assertThat(pages.getRowCount()).isEqualTo(3); validateContains(SCHEMA, pages, PATH1, 2, BytesInput.from(BYTES1)); validateContains(SCHEMA, pages, PATH1, 3, BytesInput.from(BYTES1)); - assertNull(r.readNextRowGroup()); + assertThat(r.readNextRowGroup()).isNull(); } } @@ -330,7 +314,7 @@ public void testWriteRead() throws Exception { List.of(SCHEMA.getColumnDescription(PATH1), SCHEMA.getColumnDescription(PATH2)))) { PageReadStore pages = r.readNextRowGroup(); - assertEquals(3, pages.getRowCount()); + assertThat(pages.getRowCount()).isEqualTo(3); validateContains(SCHEMA, pages, PATH1, 2, BytesInput.from(BYTES1)); validateContains(SCHEMA, pages, PATH1, 3, BytesInput.from(BYTES1)); validateContains(SCHEMA, pages, PATH2, 2, BytesInput.from(BYTES2)); @@ -338,12 +322,12 @@ public void testWriteRead() throws Exception { validateContains(SCHEMA, pages, PATH2, 1, BytesInput.from(BYTES2)); pages = r.readNextRowGroup(); - assertEquals(4, pages.getRowCount()); + assertThat(pages.getRowCount()).isEqualTo(4); validateContains(SCHEMA, pages, PATH1, 7, BytesInput.from(BYTES3)); validateContains(SCHEMA, pages, PATH2, 8, BytesInput.from(BYTES4)); - assertNull(r.readNextRowGroup()); + assertThat(r.readNextRowGroup()).isNull(); } } PrintFooter.main(new String[] {path.toString()}); @@ -388,25 +372,25 @@ public void testWriteReadWithRecordReader() throws Exception { w.end(new HashMap()); ParquetMetadata readFooter = ParquetFileReader.readFooter(configuration, path); - assertEquals("footer: " + readFooter, 2, readFooter.getBlocks().size()); + assertThat(readFooter.getBlocks()).as("footer: " + readFooter).hasSize(2); BlockMetaData rowGroup = readFooter.getBlocks().get(0); - assertEquals(c2Ends - c2Starts, rowGroup.getColumns().get(1).getTotalSize()); + assertThat(rowGroup.getColumns().get(1).getTotalSize()).isEqualTo(c2Ends - c2Starts); - assertEquals(0, rowGroup.getColumns().get(0).getDictionaryPageOffset()); - assertEquals(c2Starts, rowGroup.getColumns().get(1).getStartingPos()); - assertEquals(c2Starts, rowGroup.getColumns().get(1).getDictionaryPageOffset()); - assertEquals(c2p1Starts, rowGroup.getColumns().get(1).getFirstDataPageOffset()); + assertThat(rowGroup.getColumns().get(0).getDictionaryPageOffset()).isEqualTo(0); + assertThat(rowGroup.getColumns().get(1).getStartingPos()).isEqualTo(c2Starts); + assertThat(rowGroup.getColumns().get(1).getDictionaryPageOffset()).isEqualTo(c2Starts); + assertThat(rowGroup.getColumns().get(1).getFirstDataPageOffset()).isEqualTo(c2p1Starts); BlockMetaData rowGroup2 = readFooter.getBlocks().get(1); - assertEquals(0, rowGroup2.getColumns().get(0).getDictionaryPageOffset()); - assertEquals(c1Bock2Starts, rowGroup2.getColumns().get(0).getStartingPos()); - assertEquals(c1p1Bock2Starts, rowGroup2.getColumns().get(0).getFirstDataPageOffset()); - assertEquals(c1Block2Ends - c1Bock2Starts, rowGroup2.getColumns().get(0).getTotalSize()); + assertThat(rowGroup2.getColumns().get(0).getDictionaryPageOffset()).isEqualTo(0); + assertThat(rowGroup2.getColumns().get(0).getStartingPos()).isEqualTo(c1Bock2Starts); + assertThat(rowGroup2.getColumns().get(0).getFirstDataPageOffset()).isEqualTo(c1p1Bock2Starts); + assertThat(rowGroup2.getColumns().get(0).getTotalSize()).isEqualTo(c1Block2Ends - c1Bock2Starts); HashSet expectedEncoding = new HashSet(); expectedEncoding.add(PLAIN); expectedEncoding.add(BIT_PACKED); - assertEquals(expectedEncoding, rowGroup.getColumns().get(0).getEncodings()); + assertThat(rowGroup.getColumns().get(0).getEncodings()).isEqualTo(expectedEncoding); ParquetInputSplit split = new ParquetInputSplit( path, @@ -423,7 +407,7 @@ public void testWriteReadWithRecordReader() throws Exception { TaskAttemptID taskAttemptID = TaskAttemptID.forName("attempt_0_1_m_1_1"); TaskAttemptContext taskContext = ContextUtil.newTaskAttemptContext(configuration, taskAttemptID); RecordReader reader = input.createRecordReader(split, taskContext); - assertTrue(reader instanceof ParquetRecordReader); + assertThat(reader).isInstanceOf(ParquetRecordReader.class); // RowGroup.file_offset is checked here reader.initialize(split, taskContext); reader.close(); @@ -441,10 +425,9 @@ public void testWriteEmptyBlock() throws Exception { w.start(); w.startBlock(0); - TestUtils.assertThrows("End block with zero record", ParquetEncodingException.class, (Callable) () -> { - w.endBlock(); - return null; - }); + assertThatThrownBy(w::endBlock) + .isInstanceOf(ParquetEncodingException.class) + .hasMessage("End block with zero record"); } @Test @@ -483,8 +466,10 @@ public void testBloomFilterWriteRead() throws Exception { r.getBloomFilterDataReader(readFooter.getBlocks().get(0)); BloomFilter bloomFilter = bloomFilterReader.readBloomFilter( readFooter.getBlocks().get(0).getColumns().get(0)); - assertTrue(bloomFilter.findHash(blockSplitBloomFilter.hash(Binary.fromString("hello")))); - assertTrue(bloomFilter.findHash(blockSplitBloomFilter.hash(Binary.fromString("world")))); + assertThat(bloomFilter.findHash(blockSplitBloomFilter.hash(Binary.fromString("hello")))) + .isTrue(); + assertThat(bloomFilter.findHash(blockSplitBloomFilter.hash(Binary.fromString("world")))) + .isTrue(); } } @@ -526,14 +511,12 @@ public void testWriteReadDataPageV2() throws Exception { w.end(new HashMap<>()); ParquetMetadata readFooter = ParquetFileReader.readFooter(configuration, path); - assertEquals("footer: " + readFooter, 1, readFooter.getBlocks().size()); - assertEquals( - c1Ends - c1Starts, - readFooter.getBlocks().get(0).getColumns().get(0).getTotalSize()); - assertEquals( - c2Ends - c2Starts, - readFooter.getBlocks().get(0).getColumns().get(1).getTotalSize()); - assertEquals(c2Ends - c1Starts, readFooter.getBlocks().get(0).getTotalByteSize()); + assertThat(readFooter.getBlocks()).as("footer: " + readFooter).hasSize(1); + assertThat(readFooter.getBlocks().get(0).getColumns().get(0).getTotalSize()) + .isEqualTo(c1Ends - c1Starts); + assertThat(readFooter.getBlocks().get(0).getColumns().get(1).getTotalSize()) + .isEqualTo(c2Ends - c2Starts); + assertThat(readFooter.getBlocks().get(0).getTotalByteSize()).isEqualTo(c2Ends - c1Starts); // check for stats org.apache.parquet.column.statistics.Statistics expectedStats = createStatistics("b", "z", C1); @@ -542,9 +525,8 @@ public void testWriteReadDataPageV2() throws Exception { HashSet expectedEncoding = new HashSet(); expectedEncoding.add(PLAIN); - assertEquals( - expectedEncoding, - readFooter.getBlocks().get(0).getColumns().get(0).getEncodings()); + assertThat(readFooter.getBlocks().get(0).getColumns().get(0).getEncodings()) + .isEqualTo(expectedEncoding); try (ParquetFileReader reader = new ParquetFileReader( configuration, @@ -553,7 +535,7 @@ public void testWriteReadDataPageV2() throws Exception { readFooter.getBlocks(), List.of(SCHEMA.getColumnDescription(PATH1), SCHEMA.getColumnDescription(PATH2)))) { PageReadStore pages = reader.readNextRowGroup(); - assertEquals(14, pages.getRowCount()); + assertThat(pages.getRowCount()).isEqualTo(14); validateV2Page( SCHEMA, pages, @@ -598,7 +580,7 @@ public void testWriteReadDataPageV2() throws Exception { defLevels.toByteArray(), data2.toByteArray(), 12); - assertNull(reader.readNextRowGroup()); + assertThat(reader.readNextRowGroup()).isNull(); } } @@ -656,34 +638,33 @@ public void testAlignmentWithPadding() throws Exception { } long startFooter = fileLen - footerLen - 8; - assertEquals("Footer should start after second row group without padding", secondRowGroupEnds, startFooter); + assertThat(startFooter) + .as("Footer should start after second row group without padding") + .isEqualTo(secondRowGroupEnds); ParquetMetadata readFooter = ParquetFileReader.readFooter(conf, path); - assertEquals("footer: " + readFooter, 2, readFooter.getBlocks().size()); - assertEquals( - c1Ends - c1Starts, - readFooter.getBlocks().get(0).getColumns().get(0).getTotalSize()); - assertEquals( - c2Ends - c2Starts, - readFooter.getBlocks().get(0).getColumns().get(1).getTotalSize()); - assertEquals(c2Ends - c1Starts, readFooter.getBlocks().get(0).getTotalByteSize()); + assertThat(readFooter.getBlocks()).as("footer: " + readFooter).hasSize(2); + assertThat(readFooter.getBlocks().get(0).getColumns().get(0).getTotalSize()) + .isEqualTo(c1Ends - c1Starts); + assertThat(readFooter.getBlocks().get(0).getColumns().get(1).getTotalSize()) + .isEqualTo(c2Ends - c2Starts); + assertThat(readFooter.getBlocks().get(0).getTotalByteSize()).isEqualTo(c2Ends - c1Starts); HashSet expectedEncoding = new HashSet(); expectedEncoding.add(PLAIN); expectedEncoding.add(BIT_PACKED); - assertEquals( - expectedEncoding, - readFooter.getBlocks().get(0).getColumns().get(0).getEncodings()); + assertThat(readFooter.getBlocks().get(0).getColumns().get(0).getEncodings()) + .isEqualTo(expectedEncoding); // verify block starting positions with padding - assertEquals( - "First row group should start after magic", - 4, - readFooter.getBlocks().get(0).getStartingPos()); - assertTrue("First row group should end before the block size (120)", firstRowGroupEnds < 120); - assertEquals( - "Second row group should start at the block size", - 120, - readFooter.getBlocks().get(1).getStartingPos()); + assertThat(readFooter.getBlocks().get(0).getStartingPos()) + .as("First row group should start after magic") + .isEqualTo(4); + assertThat(firstRowGroupEnds) + .as("First row group should end before the block size (120)") + .isLessThan(120); + assertThat(readFooter.getBlocks().get(1).getStartingPos()) + .as("Second row group should start at the block size") + .isEqualTo(120); { // read first block of col #1 try (ParquetFileReader r = new ParquetFileReader( @@ -693,10 +674,10 @@ public void testAlignmentWithPadding() throws Exception { List.of(readFooter.getBlocks().get(0)), List.of(SCHEMA.getColumnDescription(PATH1)))) { PageReadStore pages = r.readNextRowGroup(); - assertEquals(3, pages.getRowCount()); + assertThat(pages.getRowCount()).isEqualTo(3); validateContains(SCHEMA, pages, PATH1, 2, BytesInput.from(BYTES1)); validateContains(SCHEMA, pages, PATH1, 3, BytesInput.from(BYTES1)); - assertNull(r.readNextRowGroup()); + assertThat(r.readNextRowGroup()).isNull(); } } @@ -709,7 +690,7 @@ public void testAlignmentWithPadding() throws Exception { List.of(SCHEMA.getColumnDescription(PATH1), SCHEMA.getColumnDescription(PATH2)))) { PageReadStore pages = r.readNextRowGroup(); - assertEquals(3, pages.getRowCount()); + assertThat(pages.getRowCount()).isEqualTo(3); validateContains(SCHEMA, pages, PATH1, 2, BytesInput.from(BYTES1)); validateContains(SCHEMA, pages, PATH1, 3, BytesInput.from(BYTES1)); validateContains(SCHEMA, pages, PATH2, 2, BytesInput.from(BYTES2)); @@ -717,12 +698,12 @@ public void testAlignmentWithPadding() throws Exception { validateContains(SCHEMA, pages, PATH2, 1, BytesInput.from(BYTES2)); pages = r.readNextRowGroup(); - assertEquals(4, pages.getRowCount()); + assertThat(pages.getRowCount()).isEqualTo(4); validateContains(SCHEMA, pages, PATH1, 7, BytesInput.from(BYTES3)); validateContains(SCHEMA, pages, PATH2, 8, BytesInput.from(BYTES4)); - assertNull(r.readNextRowGroup()); + assertThat(r.readNextRowGroup()).isNull(); } } PrintFooter.main(new String[] {path.toString()}); @@ -784,34 +765,33 @@ public void testAlignmentWithNoPaddingNeeded() throws Exception { } long startFooter = fileLen - footerLen - 8; - assertEquals("Footer should start after second row group without padding", secondRowGroupEnds, startFooter); + assertThat(startFooter) + .as("Footer should start after second row group without padding") + .isEqualTo(secondRowGroupEnds); ParquetMetadata readFooter = ParquetFileReader.readFooter(conf, path); - assertEquals("footer: " + readFooter, 2, readFooter.getBlocks().size()); - assertEquals( - c1Ends - c1Starts, - readFooter.getBlocks().get(0).getColumns().get(0).getTotalSize()); - assertEquals( - c2Ends - c2Starts, - readFooter.getBlocks().get(0).getColumns().get(1).getTotalSize()); - assertEquals(c2Ends - c1Starts, readFooter.getBlocks().get(0).getTotalByteSize()); + assertThat(readFooter.getBlocks()).as("footer: " + readFooter).hasSize(2); + assertThat(readFooter.getBlocks().get(0).getColumns().get(0).getTotalSize()) + .isEqualTo(c1Ends - c1Starts); + assertThat(readFooter.getBlocks().get(0).getColumns().get(1).getTotalSize()) + .isEqualTo(c2Ends - c2Starts); + assertThat(readFooter.getBlocks().get(0).getTotalByteSize()).isEqualTo(c2Ends - c1Starts); HashSet expectedEncoding = new HashSet(); expectedEncoding.add(PLAIN); expectedEncoding.add(BIT_PACKED); - assertEquals( - expectedEncoding, - readFooter.getBlocks().get(0).getColumns().get(0).getEncodings()); + assertThat(readFooter.getBlocks().get(0).getColumns().get(0).getEncodings()) + .isEqualTo(expectedEncoding); // verify block starting positions with padding - assertEquals( - "First row group should start after magic", - 4, - readFooter.getBlocks().get(0).getStartingPos()); - assertTrue("First row group should end before the block size (120)", firstRowGroupEnds > 100); - assertEquals( - "Second row group should start after no padding", - 109, - readFooter.getBlocks().get(1).getStartingPos()); + assertThat(readFooter.getBlocks().get(0).getStartingPos()) + .as("First row group should start after magic") + .isEqualTo(4); + assertThat(firstRowGroupEnds) + .as("First row group should end before the block size (120)") + .isGreaterThan(100); + assertThat(readFooter.getBlocks().get(1).getStartingPos()) + .as("Second row group should start after no padding") + .isEqualTo(109); { // read first block of col #1 try (ParquetFileReader r = new ParquetFileReader( @@ -821,10 +801,10 @@ public void testAlignmentWithNoPaddingNeeded() throws Exception { List.of(readFooter.getBlocks().get(0)), List.of(SCHEMA.getColumnDescription(PATH1)))) { PageReadStore pages = r.readNextRowGroup(); - assertEquals(3, pages.getRowCount()); + assertThat(pages.getRowCount()).isEqualTo(3); validateContains(SCHEMA, pages, PATH1, 2, BytesInput.from(BYTES1)); validateContains(SCHEMA, pages, PATH1, 3, BytesInput.from(BYTES1)); - assertNull(r.readNextRowGroup()); + assertThat(r.readNextRowGroup()).isNull(); } } @@ -836,7 +816,7 @@ public void testAlignmentWithNoPaddingNeeded() throws Exception { readFooter.getBlocks(), List.of(SCHEMA.getColumnDescription(PATH1), SCHEMA.getColumnDescription(PATH2)))) { PageReadStore pages = r.readNextRowGroup(); - assertEquals(3, pages.getRowCount()); + assertThat(pages.getRowCount()).isEqualTo(3); validateContains(SCHEMA, pages, PATH1, 2, BytesInput.from(BYTES1)); validateContains(SCHEMA, pages, PATH1, 3, BytesInput.from(BYTES1)); validateContains(SCHEMA, pages, PATH2, 2, BytesInput.from(BYTES2)); @@ -844,12 +824,12 @@ public void testAlignmentWithNoPaddingNeeded() throws Exception { validateContains(SCHEMA, pages, PATH2, 1, BytesInput.from(BYTES2)); pages = r.readNextRowGroup(); - assertEquals(4, pages.getRowCount()); + assertThat(pages.getRowCount()).isEqualTo(4); validateContains(SCHEMA, pages, PATH1, 7, BytesInput.from(BYTES3)); validateContains(SCHEMA, pages, PATH2, 8, BytesInput.from(BYTES4)); - assertNull(r.readNextRowGroup()); + assertThat(r.readNextRowGroup()).isNull(); } } PrintFooter.main(new String[] {path.toString()}); @@ -872,15 +852,15 @@ public void testConvertToThriftStatistics() throws Exception { (LongStatistics) org.apache.parquet.format.converter.ParquetMetadataConverter.fromParquetStatistics( createdBy, thriftStats, PrimitiveTypeName.INT64); - assertEquals(parquetMRstats.getMax(), convertedBackStats.getMax()); - assertEquals(parquetMRstats.getMin(), convertedBackStats.getMin()); - assertEquals(parquetMRstats.getNumNulls(), convertedBackStats.getNumNulls()); + assertThat(convertedBackStats.getMax()).isEqualTo(parquetMRstats.getMax()); + assertThat(convertedBackStats.getMin()).isEqualTo(parquetMRstats.getMin()); + assertThat(convertedBackStats.getNumNulls()).isEqualTo(parquetMRstats.getNumNulls()); } @Test public void testWriteReadStatistics() throws Exception { // this test assumes statistics will be read - Assume.assumeTrue(!shouldIgnoreStatistics(Version.FULL_VERSION, BINARY)); + assumeThat(shouldIgnoreStatistics(Version.FULL_VERSION, BINARY)).isFalse(); File testFile = temp.newFile(); testFile.delete(); @@ -999,7 +979,7 @@ public void testMetaDataFile() throws Exception { footers = ParquetFileReader.readFooters(configuration, outputStatus, false); validateFooters(footers); footers = ParquetFileReader.readFooters(configuration, fs.getFileStatus(new Path(testDirPath, "part0")), false); - assertEquals(1, footers.size()); + assertThat(footers).hasSize(1); final FileStatus metadataFile = fs.getFileStatus(new Path(testDirPath, ParquetFileWriter.PARQUET_METADATA_FILE)); @@ -1024,7 +1004,7 @@ public void testMetaDataFile() throws Exception { @Test public void testWriteReadStatisticsAllNulls() throws Exception { // this test assumes statistics will be read - Assume.assumeTrue(!shouldIgnoreStatistics(Version.FULL_VERSION, BINARY)); + assumeThat(shouldIgnoreStatistics(Version.FULL_VERSION, BINARY)).isFalse(); File testFile = temp.newFile(); testFile.delete(); @@ -1051,26 +1031,25 @@ public void testWriteReadStatisticsAllNulls() throws Exception { // assert the statistics object is not empty org.apache.parquet.column.statistics.Statistics stats = readFooter.getBlocks().get(0).getColumns().get(0).getStatistics(); - assertFalse("is empty: " + stats, stats.isEmpty()); + assertThat(stats.isEmpty()).as("is empty: " + stats).isFalse(); // assert the number of nulls are correct for the first block - assertEquals("nulls: " + stats, 1, stats.getNumNulls()); + assertThat(stats.getNumNulls()).as("nulls: " + stats).isEqualTo(1); } private void validateFooters(final List