diff --git a/parquet-avro/src/test/java/org/apache/parquet/avro/TestReadWrite.java b/parquet-avro/src/test/java/org/apache/parquet/avro/TestReadWrite.java index 0070bbac09..6dbf79470b 100644 --- a/parquet-avro/src/test/java/org/apache/parquet/avro/TestReadWrite.java +++ b/parquet-avro/src/test/java/org/apache/parquet/avro/TestReadWrite.java @@ -80,11 +80,16 @@ import org.apache.parquet.schema.MessageType; import org.apache.parquet.schema.MessageTypeParser; import org.apache.parquet.schema.PrimitiveType; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +@ParameterizedClass +@MethodSource("data") public class TestReadWrite { enum Converters { @@ -190,20 +195,24 @@ static Stream data() { CodecFactory.EXPLICIT)); } + @Parameter(0) private Converters converter; + + @Parameter(1) private FileLocation fileLocation; + + @Parameter(2) private ConfigurationType conf; + + @Parameter(3) private CodecFactory codecType; private final Configuration testConf = new Configuration(); private final ParquetConfiguration hadoopConfWithInterface = new HadoopParquetConfiguration(); private final ParquetConfiguration plainParquetConf = new PlainParquetConfiguration(); - private void init(Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) { - this.converter = converter; - this.fileLocation = fileLocation; - this.conf = conf; - this.codecType = codecs; + @BeforeEach + public void setUpConfigurations() { this.testConf.setBoolean(AvroReadSupport.AVRO_COMPATIBILITY, converter.isCompatible()); this.testConf.setBoolean("parquet.avro.add-list-element-records", false); this.testConf.setBoolean("parquet.avro.write-old-list-structure", false); @@ -215,12 +224,8 @@ private void init(Converters converter, FileLocation fileLocation, Configuration this.plainParquetConf.setBoolean("parquet.avro.write-old-list-structure", false); } - @ParameterizedTest - @MethodSource("data") - public void testEmptyArray( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testEmptyArray() throws Exception { Schema schema = new Schema.Parser().parse(Resources.getResource("array.avsc").openStream()); @@ -243,12 +248,8 @@ public void testEmptyArray( } } - @ParameterizedTest - @MethodSource("data") - public void testEmptyMap( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testEmptyMap() throws Exception { Schema schema = new Schema.Parser().parse(Resources.getResource("map.avsc").openStream()); @@ -271,12 +272,8 @@ public void testEmptyMap( } } - @ParameterizedTest - @MethodSource("data") - public void testMapWithNulls( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testMapWithNulls() throws Exception { Schema schema = new Schema.Parser() .parse(Resources.getResource("map_with_nulls.avsc").openStream()); @@ -306,12 +303,8 @@ public void testMapWithNulls( } } - @ParameterizedTest - @MethodSource("data") - public void testMapRequiredValueWithNull( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testMapRequiredValueWithNull() throws Exception { Schema schema = Schema.createRecord("record1", null, null, false); schema.setFields(Lists.newArrayList( new Schema.Field("mymap", Schema.createMap(Schema.create(Schema.Type.INT)), null, null))); @@ -337,12 +330,8 @@ public void testMapRequiredValueWithNull( } } - @ParameterizedTest - @MethodSource("data") - public void testMapWithUtf8Key( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testMapWithUtf8Key() throws Exception { Schema schema = new Schema.Parser().parse(Resources.getResource("map.avsc").openStream()); @@ -368,12 +357,8 @@ public void testMapWithUtf8Key( } } - @ParameterizedTest - @MethodSource("data") - public void testDecimalValues( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testDecimalValues() throws Exception { Schema decimalSchema = Schema.createRecord("myrecord", null, null, false); Schema decimal = LogicalTypes.decimal(9, 2).addToSchema(Schema.create(Schema.Type.BYTES)); decimalSchema.setFields(Collections.singletonList(new Schema.Field("dec", decimal, null, null))); @@ -420,12 +405,8 @@ public void testDecimalValues( assertThat(records).as("Content should match").containsExactlyElementsOf(expected); } - @ParameterizedTest - @MethodSource("data") - public void testFixedDecimalValues( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testFixedDecimalValues() throws Exception { Schema decimalSchema = Schema.createRecord("myrecord", null, null, false); Schema decimal = LogicalTypes.decimal(9, 2).addToSchema(Schema.createFixed("dec", null, null, 4)); decimalSchema.setFields(Collections.singletonList(new Schema.Field("dec", decimal, null, null))); @@ -472,12 +453,8 @@ public void testFixedDecimalValues( assertThat(records).as("Content should match").containsExactlyElementsOf(expected); } - @ParameterizedTest - @MethodSource("data") - public void testDecimalIntegerValues( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testDecimalIntegerValues() throws Exception { Path path = new Path(tempDir.resolve("test_decimal_integer_values.parquet").toUri()); @@ -540,11 +517,8 @@ public void testDecimalIntegerValues( assertThat(secondSalary).as("Should be 120.3, but is " + secondSalary).isEqualTo(new BigDecimal("120.3")); } - @ParameterizedTest - @MethodSource("data") - public void testAll(Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testAll() throws Exception { Schema schema = new Schema.Parser().parse(Resources.getResource("all.avsc").openStream()); @@ -622,12 +596,8 @@ public void testAll(Converters converter, FileLocation fileLocation, Configurati assertThat(nextRecord.get("myfixed")).isEqualTo(genericFixed); } - @ParameterizedTest - @MethodSource("data") - public void testAllUsingDefaultAvroSchema( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testAllUsingDefaultAvroSchema() throws Exception { Path file = createTempFile(); // write file using Parquet APIs @@ -847,12 +817,8 @@ public void write(Map record) { } } - @ParameterizedTest - @MethodSource("data") - public void testUnionWithSingleNonNullType( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testUnionWithSingleNonNullType() throws Exception { Schema avroSchema = Schema.createRecord("SingleStringUnionRecord", null, null, false); avroSchema.setFields(Collections.singletonList( new Schema.Field("value", Schema.createUnion(Schema.create(Schema.Type.STRING)), null, null))); @@ -880,12 +846,8 @@ public void testUnionWithSingleNonNullType( } } - @ParameterizedTest - @MethodSource("data") - public void testDuplicatedValuesWithDictionary( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testDuplicatedValuesWithDictionary() throws Exception { Schema schema = SchemaBuilder.record("spark_schema") .fields() .optionalBytes("value") @@ -919,12 +881,8 @@ public void testDuplicatedValuesWithDictionary( } } - @ParameterizedTest - @MethodSource("data") - public void testNestedLists( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testNestedLists() throws Exception { Schema schema = new Schema.Parser() .parse(Resources.getResource("nested_array.avsc").openStream()); String file = createTempFile().toUri().getPath(); @@ -966,12 +924,8 @@ public void testNestedLists( * A test demonstrating the most simple way to write and read Parquet files * using Avro {@link GenericRecord}. */ - @ParameterizedTest - @MethodSource("data") - public void testSimpleGeneric( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws IOException { - init(converter, fileLocation, conf, codecs); + @Test + public void testSimpleGeneric() throws IOException { final Schema schema = Schema.createRecord("Person", null, "org.apache.parquet", false); schema.setFields(Arrays.asList( new Schema.Field("name", Schema.create(Schema.Type.STRING), null, null), @@ -1038,12 +992,8 @@ public Integer toInt(LocalDate date, Schema schema, LogicalType type) { } } - @ParameterizedTest - @MethodSource("data") - public void testParsesDataModelFromConf( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws Exception { - init(converter, fileLocation, conf, codecs); + @Test + public void testParsesDataModelFromConf() throws Exception { Schema datetimeSchema = Schema.createRecord("myrecord", null, null, false); Schema date = LogicalTypes.date().addToSchema(Schema.create(Schema.Type.INT)); datetimeSchema.setFields(Collections.singletonList(new Schema.Field("date", date, null, null))); @@ -1089,12 +1039,8 @@ public void testParsesDataModelFromConf( assertThat(records).as("Content should match").containsExactlyElementsOf(expected); } - @ParameterizedTest - @MethodSource("data") - public void testConstructor( - Converters converter, FileLocation fileLocation, ConfigurationType conf, CodecFactory codecs) - throws IOException { - init(converter, fileLocation, conf, codecs); + @Test + public void testConstructor() throws IOException { String testFile = URI.create(Resources.getResource("strings-2.parquet").getFile()).getRawPath(); InputFile inputFile = new LocalInputFile(Paths.get(testFile)); diff --git a/parquet-avro/src/test/java/org/apache/parquet/avro/TestReadWriteOldListBehavior.java b/parquet-avro/src/test/java/org/apache/parquet/avro/TestReadWriteOldListBehavior.java index 9b072ba26d..79be0a22f9 100644 --- a/parquet-avro/src/test/java/org/apache/parquet/avro/TestReadWriteOldListBehavior.java +++ b/parquet-avro/src/test/java/org/apache/parquet/avro/TestReadWriteOldListBehavior.java @@ -52,23 +52,28 @@ import org.apache.parquet.io.api.Binary; import org.apache.parquet.io.api.RecordConsumer; import org.apache.parquet.schema.MessageTypeParser; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.ValueSource; +@ParameterizedClass +@ValueSource(booleans = {false, true}) public class TestReadWriteOldListBehavior { + @Parameter private boolean compat; + private final Configuration testConf = new Configuration(false); - private void init(boolean compat) { - this.compat = compat; + @BeforeEach + public void setUpConfiguration() { this.testConf.setBoolean(AvroReadSupport.AVRO_COMPATIBILITY, compat); } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testEmptyArray(boolean compat) throws Exception { - init(compat); + @Test + public void testEmptyArray() throws Exception { Schema schema = new Schema.Parser().parse(Resources.getResource("array.avsc").openStream()); @@ -93,10 +98,8 @@ public void testEmptyArray(boolean compat) throws Exception { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testEmptyMap(boolean compat) throws Exception { - init(compat); + @Test + public void testEmptyMap() throws Exception { Schema schema = new Schema.Parser().parse(Resources.getResource("map.avsc").openStream()); @@ -121,10 +124,8 @@ public void testEmptyMap(boolean compat) throws Exception { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testMapWithNulls(boolean compat) throws Exception { - init(compat); + @Test + public void testMapWithNulls() throws Exception { Schema schema = new Schema.Parser() .parse(Resources.getResource("map_with_nulls.avsc").openStream()); @@ -153,10 +154,8 @@ public void testMapWithNulls(boolean compat) throws Exception { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testMapRequiredValueWithNull(boolean compat) throws Exception { - init(compat); + @Test + public void testMapRequiredValueWithNull() throws Exception { Schema schema = Schema.createRecord("record1", null, null, false); schema.setFields(Lists.newArrayList( new Schema.Field("mymap", Schema.createMap(Schema.create(Schema.Type.INT)), null, null))); @@ -181,10 +180,8 @@ public void testMapRequiredValueWithNull(boolean compat) throws Exception { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testMapWithUtf8Key(boolean compat) throws Exception { - init(compat); + @Test + public void testMapWithUtf8Key() throws Exception { Schema schema = new Schema.Parser().parse(Resources.getResource("map.avsc").openStream()); @@ -209,10 +206,8 @@ public void testMapWithUtf8Key(boolean compat) throws Exception { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testAll(boolean compat) throws Exception { - init(compat); + @Test + public void testAll() throws Exception { Schema schema = new Schema.Parser().parse(Resources.getResource("all.avsc").openStream()); @@ -288,10 +283,8 @@ public void testAll(boolean compat) throws Exception { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testArrayWithNullValues(boolean compat) throws Exception { - init(compat); + @Test + public void testArrayWithNullValues() throws Exception { Schema schema = new Schema.Parser().parse(Resources.getResource("all.avsc").openStream()); @@ -348,10 +341,8 @@ public void testArrayWithNullValues(boolean compat) throws Exception { .hasMessageContaining("parquet.avro.write-old-list-structure"); } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testAllUsingDefaultAvroSchema(boolean compat) throws Exception { - init(compat); + @Test + public void testAllUsingDefaultAvroSchema() throws Exception { File tmp = File.createTempFile(getClass().getSimpleName(), ".tmp"); tmp.deleteOnExit(); tmp.delete(); diff --git a/parquet-avro/src/test/java/org/apache/parquet/avro/TestSpecificReadWrite.java b/parquet-avro/src/test/java/org/apache/parquet/avro/TestSpecificReadWrite.java index 91aa29d36e..154b27432e 100644 --- a/parquet-avro/src/test/java/org/apache/parquet/avro/TestSpecificReadWrite.java +++ b/parquet-avro/src/test/java/org/apache/parquet/avro/TestSpecificReadWrite.java @@ -41,25 +41,32 @@ import org.apache.parquet.hadoop.ParquetReader; import org.apache.parquet.hadoop.ParquetWriter; import org.apache.parquet.hadoop.metadata.CompressionCodecName; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.ValueSource; /** * Other tests exercise the use of Avro Generic, a dynamic data representation. This class focuses * on Avro Speific whose schemas are pre-compiled to POJOs with built in SerDe for faster serialization. */ +@ParameterizedClass +@ValueSource(booleans = {false, true}) public class TestSpecificReadWrite { - private static Configuration testConf(boolean compat) { - Configuration conf = new Configuration(false); - conf.setBoolean(AvroReadSupport.AVRO_COMPATIBILITY, compat); - return conf; + @Parameter + private boolean compat; + + private final Configuration testConf = new Configuration(false); + + @BeforeEach + public void setUpConfiguration() { + testConf.setBoolean(AvroReadSupport.AVRO_COMPATIBILITY, compat); } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testCompatReadWriteSpecific(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testCompatReadWriteSpecific() throws IOException { Path path = writeCarsToParquetFile(10, CompressionCodecName.UNCOMPRESSED, false); try (ParquetReader reader = new AvroParquetReader<>(testConf, path)) { for (int i = 0; i < 10; i++) { @@ -71,10 +78,8 @@ public void testCompatReadWriteSpecific(boolean compat) throws IOException { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testReadWriteSpecificWithDictionary(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testReadWriteSpecificWithDictionary() throws IOException { Path path = writeCarsToParquetFile(10, CompressionCodecName.UNCOMPRESSED, true); try (ParquetReader reader = new AvroParquetReader<>(testConf, path)) { for (int i = 0; i < 10; i++) { @@ -86,10 +91,8 @@ public void testReadWriteSpecificWithDictionary(boolean compat) throws IOExcepti } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testFilterMatchesMultiple(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testFilterMatchesMultiple() throws IOException { Path path = writeCarsToParquetFile(10, CompressionCodecName.UNCOMPRESSED, false); try (ParquetReader reader = new AvroParquetReader<>(testConf, path, column("make", equalTo("Volkswagen")))) { @@ -101,10 +104,8 @@ public void testFilterMatchesMultiple(boolean compat) throws IOException { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testFilterMatchesMultipleBlocks(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testFilterMatchesMultipleBlocks() throws IOException { Path path = writeCarsToParquetFile( 10000, CompressionCodecName.UNCOMPRESSED, false, DEFAULT_BLOCK_SIZE / 64, DEFAULT_PAGE_SIZE / 64); try (ParquetReader reader = @@ -117,10 +118,8 @@ public void testFilterMatchesMultipleBlocks(boolean compat) throws IOException { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testFilterMatchesNoBlocks(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testFilterMatchesNoBlocks() throws IOException { Path path = writeCarsToParquetFile( 10000, CompressionCodecName.UNCOMPRESSED, false, DEFAULT_BLOCK_SIZE / 64, DEFAULT_PAGE_SIZE / 64); try (ParquetReader reader = new AvroParquetReader<>(testConf, path, column("make", equalTo("Bogus")))) { @@ -128,10 +127,8 @@ public void testFilterMatchesNoBlocks(boolean compat) throws IOException { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testFilterMatchesFinalBlockOnly(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testFilterMatchesFinalBlockOnly() throws IOException { File tmp = File.createTempFile(getClass().getSimpleName(), ".tmp"); tmp.deleteOnExit(); tmp.delete(); @@ -162,10 +159,8 @@ public void testFilterMatchesFinalBlockOnly(boolean compat) throws IOException { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testFilterWithDictionary(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testFilterWithDictionary() throws IOException { Path path = writeCarsToParquetFile(1, CompressionCodecName.UNCOMPRESSED, true); try (ParquetReader reader = new AvroParquetReader<>(testConf, path, column("make", equalTo("Volkswagen")))) { @@ -175,10 +170,8 @@ public void testFilterWithDictionary(boolean compat) throws IOException { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testFilterOnSubAttribute(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testFilterOnSubAttribute() throws IOException { Path path = writeCarsToParquetFile(1, CompressionCodecName.UNCOMPRESSED, false); ParquetReader reader = @@ -195,10 +188,8 @@ public void testFilterOnSubAttribute(boolean compat) throws IOException { assertThat(reader.read()).isNull(); } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testProjection(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testProjection() throws IOException { Path path = writeCarsToParquetFile(1, CompressionCodecName.UNCOMPRESSED, false); Configuration conf = new Configuration(testConf); @@ -237,10 +228,8 @@ public void testProjection(boolean compat) throws IOException { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testRepeatedRecordProjection(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testRepeatedRecordProjection() throws IOException { Path path = writeCarsToParquetFile(1, CompressionCodecName.UNCOMPRESSED, false); Configuration conf = new Configuration(testConf); Schema schema = Car.getClassSchema(); @@ -277,10 +266,8 @@ public void testRepeatedRecordProjection(boolean compat) throws IOException { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testAvroReadSchema(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testAvroReadSchema() throws IOException { Path path = writeCarsToParquetFile(1, CompressionCodecName.UNCOMPRESSED, false); Configuration conf = new Configuration(testConf); AvroReadSupport.setAvroReadSchema(conf, NewCar.SCHEMA$); @@ -297,10 +284,8 @@ public void testAvroReadSchema(boolean compat) throws IOException { } } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - public void testParsesSpecificDataModel(boolean compat) throws IOException { - Configuration testConf = testConf(compat); + @Test + public void testParsesSpecificDataModel() throws IOException { // SpecificRecord contains a logical type and will fail to decode unless its SpecificData model is parsed List records = IntStream.range(0, 25) .mapToObj(i -> LogicalTypesTest.newBuilder() diff --git a/parquet-column/src/test/java/org/apache/parquet/io/TestColumnIO.java b/parquet-column/src/test/java/org/apache/parquet/io/TestColumnIO.java index ca12479323..508e58267b 100644 --- a/parquet-column/src/test/java/org/apache/parquet/io/TestColumnIO.java +++ b/parquet-column/src/test/java/org/apache/parquet/io/TestColumnIO.java @@ -30,6 +30,7 @@ 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 static org.assertj.core.api.Assumptions.assumeThat; import java.util.ArrayList; import java.util.Arrays; @@ -61,12 +62,19 @@ import org.apache.parquet.schema.Type.Repetition; import org.apache.parquet.schema.Types; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@ParameterizedClass(name = "useDictionary = {0}") +@ValueSource(booleans = {true, false}) public class TestColumnIO { + + @Parameter + private boolean useDictionary; + private static final Logger LOG = LoggerFactory.getLogger(TestColumnIO.class); private static final String oneOfEach = "message Document {\n" @@ -141,12 +149,14 @@ public class TestColumnIO { @Test public void testSchema() { + assumeThat(useDictionary) + .as("independent of useDictionary, so it only needs to run once") + .isTrue(); assertThat(schema).asString().isEqualTo(schemaString); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testReadUsingRequestedSchemaWithExtraFields(boolean useDictionary) { + @Test + public void testReadUsingRequestedSchemaWithExtraFields() { MessageType orginalSchema = new MessageType( "schema", new PrimitiveType(REQUIRED, INT32, "a"), new PrimitiveType(OPTIONAL, INT32, "b")); MessageType schemaWithExtraField = new MessageType( @@ -186,9 +196,8 @@ public void testReadUsingRequestedSchemaWithExtraFields(boolean useDictionary) { } } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testReadUsingRequestedSchemaWithIncompatibleField(boolean useDictionary) { + @Test + public void testReadUsingRequestedSchemaWithIncompatibleField() { MessageType originalSchema = new MessageType("schema", new PrimitiveType(OPTIONAL, INT32, "e")); MemPageStore store = new MemPageStore(1); SimpleGroupFactory groupFactory = new SimpleGroupFactory(originalSchema); @@ -203,9 +212,8 @@ public void testReadUsingRequestedSchemaWithIncompatibleField(boolean useDiction "The requested schema is not compatible with the file schema. incompatible types: optional binary e != optional int32 e"); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testReadUsingSchemaWithRequiredFieldThatWasOptional(boolean useDictionary) { + @Test + public void testReadUsingSchemaWithRequiredFieldThatWasOptional() { MessageType originalSchema = new MessageType("schema", new PrimitiveType(OPTIONAL, INT32, "e")); MemPageStore store = new MemPageStore(1); SimpleGroupFactory groupFactory = new SimpleGroupFactory(originalSchema); @@ -221,9 +229,8 @@ public void testReadUsingSchemaWithRequiredFieldThatWasOptional(boolean useDicti "The requested schema is not compatible with the file schema. incompatible types: required int32 e != optional int32 e"); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testReadUsingProjectedSchema(boolean useDictionary) { + @Test + public void testReadUsingProjectedSchema() { MessageType orginalSchema = new MessageType( "schema", new PrimitiveType(REQUIRED, INT32, "a"), new PrimitiveType(REQUIRED, INT32, "b")); MessageType projectedSchema = new MessageType("schema", new PrimitiveType(OPTIONAL, INT32, "b")); @@ -245,9 +252,8 @@ public void testReadUsingProjectedSchema(boolean useDictionary) { } } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testColumnIOAllowsProjectionWithinFileGroup(boolean useDictionary) { + @Test + public void testColumnIOAllowsProjectionWithinFileGroup() { GroupType fileGroup = Types.optionalGroup() .as(LogicalTypeAnnotation.fileType()) .optional(BINARY) @@ -327,9 +333,8 @@ private void writeGroups( columns.flush(); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testColumnIO(boolean useDictionary) { + @Test + public void testColumnIO() { log(schema); log("r1"); log(r1); @@ -402,9 +407,8 @@ public void testColumnIO(boolean useDictionary) { } } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testOneOfEach(boolean useDictionary) { + @Test + public void testOneOfEach() { MessageType oneOfEachSchema = MessageTypeParser.parseMessageType(oneOfEach); GroupFactory gf = new SimpleGroupFactory(oneOfEachSchema); Group g1 = gf.newGroup() @@ -420,9 +424,8 @@ public void testOneOfEach(boolean useDictionary) { testSchema(oneOfEachSchema, List.of(g1), useDictionary); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testRequiredOfRequired(boolean useDictionary) { + @Test + public void testRequiredOfRequired() { MessageType reqreqSchema = MessageTypeParser.parseMessageType( "message Document {\n" + " required group foo {\n" + " required int64 bar;\n" + " }\n" + "}\n"); @@ -433,9 +436,8 @@ public void testRequiredOfRequired(boolean useDictionary) { testSchema(reqreqSchema, List.of(g1), useDictionary); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testOptionalRequiredInteraction(boolean useDictionary) { + @Test + public void testOptionalRequiredInteraction() { for (int i = 0; i < 6; i++) { Type current = new PrimitiveType(Repetition.REQUIRED, PrimitiveTypeName.BINARY, "primitive"); for (int j = 0; j < i; j++) { @@ -558,9 +560,8 @@ private void validateFSA( log("----"); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testPushParser(boolean useDictionary) { + @Test + public void testPushParser() { MemPageStore memPageStore = new MemPageStore(1); ColumnWriteStoreV1 columns = newColumnWriteStore(memPageStore, useDictionary); MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema); @@ -584,9 +585,8 @@ private ColumnWriteStoreV1 newColumnWriteStore(MemPageStore memPageStore, boolea .build()); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testEmptyField(boolean useDictionary) { + @Test + public void testEmptyField() { MemPageStore memPageStore = new MemPageStore(1); ColumnWriteStoreV1 columns = newColumnWriteStore(memPageStore, useDictionary); MessageColumnIO columnIO = new ColumnIOFactory(true).getColumnIO(schema); @@ -603,6 +603,9 @@ public void testEmptyField(boolean useDictionary) { @Test public void testGroupWriter() { + assumeThat(useDictionary) + .as("independent of useDictionary, so it only needs to run once") + .isTrue(); List result = new ArrayList<>(); final GroupRecordConverter groupRecordConverter = new GroupRecordConverter(schema); RecordConsumer groupConsumer = new ConverterConsumer(groupRecordConverter.getRootConverter(), schema); @@ -623,6 +626,9 @@ public void testGroupWriter() { @Test public void testWriteWithGroupWriter() { + assumeThat(useDictionary) + .as("independent of useDictionary, so it only needs to run once") + .isTrue(); final String[] expected = { "[DocId]: 10, r:0, d:0", diff --git a/parquet-common/src/test/java/org/apache/parquet/bytes/TestByteBufferInputStreamRead.java b/parquet-common/src/test/java/org/apache/parquet/bytes/TestByteBufferInputStreamRead.java index 7960ccbc99..562fbfafba 100644 --- a/parquet-common/src/test/java/org/apache/parquet/bytes/TestByteBufferInputStreamRead.java +++ b/parquet-common/src/test/java/org/apache/parquet/bytes/TestByteBufferInputStreamRead.java @@ -25,7 +25,9 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Stream; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -33,6 +35,8 @@ * Tests {@link ByteBufferInputStream#read(ByteBuffer)} appending into the caller's destination buffer for both single * buffer and multi buffer streams created through the public wrap entry points. */ +@ParameterizedClass(name = "{0} {1}") +@MethodSource("kinds") public class TestByteBufferInputStreamRead { private static final byte PREFIX_BYTE = (byte) 0x11; @@ -53,14 +57,19 @@ private enum SourceKind { MULTI } + @Parameter(0) + private OutputKind output; + + @Parameter(1) + private SourceKind source; + static Stream kinds() { return Stream.of(OutputKind.values()) .flatMap(output -> Stream.of(SourceKind.values()).map(source -> Arguments.of(output, source))); } - @ParameterizedTest(name = "{0} {1}") - @MethodSource("kinds") - public void partialCopyAdvancesDestinationPosition(OutputKind output, SourceKind source) { + @Test + public void partialCopyAdvancesDestinationPosition() { byte[] data = data(10, 1); int copied = DEST_LIMIT - PREFIX_LENGTH; ByteBuffer dest = destination(output, DEST_LIMIT, PREFIX_LENGTH); @@ -70,9 +79,8 @@ public void partialCopyAdvancesDestinationPosition(OutputKind output, SourceKind assertContent(dest, output, source, Arrays.copyOf(data, copied)); } - @ParameterizedTest(name = "{0} {1}") - @MethodSource("kinds") - public void fullSourceCopyKeepsLimitAndRoomForAppendedRead(OutputKind output, SourceKind source) { + @Test + public void fullSourceCopyKeepsLimitAndRoomForAppendedRead() { byte[] first = data(4, 1); byte[] second = data(3, 11); ByteBuffer dest = destination(output, DEST_CAPACITY, PREFIX_LENGTH); @@ -83,9 +91,8 @@ public void fullSourceCopyKeepsLimitAndRoomForAppendedRead(OutputKind output, So assertContent(dest, output, source, first, second); } - @ParameterizedTest(name = "{0} {1}") - @MethodSource("kinds") - public void readIntoExhaustedDestinationReturnsZeroWithoutMutatingIt(OutputKind output, SourceKind source) { + @Test + public void readIntoExhaustedDestinationReturnsZeroWithoutMutatingIt() { byte[] data = data(10, 1); ByteBuffer dest = destination(output, DEST_LIMIT, DEST_LIMIT); ByteBufferInputStream in = stream(source, data, false); @@ -99,10 +106,8 @@ public void readIntoExhaustedDestinationReturnsZeroWithoutMutatingIt(OutputKind assertThat(in.available()).as("%s %s: source remaining", output, source).isEqualTo(data.length); } - @ParameterizedTest(name = "{0} {1}") - @MethodSource("kinds") - public void readAtEndOfStreamReturnsMinusOneWithoutMutatingDestination(OutputKind output, SourceKind source) - throws Exception { + @Test + public void readAtEndOfStreamReturnsMinusOneWithoutMutatingDestination() throws Exception { byte[] data = data(10, 1); ByteBufferInputStream in = stream(source, data, true); ByteBuffer dest = destination(output, DEST_LIMIT, PREFIX_LENGTH); diff --git a/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java b/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java index 18e9b02efb..126583aab6 100644 --- a/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java +++ b/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java @@ -39,7 +39,10 @@ import java.util.stream.Stream; import org.apache.parquet.util.AutoCloseables; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; @@ -47,12 +50,17 @@ /** * Unit tests for the {@link BytesInput} class and its descendants. */ +@ParameterizedClass(name = "{0}") +@MethodSource("parameters") public class TestBytesInput { private static final Random RANDOM = new Random(2024_02_20_16_28L); - private TrackingByteBufferAllocator allocator; + + @Parameter private ByteBufferAllocator innerAllocator; + private TrackingByteBufferAllocator allocator; + static Stream parameters() { return Stream.of( Arguments.of(new HeapByteBufferAllocator() { @@ -69,8 +77,8 @@ public String toString() { })); } - private void initAllocator(ByteBufferAllocator innerAllocator) { - this.innerAllocator = innerAllocator; + @BeforeEach + public void initAllocator() { allocator = TrackingByteBufferAllocator.wrap(innerAllocator); } @@ -79,10 +87,8 @@ public void closeAllocator() { allocator.close(); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromSingleByteBuffer(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromSingleByteBuffer() throws IOException { byte[] data = new byte[1000]; RANDOM.nextBytes(data); Supplier factory = () -> BytesInput.from(toByteBuffer(data)); @@ -92,10 +98,8 @@ public void testFromSingleByteBuffer(ByteBufferAllocator innerAllocator) throws validateToByteBufferIsInternal(factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromMultipleByteBuffers(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromMultipleByteBuffers() throws IOException { byte[] data = new byte[1000]; RANDOM.nextBytes(data); Supplier factory = () -> BytesInput.from( @@ -107,10 +111,8 @@ public void testFromMultipleByteBuffers(ByteBufferAllocator innerAllocator) thro validate(data, factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromByteArray(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromByteArray() throws IOException { byte[] data = new byte[1000]; RANDOM.nextBytes(data); byte[] input = new byte[data.length + 20]; @@ -121,10 +123,8 @@ public void testFromByteArray(ByteBufferAllocator innerAllocator) throws IOExcep validate(data, factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testCopyDoesNotAliasSourceBytes(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testCopyDoesNotAliasSourceBytes() throws IOException { byte[] source = {'a'}; BytesInput copied = BytesInput.copy(BytesInput.from(source)); @@ -133,10 +133,8 @@ public void testCopyDoesNotAliasSourceBytes(ByteBufferAllocator innerAllocator) assertThat(copied.toByteArray()).isEqualTo(new byte[] {'a'}); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromByteArrayToByteArraySubRange(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromByteArrayToByteArraySubRange() throws IOException { // Sub-range (offset != 0): toByteArray() must return a copy of the specified range byte[] input = new byte[1000]; RANDOM.nextBytes(input); @@ -147,10 +145,8 @@ public void testFromByteArrayToByteArraySubRange(ByteBufferAllocator innerAlloca assertThat(result).isEqualTo(expected); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromInputStream(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromInputStream() throws IOException { byte[] data = new byte[1000]; RANDOM.nextBytes(data); byte[] input = new byte[data.length + 10]; @@ -161,10 +157,8 @@ public void testFromInputStream(ByteBufferAllocator innerAllocator) throws IOExc validate(data, factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromLargeAvailableAgnosticInputStream(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromLargeAvailableAgnosticInputStream() throws IOException { // allocate a bytes that large than // java.nio.channel.Channels.ReadableByteChannelImpl.TRANSFER_SIZE = 8192 byte[] data = new byte[9 * 1024]; @@ -177,10 +171,8 @@ public void testFromLargeAvailableAgnosticInputStream(ByteBufferAllocator innerA validate(data, factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromByteArrayOutputStream(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromByteArrayOutputStream() throws IOException { byte[] data = new byte[1000]; RANDOM.nextBytes(data); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -190,10 +182,8 @@ public void testFromByteArrayOutputStream(ByteBufferAllocator innerAllocator) th validate(data, factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromCapacityByteArrayOutputStreamOneSlab(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromCapacityByteArrayOutputStreamOneSlab() throws IOException { byte[] data = new byte[1000]; RANDOM.nextBytes(data); List toClose = new ArrayList<>(); @@ -217,11 +207,8 @@ public void testFromCapacityByteArrayOutputStreamOneSlab(ByteBufferAllocator inn } } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromCapacityByteArrayOutputStreamMultipleSlabs(ByteBufferAllocator innerAllocator) - throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromCapacityByteArrayOutputStreamMultipleSlabs() throws IOException { byte[] data = new byte[1000]; RANDOM.nextBytes(data); List toClose = new ArrayList<>(); @@ -241,10 +228,8 @@ public void testFromCapacityByteArrayOutputStreamMultipleSlabs(ByteBufferAllocat } } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromInt(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromInt() throws IOException { int value = RANDOM.nextInt(); ByteArrayOutputStream baos = new ByteArrayOutputStream(4); BytesUtils.writeIntLittleEndian(baos, value); @@ -254,10 +239,8 @@ public void testFromInt(ByteBufferAllocator innerAllocator) throws IOException { validate(data, factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromUnsignedVarInt(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromUnsignedVarInt() throws IOException { int value = RANDOM.nextInt(Short.MAX_VALUE); ByteArrayOutputStream baos = new ByteArrayOutputStream(2); BytesUtils.writeUnsignedVarInt(value, baos); @@ -267,10 +250,8 @@ public void testFromUnsignedVarInt(ByteBufferAllocator innerAllocator) throws IO validate(data, factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromUnsignedVarLong(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromUnsignedVarLong() throws IOException { long value = RANDOM.nextInt(Integer.MAX_VALUE); ByteArrayOutputStream baos = new ByteArrayOutputStream(4); BytesUtils.writeUnsignedVarLong(value, baos); @@ -280,10 +261,8 @@ public void testFromUnsignedVarLong(ByteBufferAllocator innerAllocator) throws I validate(data, factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromZigZagVarInt(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromZigZagVarInt() throws IOException { int value = RANDOM.nextInt() % Short.MAX_VALUE; ByteArrayOutputStream baos = new ByteArrayOutputStream(); BytesUtils.writeZigZagVarInt(value, baos); @@ -293,10 +272,8 @@ public void testFromZigZagVarInt(ByteBufferAllocator innerAllocator) throws IOEx validate(data, factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFromZigZagVarLong(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testFromZigZagVarLong() throws IOException { long value = RANDOM.nextInt(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BytesUtils.writeZigZagVarLong(value, baos); @@ -306,20 +283,16 @@ public void testFromZigZagVarLong(ByteBufferAllocator innerAllocator) throws IOE validate(data, factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testEmpty(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testEmpty() throws IOException { byte[] data = new byte[0]; Supplier factory = () -> BytesInput.empty(); validate(data, factory); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testConcatenatingByteBufferCollectorOneSlab(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testConcatenatingByteBufferCollectorOneSlab() throws IOException { byte[] data = new byte[1000]; RANDOM.nextBytes(data); List toClose = new ArrayList<>(); @@ -340,11 +313,8 @@ public void testConcatenatingByteBufferCollectorOneSlab(ByteBufferAllocator inne } } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testConcatenatingByteBufferCollectorMultipleSlabs(ByteBufferAllocator innerAllocator) - throws IOException { - initAllocator(innerAllocator); + @Test + public void testConcatenatingByteBufferCollectorMultipleSlabs() throws IOException { byte[] data = new byte[1000]; RANDOM.nextBytes(data); List toClose = new ArrayList<>(); @@ -366,10 +336,8 @@ public void testConcatenatingByteBufferCollectorMultipleSlabs(ByteBufferAllocato } } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testConcat(ByteBufferAllocator innerAllocator) throws IOException { - initAllocator(innerAllocator); + @Test + public void testConcat() throws IOException { byte[] data = new byte[1000]; RANDOM.nextBytes(data); diff --git a/parquet-common/src/test/java/org/apache/parquet/bytes/TestReusingByteBufferAllocator.java b/parquet-common/src/test/java/org/apache/parquet/bytes/TestReusingByteBufferAllocator.java index fbcd018c3c..8f00bd409e 100644 --- a/parquet-common/src/test/java/org/apache/parquet/bytes/TestReusingByteBufferAllocator.java +++ b/parquet-common/src/test/java/org/apache/parquet/bytes/TestReusingByteBufferAllocator.java @@ -27,10 +27,15 @@ import java.util.function.Function; import java.util.stream.Stream; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +@ParameterizedClass(name = "{0} {1}") +@MethodSource("parameters") public class TestReusingByteBufferAllocator { private enum AllocatorType { @@ -49,6 +54,12 @@ public ReusingByteBufferAllocator create(ByteBufferAllocator allocator) { private static final Random RANDOM = new Random(2024_02_22_09_51L); + @Parameter(0) + private ByteBufferAllocator innerAllocator; + + @Parameter(1) + private AllocatorType type; + private TrackingByteBufferAllocator allocator; static Stream parameters() { @@ -69,7 +80,8 @@ public String toString() { Stream.of(AllocatorType.values()).map(type -> Arguments.of(innerAllocator, type))); } - private void initAllocator(ByteBufferAllocator innerAllocator) { + @BeforeEach + public void initAllocator() { allocator = TrackingByteBufferAllocator.wrap(innerAllocator); } @@ -78,10 +90,8 @@ public void closeAllocator() { allocator.close(); } - @ParameterizedTest(name = "{0} {1}") - @MethodSource("parameters") - public void normalUseCase(ByteBufferAllocator innerAllocator, AllocatorType type) { - initAllocator(innerAllocator); + @Test + public void normalUseCase() { try (ReusingByteBufferAllocator reusingAllocator = type.create(allocator)) { assertThat(reusingAllocator.isDirect()).isEqualTo(innerAllocator.isDirect()); for (int i = 0; i < 10; ++i) { @@ -112,10 +122,8 @@ private void validateBuffer(ByteBuffer buf, int size) { assertThatThrownBy(buf::reset).isInstanceOf(InvalidMarkException.class); } - @ParameterizedTest(name = "{0} {1}") - @MethodSource("parameters") - public void validateExceptions(ByteBufferAllocator innerAllocator, AllocatorType type) { - initAllocator(innerAllocator); + @Test + public void validateExceptions() { try (ByteBufferReleaser releaser = new ByteBufferReleaser(allocator); ReusingByteBufferAllocator reusingAllocator = type.create(allocator)) { ByteBuffer fromOther = allocator.allocate(10); 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 7ca2885fe6..56ba180e23 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 @@ -61,8 +61,10 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; @@ -73,6 +75,8 @@ * Each test runs against all Parquet writer versions. * All data types are validating with and without dictionary encoding. */ +@ParameterizedClass(name = "{0}/{1}") +@MethodSource("getParameters") public class FileEncodingsIT { private static final Logger LOG = LoggerFactory.getLogger(FileEncodingsIT.class); @@ -95,6 +99,12 @@ public class FileEncodingsIT { private static RandomValues.FixedGenerator fixedBinaryGenerator; // Parameters + @Parameter(0) + private PrimitiveTypeName paramTypeName; + + @Parameter(1) + private CompressionCodecName compression; + private TrackingByteBufferAllocator allocator; static Stream getParameters() { @@ -147,10 +157,8 @@ public void closeAllocator() { allocator.close(); } - @ParameterizedTest(name = "{0}/{1}") - @MethodSource("getParameters") - public void testFileEncodingsWithoutDictionary(PrimitiveTypeName paramTypeName, CompressionCodecName compression) - throws Exception { + @Test + public void testFileEncodingsWithoutDictionary() throws Exception { final boolean DISABLE_DICTIONARY = false; List randomValues; randomValues = generateRandomValues(paramTypeName, RECORD_COUNT); @@ -177,10 +185,8 @@ public void testFileEncodingsWithoutDictionary(PrimitiveTypeName paramTypeName, } } - @ParameterizedTest(name = "{0}/{1}") - @MethodSource("getParameters") - public void testFileEncodingsWithDictionary(PrimitiveTypeName paramTypeName, CompressionCodecName compression) - throws Exception { + @Test + public void testFileEncodingsWithDictionary() throws Exception { final boolean ENABLE_DICTIONARY = true; List dictionaryValues = generateDictionaryValues(paramTypeName, RECORD_COUNT); 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 5020f77b7f..e4ab0cd8db 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 @@ -100,9 +100,14 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.EnumSource; +@ParameterizedClass +@EnumSource(WriterVersion.class) public class DictionaryFilterTest { private static final int nElements = 1000; @@ -267,7 +272,11 @@ private static Path fileForWriterVersion(WriterVersion version) { } } - private void setUp(WriterVersion version) throws Exception { + @Parameter + private WriterVersion version; + + @BeforeEach + public void setUp() throws Exception { reader = ParquetFileReader.open(conf, fileForWriterVersion(version)); ParquetMetadata meta = reader.getFooter(); ccmd = meta.getBlocks().get(0).getColumns(); @@ -281,10 +290,8 @@ public void tearDown() throws Exception { } } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testDictionaryEncodedColumns(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testDictionaryEncodedColumns() throws Exception { switch (version) { case PARQUET_1_0: testDictionaryEncodedColumnsV1(); @@ -383,10 +390,8 @@ private void testDictionaryEncodedColumnsV2() { } } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testEqBinary(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testEqBinary() throws Exception { BinaryColumn b = binaryColumn("binary_field"); FilterPredicate pred = eq(b, Binary.fromString("c")); @@ -403,10 +408,8 @@ public void testEqBinary(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testEqFixed(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testEqFixed() throws Exception { BinaryColumn b = binaryColumn("fixed_field"); // Only V2 supports dictionary encoding for FIXED_LEN_BYTE_ARRAY values @@ -425,10 +428,8 @@ public void testEqFixed(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testEqInt96(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testEqInt96() throws Exception { BinaryColumn b = binaryColumn("int96_field"); // INT96 ordering is undefined => no filtering shall be done @@ -445,10 +446,8 @@ public void testEqInt96(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testNotEqBinary(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testNotEqBinary() throws Exception { BinaryColumn sharp = binaryColumn("single_value_field"); BinaryColumn sharpAndNull = binaryColumn("optional_single_value_field"); BinaryColumn b = binaryColumn("binary_field"); @@ -482,10 +481,8 @@ public void testNotEqBinary(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testLtInt(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testLtInt() throws Exception { IntColumn i32 = intColumn("int32_field"); int lowest = Integer.MAX_VALUE; for (int value : intValues) { @@ -504,10 +501,8 @@ public void testLtInt(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testLtFixed(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testLtFixed() throws Exception { BinaryColumn fixed = binaryColumn("fixed_field"); // Only V2 supports dictionary encoding for FIXED_LEN_BYTE_ARRAY values @@ -522,10 +517,8 @@ public void testLtFixed(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testLtEqLong(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testLtEqLong() throws Exception { LongColumn i64 = longColumn("int64_field"); long lowest = Long.MAX_VALUE; for (long value : longValues) { @@ -544,10 +537,8 @@ public void testLtEqLong(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testGtFloat(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testGtFloat() throws Exception { FloatColumn f = floatColumn("float_field"); float highest = Float.MIN_VALUE; for (int value : intValues) { @@ -566,10 +557,8 @@ public void testGtFloat(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testGtEqDouble(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testGtEqDouble() throws Exception { DoubleColumn d = doubleColumn("double_field"); double highest = Double.MIN_VALUE; for (int value : intValues) { @@ -588,10 +577,8 @@ public void testGtEqDouble(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testNaNDictionaryFilterIsConservative(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testNaNDictionaryFilterIsConservative() throws Exception { List nanColumns = nanColumns(); DictionaryPageReadStore nanDictionaries = nanDictionaries(); DoubleColumn doubleColumn = doubleColumn("double_nan_field"); @@ -659,10 +646,8 @@ public void testNaNDictionaryFilterIsConservative(WriterVersion version) throws .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testNaNDictionaryValuesMakeRangeFiltersConservative(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testNaNDictionaryValuesMakeRangeFiltersConservative() throws Exception { DictionaryPageReadStore dictionariesWithNaNs = dictionariesWithNaNs(); assertNaNDictionaryRangeFiltersAreConservative(nanColumns(), dictionariesWithNaNs); assertNaNDictionaryRangeFiltersAreConservative(ieeeNaNColumns(), dictionariesWithNaNs); @@ -823,10 +808,8 @@ private static byte[] littleEndianInts(int... values) { return buffer.array(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testInBinary(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testInBinary() throws Exception { BinaryColumn b = binaryColumn("binary_field"); Set set1 = new HashSet<>(); @@ -895,10 +878,8 @@ public void testInBinary(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testInFixed(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testInFixed() throws Exception { BinaryColumn b = binaryColumn("fixed_field"); // Only V2 supports dictionary encoding for FIXED_LEN_BYTE_ARRAY values @@ -940,10 +921,8 @@ public void testInFixed(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testInInt96(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testInInt96() throws Exception { // INT96 ordering is undefined => no filtering shall be done BinaryColumn b = binaryColumn("int96_field"); @@ -985,10 +964,8 @@ public void testInInt96(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testAnd(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testAnd() throws Exception { BinaryColumn col = binaryColumn("binary_field"); // both evaluate to false (no upper-case letters are in the dictionary) @@ -1013,10 +990,8 @@ public void testAnd(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testOr(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testOr() throws Exception { BinaryColumn col = binaryColumn("binary_field"); // both evaluate to false (no upper-case letters are in the dictionary) @@ -1041,10 +1016,8 @@ public void testOr(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testUdp(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testUdp() throws Exception { InInt32UDP dropabble = new InInt32UDP(ImmutableSet.of(42)); InInt32UDP undroppable = new InInt32UDP(ImmutableSet.of(205)); @@ -1057,10 +1030,8 @@ public void testUdp(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testNullAcceptingUdp(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testNullAcceptingUdp() throws Exception { InInt32UDP drop42DenyNulls = new InInt32UDP(Sets.newHashSet(205)); InInt32UDP drop42AcceptNulls = new InInt32UDP(Sets.newHashSet(null, 205)); @@ -1075,10 +1046,8 @@ public void testNullAcceptingUdp(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testInverseUdp(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testInverseUdp() throws Exception { InInt32UDP droppable = new InInt32UDP(ImmutableSet.of(42)); InInt32UDP undroppable = new InInt32UDP(ImmutableSet.of(205)); Set allValues = ImmutableSet.copyOf(Ints.asList(intValues)); @@ -1103,10 +1072,8 @@ public void testInverseUdp(WriterVersion version) throws Exception { .isTrue(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testColumnWithoutDictionary(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testColumnWithoutDictionary() throws Exception { IntColumn plain = intColumn("plain_int32_field"); DictionaryPageReadStore dictionaryStore = mock(DictionaryPageReadStore.class); @@ -1137,10 +1104,8 @@ public void testColumnWithoutDictionary(WriterVersion version) throws Exception verifyNoInteractions(dictionaryStore); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testColumnWithDictionaryAndPlainEncodings(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testColumnWithDictionaryAndPlainEncodings() throws Exception { IntColumn plain = intColumn("fallback_binary_field"); DictionaryPageReadStore dictionaryStore = mock(DictionaryPageReadStore.class); @@ -1171,10 +1136,8 @@ public void testColumnWithDictionaryAndPlainEncodings(WriterVersion version) thr verifyNoInteractions(dictionaryStore); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testEqMissingColumn(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testEqMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); assertThat(canDrop(eq(b, Binary.fromString("any")), ccmd, dictionaries)) @@ -1186,10 +1149,8 @@ public void testEqMissingColumn(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testNotEqMissingColumn(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testNotEqMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); assertThat(canDrop(notEq(b, Binary.fromString("any")), ccmd, dictionaries)) @@ -1201,10 +1162,8 @@ public void testNotEqMissingColumn(WriterVersion version) throws Exception { .isTrue(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testLtMissingColumn(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testLtMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); assertThat(canDrop(lt(b, Binary.fromString("any")), ccmd, dictionaries)) @@ -1212,10 +1171,8 @@ public void testLtMissingColumn(WriterVersion version) throws Exception { .isTrue(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testLtEqMissingColumn(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testLtEqMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); assertThat(canDrop(ltEq(b, Binary.fromString("any")), ccmd, dictionaries)) @@ -1223,10 +1180,8 @@ public void testLtEqMissingColumn(WriterVersion version) throws Exception { .isTrue(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testGtMissingColumn(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testGtMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); assertThat(canDrop(gt(b, Binary.fromString("any")), ccmd, dictionaries)) @@ -1234,10 +1189,8 @@ public void testGtMissingColumn(WriterVersion version) throws Exception { .isTrue(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testGtEqMissingColumn(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testGtEqMissingColumn() throws Exception { BinaryColumn b = binaryColumn("missing_column"); assertThat(canDrop(gtEq(b, Binary.fromString("any")), ccmd, dictionaries)) @@ -1245,10 +1198,8 @@ public void testGtEqMissingColumn(WriterVersion version) throws Exception { .isTrue(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testUdpMissingColumn(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testUdpMissingColumn() throws Exception { InInt32UDP nullRejecting = new InInt32UDP(ImmutableSet.of(42)); InInt32UDP nullAccepting = new InInt32UDP(Sets.newHashSet((Integer) null)); IntColumn fake = intColumn("missing_column"); @@ -1261,10 +1212,8 @@ public void testUdpMissingColumn(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testInverseUdpMissingColumn(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testInverseUdpMissingColumn() throws Exception { InInt32UDP nullRejecting = new InInt32UDP(ImmutableSet.of(42)); InInt32UDP nullAccepting = new InInt32UDP(Sets.newHashSet((Integer) null)); IntColumn fake = intColumn("missing_column"); @@ -1277,10 +1226,8 @@ public void testInverseUdpMissingColumn(WriterVersion version) throws Exception .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testContainsAnd(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testContainsAnd() throws Exception { BinaryColumn col = binaryColumn("binary_field"); // both evaluate to false (no upper-case letters are in the dictionary) @@ -1305,10 +1252,8 @@ public void testContainsAnd(WriterVersion version) throws Exception { .isFalse(); } - @ParameterizedTest - @EnumSource(WriterVersion.class) - public void testContainsOr(WriterVersion version) throws Exception { - setUp(version); + @Test + public void testContainsOr() throws Exception { BinaryColumn col = binaryColumn("binary_field"); // both evaluate to false (no upper-case letters are in the dictionary) 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 2d70a29090..47b823ab92 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 @@ -31,14 +31,31 @@ import org.apache.parquet.io.InputFile; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +@ParameterizedClass +@MethodSource("fileAndEncryption") public class TestAdaptiveBlockSplitBloomFiltering { + @Parameter(0) + private Path file; + + @Parameter(1) + private boolean isEncrypted; + private final TestBloomFiltering bloomTests = new TestBloomFiltering(); + @BeforeEach + public void setUpBloomTests() { + bloomTests.file = file; + bloomTests.isEncrypted = isEncrypted; + } + @BeforeAll public static void createFiles() throws IOException { TestBloomFiltering.createFiles(true); @@ -53,21 +70,18 @@ static Stream fileAndEncryption() { return TestBloomFiltering.fileAndEncryption(); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testSimpleFiltering(Path file, boolean isEncrypted) throws IOException { - bloomTests.testSimpleFiltering(file, isEncrypted); + @Test + public void testSimpleFiltering() throws IOException { + bloomTests.testSimpleFiltering(); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testNestedFiltering(Path file, boolean isEncrypted) throws IOException { - bloomTests.testNestedFiltering(file, isEncrypted); + @Test + public void testNestedFiltering() throws IOException { + bloomTests.testNestedFiltering(); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void checkBloomFilterSize(Path file, boolean isEncrypted) throws IOException { + @Test + public void checkBloomFilterSize() throws IOException { FileDecryptionProperties fileDecryptionProperties = bloomTests.getFileDecryptionProperties(isEncrypted); final ParquetReadOptions readOptions = ParquetReadOptions.builder() .withDecryption(fileDecryptionProperties) 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 c948498f40..1a21545f2e 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 @@ -64,12 +64,16 @@ import org.apache.parquet.io.api.Binary; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@ParameterizedClass +@MethodSource("fileAndEncryption") public class TestBloomFiltering { private static final Path FILE_V1 = createTempFile(false); private static final Path FILE_V2 = createTempFile(false); @@ -87,6 +91,12 @@ public class TestBloomFiltering { private static final String COLUMN_ENCRYPTION_KEY1_ID = "kc1"; private static final String COLUMN_ENCRYPTION_KEY2_ID = "kc2"; + @Parameter(0) + Path file; + + @Parameter(1) + boolean isEncrypted; + static Stream fileAndEncryption() { return Stream.of( Arguments.of(FILE_V1, false), @@ -360,9 +370,8 @@ public static void deleteFiles() throws IOException { deleteFile(FILE_V2_E); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testSimpleFiltering(Path file, boolean isEncrypted) throws IOException { + @Test + public void testSimpleFiltering() throws IOException { assertCorrectFiltering(file, isEncrypted, record -> record.getId() == 1234L, eq(longColumn("id"), 1234L)); assertCorrectFiltering( @@ -396,9 +405,8 @@ record -> "miller".equals(record.getName()) || "anderson".equals(record.getName( file, isEncrypted, record -> "dummy".equals(record.getName()), in(binaryColumn("name"), values3)); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testNestedFiltering(Path file, boolean isEncrypted) throws IOException { + @Test + public void testNestedFiltering() throws IOException { assertCorrectFiltering( file, isEncrypted, @@ -409,9 +417,8 @@ record -> { eq(doubleColumn("location.lat"), 99.9)); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testContainsEqFiltering(Path file, boolean isEncrypted) throws IOException { + @Test + public void testContainsEqFiltering() throws IOException { assertCorrectFiltering( file, isEncrypted, @@ -421,9 +428,8 @@ record -> Optional.ofNullable(record.getPhoneNumbers()) contains(eq(longColumn("phoneNumbers.phone.number"), 250L))); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testContainsOrFiltering(Path file, boolean isEncrypted) throws IOException { + @Test + public void testContainsOrFiltering() throws IOException { assertCorrectFiltering( file, isEncrypted, @@ -435,9 +441,8 @@ record -> Optional.ofNullable(record.getPhoneNumbers()) contains(eq(longColumn("phoneNumbers.phone.number"), 50L)))); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testContainsAndFiltering(Path file, boolean isEncrypted) throws IOException { + @Test + public void testContainsAndFiltering() throws IOException { assertCorrectFiltering( file, isEncrypted, @@ -450,9 +455,8 @@ record -> Optional.ofNullable(record.getPhoneNumbers()) contains(eq(longColumn("phoneNumbers.phone.number"), 5L)))); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void checkBloomFilterSize(Path file, boolean isEncrypted) throws IOException { + @Test + public void checkBloomFilterSize() throws IOException { FileDecryptionProperties fileDecryptionProperties = getFileDecryptionProperties(isEncrypted); final ParquetReadOptions readOptions = ParquetReadOptions.builder() .withDecryption(fileDecryptionProperties) 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 f9d46892e9..705b676d2f 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 @@ -89,7 +89,9 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; @@ -98,6 +100,8 @@ /** * Unit tests for high level column index based filtering. */ +@ParameterizedClass +@MethodSource("fileAndEncryption") public class TestColumnIndexFiltering { private static final Logger LOGGER = LoggerFactory.getLogger(TestColumnIndexFiltering.class); private static final Random RANDOM = new Random(42); @@ -137,6 +141,12 @@ static Stream fileAndEncryption() { Arguments.of(FILE_V2_E, true)); } + @Parameter(0) + private Path file; + + @Parameter(1) + private boolean isEncrypted; + private TrackingByteBufferAllocator allocator; @BeforeEach @@ -402,9 +412,8 @@ public static void deleteFiles() throws IOException { deleteFile(FILE_V2_E); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testSimpleFiltering(Path file, boolean isEncrypted) throws IOException { + @Test + public void testSimpleFiltering() throws IOException { assertCorrectFiltering(file, isEncrypted, record -> record.getId() == 1234, eq(longColumn("id"), 1234l)); Set idSet = new HashSet<>(); @@ -458,9 +467,8 @@ record -> ("anderson".equals(record.getName()) file, isEncrypted, record -> record.getName() == null, in(binaryColumn("name"), nullSet)); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testNoFiltering(Path file, boolean isEncrypted) throws IOException { + @Test + public void testNoFiltering() throws IOException { // Column index filtering with no-op filter assertThat(readUsers(file, isEncrypted, FilterCompat.NOOP, false)).isEqualTo(DATA); assertThat(readUsers(file, isEncrypted, FilterCompat.NOOP, true)).isEqualTo(DATA); @@ -488,9 +496,8 @@ public void testNoFiltering(Path file, boolean isEncrypted) throws IOException { .isEqualTo(DATA); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testComplexFiltering(Path file, boolean isEncrypted) throws IOException { + @Test + public void testComplexFiltering() throws IOException { assertCorrectFiltering( file, isEncrypted, @@ -611,9 +618,8 @@ public boolean inverseCanDrop(Statistics statistics) { } } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testUDF(Path file, boolean isEncrypted) throws IOException { + @Test + public void testUDF() throws IOException { assertCorrectFiltering( file, isEncrypted, @@ -630,9 +636,8 @@ record -> !(NameStartsWithVowel.isStartingWithVowel(record.getName()) || record. userDefined(longColumn("id"), new IsDivisibleBy(234))))); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testFilteringWithMissingColumns(Path file, boolean isEncrypted) throws IOException { + @Test + public void testFilteringWithMissingColumns() throws IOException { // Missing column filter is always true assertThat(readUsers(file, isEncrypted, notEq(binaryColumn("not-existing-binary"), Binary.EMPTY), true)) .isEqualTo(DATA); @@ -666,9 +671,8 @@ record -> record.getId() == 1234, or(eq(longColumn("id"), 1234l), userDefined(longColumn("not-existing-long"), new IsDivisibleBy(1)))); } - @ParameterizedTest - @MethodSource("fileAndEncryption") - public void testFilteringWithProjection(Path file, boolean isEncrypted) throws IOException { + @Test + public void testFilteringWithProjection() throws IOException { // All rows shall be retrieved because all values in column 'name' shall be handled as null values assertThat(readUsersWithProjection( file, 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 c32cb00f5b..96638d45a9 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 @@ -44,9 +44,13 @@ import org.apache.parquet.schema.GroupType; import org.apache.parquet.schema.MessageType; import org.apache.parquet.schema.PrimitiveType; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.EnumSource; +@ParameterizedClass(name = "WriterVersion = {0}") +@EnumSource(ParquetProperties.WriterVersion.class) public class TestIndexCache { private final Configuration conf = new Configuration(); private final int numRecords = 100000; @@ -61,9 +65,11 @@ public class TestIndexCache { new PrimitiveType(REPEATED, BINARY, "Backward"), new PrimitiveType(REPEATED, BINARY, "Forward"))); - @ParameterizedTest(name = "WriterVersion = {0}") - @EnumSource(ParquetProperties.WriterVersion.class) - public void testNoneCacheStrategy(ParquetProperties.WriterVersion writerVersion) throws IOException { + @Parameter + private ParquetProperties.WriterVersion writerVersion; + + @Test + public void testNoneCacheStrategy() throws IOException { String file = createTestFile(writerVersion, "DocID"); ParquetReadOptions options = ParquetReadOptions.builder().build(); @@ -84,9 +90,8 @@ public void testNoneCacheStrategy(ParquetProperties.WriterVersion writerVersion) } } - @ParameterizedTest(name = "WriterVersion = {0}") - @EnumSource(ParquetProperties.WriterVersion.class) - public void testPrefetchCacheStrategy(ParquetProperties.WriterVersion writerVersion) throws IOException { + @Test + public void testPrefetchCacheStrategy() throws IOException { String file = createTestFile(writerVersion, "DocID", "Name"); ParquetReadOptions options = ParquetReadOptions.builder().build(); 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 60456f5667..a11265a689 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 @@ -115,7 +115,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.ValueSource; import org.mockito.Mockito; import org.slf4j.Logger; @@ -127,8 +128,13 @@ * This verifies that the vector IO code path is correct, and that * the default path continues to work. */ +@ParameterizedClass(name = "vectoredRead = {0}") +@ValueSource(booleans = {true, false}) public class TestParquetFileWriter { + @Parameter + private boolean vectoredRead; + private static final Logger LOG = LoggerFactory.getLogger(TestParquetFileWriter.class); private static final MessageType SCHEMA = MessageTypeParser.parseMessageType("message m {" @@ -205,6 +211,9 @@ private ParquetFileWriter createWriter( @Test public void testWriteMode() throws Exception { + assumeThat(vectoredRead) + .as("independent of vectoredRead, so it only needs to run once") + .isTrue(); MessageType schema = MessageTypeParser.parseMessageType( "message m { required group a {required binary b;} required group " + "c { required int64 d; }}"); Configuration conf = new Configuration(); @@ -216,9 +225,8 @@ public void testWriteMode() throws Exception { Files.deleteIfExists(java.nio.file.Paths.get(path.toUri())); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testWriteRead(boolean vectoredRead) throws Exception { + @Test + public void testWriteRead() throws Exception { Path path = newTempPath(); Configuration configuration = getTestConfiguration(vectoredRead); @@ -317,9 +325,8 @@ public void testWriteRead(boolean vectoredRead) throws Exception { PrintFooter.main(new String[] {path.toString()}); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testWriteReadWithRecordReader(boolean vectoredRead) throws Exception { + @Test + public void testWriteReadWithRecordReader() throws Exception { Path path = newTempPath(); Configuration configuration = getTestConfiguration(vectoredRead); @@ -397,6 +404,9 @@ public void testWriteReadWithRecordReader(boolean vectoredRead) throws Exception @Test public void testWriteEmptyBlock() throws Exception { + assumeThat(vectoredRead) + .as("independent of vectoredRead, so it only needs to run once") + .isTrue(); Path path = newTempPath(); Configuration configuration = new Configuration(); @@ -409,9 +419,8 @@ public void testWriteEmptyBlock() throws Exception { .hasMessage("End block with zero record"); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testBloomFilterWriteRead(boolean vectoredRead) throws Exception { + @Test + public void testBloomFilterWriteRead() throws Exception { MessageType schema = MessageTypeParser.parseMessageType("message test { required binary foo; }"); Path path = newTempPath(); Configuration configuration = getTestConfiguration(vectoredRead); @@ -453,6 +462,9 @@ public void testBloomFilterWriteRead(boolean vectoredRead) throws Exception { @Test public void testAddBloomFilterStringResolvesUnambiguousDottedColumn() throws Exception { + assumeThat(vectoredRead) + .as("independent of vectoredRead, so it only needs to run once") + .isTrue(); MessageType schema = Types.buildMessage().required(BINARY).named("a.b").named("test"); Path path = newTempPath(); Configuration configuration = new Configuration(); @@ -483,6 +495,9 @@ public void testAddBloomFilterStringResolvesUnambiguousDottedColumn() throws Exc @Test public void testAddBloomFilterStringRejectsAmbiguousDottedColumn() throws Exception { + assumeThat(vectoredRead) + .as("independent of vectoredRead, so it only needs to run once") + .isTrue(); MessageType schema = Types.buildMessage() .required(BINARY) .named("a.b") @@ -503,9 +518,8 @@ public void testAddBloomFilterStringRejectsAmbiguousDottedColumn() throws Except writer.close(); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testWriteReadDataPageV2(boolean vectoredRead) throws Exception { + @Test + public void testWriteReadDataPageV2() throws Exception { Path path = newTempPath(); Configuration configuration = getTestConfiguration(vectoredRead); @@ -612,9 +626,8 @@ public void testWriteReadDataPageV2(boolean vectoredRead) throws Exception { } } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testAlignmentWithPadding(boolean vectoredRead) throws Exception { + @Test + public void testAlignmentWithPadding() throws Exception { Path path = newTempPath(); Configuration conf = getTestConfiguration(vectoredRead); // Disable writing out checksums as hardcoded byte offsets in assertions below expect it @@ -736,9 +749,8 @@ public void testAlignmentWithPadding(boolean vectoredRead) throws Exception { PrintFooter.main(new String[] {path.toString()}); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testAlignmentWithNoPaddingNeeded(boolean vectoredRead) throws Exception { + @Test + public void testAlignmentWithNoPaddingNeeded() throws Exception { Path path = newTempPath(); Configuration conf = getTestConfiguration(vectoredRead); // Disable writing out checksums as hardcoded byte offsets in assertions below expect it @@ -861,9 +873,8 @@ public void testAlignmentWithNoPaddingNeeded(boolean vectoredRead) throws Except PrintFooter.main(new String[] {path.toString()}); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testConvertToThriftStatistics(boolean vectoredRead) throws Exception { + @Test + public void testConvertToThriftStatistics() throws Exception { long[] longArray = new long[] {39L, 99L, 12L, 1000L, 65L, 542L, 2533461316L, -253346131996L, Long.MAX_VALUE, Long.MIN_VALUE }; @@ -884,9 +895,8 @@ public void testConvertToThriftStatistics(boolean vectoredRead) throws Exception assertThat(convertedBackStats.getNumNulls()).isEqualTo(parquetMRstats.getNumNulls()); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testWriteReadStatistics(boolean vectoredRead) throws Exception { + @Test + public void testWriteReadStatistics() throws Exception { // this test assumes statistics will be read assumeThat(shouldIgnoreStatistics(Version.FULL_VERSION, BINARY)).isFalse(); @@ -979,9 +989,8 @@ public void testWriteReadStatistics(boolean vectoredRead) throws Exception { } } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testMetaDataFile(boolean vectoredRead) throws Exception { + @Test + public void testMetaDataFile() throws Exception { Path testDirPath = new Path(Files.createTempDirectory(tempDir, "folder").toUri()); Configuration configuration = getTestConfiguration(vectoredRead); @@ -1025,9 +1034,8 @@ public void testMetaDataFile(boolean vectoredRead) throws Exception { validateFooters(footers); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testWriteReadStatisticsAllNulls(boolean vectoredRead) throws Exception { + @Test + public void testWriteReadStatisticsAllNulls() throws Exception { // this test assumes statistics will be read assumeThat(shouldIgnoreStatistics(Version.FULL_VERSION, BINARY)).isFalse(); @@ -1157,9 +1165,8 @@ private void validateContains(MessageType schema, PageReadStore pages, String[] assertThat(((DataPageV1) page).getBytes().toByteArray()).isEqualTo(bytes.toByteArray()); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testMergeMetadata(boolean vectoredRead) { + @Test + public void testMergeMetadata() { FileMetaData md1 = new FileMetaData( new MessageType( "root1", new PrimitiveType(REPEATED, BINARY, "a"), new PrimitiveType(OPTIONAL, BINARY, "b")), @@ -1178,9 +1185,8 @@ public void testMergeMetadata(boolean vectoredRead) { .isEqualTo(merged.getSchema()); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testMergeFooters(boolean vectoredRead) { + @Test + public void testMergeFooters() { List oneBlocks = new ArrayList(); oneBlocks.add(new BlockMetaData()); oneBlocks.add(new BlockMetaData()); @@ -1231,9 +1237,8 @@ public void testMergeFooters(boolean vectoredRead) { * {@link ParquetFileWriter#mergeFooters(Path, List)} expects a fully-qualified * path for the root and crashes if a relative one is provided. */ - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testWriteMetadataFileWithRelativeOutputPath(boolean vectoredRead) throws IOException { + @Test + public void testWriteMetadataFileWithRelativeOutputPath() throws IOException { Configuration conf = getTestConfiguration(vectoredRead); FileSystem fs = FileSystem.get(conf); Path relativeRoot = new Path("target/_test_relative"); @@ -1254,9 +1259,8 @@ public void testWriteMetadataFileWithRelativeOutputPath(boolean vectoredRead) th ParquetFileWriter.writeMetadataFile(conf, relativeRoot, footers, JobSummaryLevel.ALL); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testColumnIndexWriteRead(boolean vectoredRead) throws Exception { + @Test + public void testColumnIndexWriteRead() throws Exception { // Don't truncate testColumnIndexWriteRead(vectoredRead, Integer.MAX_VALUE); // Truncate to DEFAULT_COLUMN_INDEX_TRUNCATE_LENGTH @@ -1436,9 +1440,8 @@ private void testColumnIndexWriteRead(boolean vectoredRead, int columnIndexTrunc } } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testMergeMetadataWithConflictingKeyValues(boolean vectoredRead) { + @Test + public void testMergeMetadataWithConflictingKeyValues() { Map keyValues1 = new HashMap() { { put("a", "b"); @@ -1471,9 +1474,8 @@ public void testMergeMetadataWithConflictingKeyValues(boolean vectoredRead) { assertThat(mergedValue).isIn("b,c", "c,b"); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testMergeMetadataWithNoConflictingKeyValues(boolean vectoredRead) { + @Test + public void testMergeMetadataWithNoConflictingKeyValues() { Map keyValues1 = new HashMap() { { put("a", "b"); @@ -1537,11 +1539,17 @@ private Path existingTempPath() throws IOException { @Test public void testNoFlushWhenEndFailsWithIOException() throws Exception { + assumeThat(vectoredRead) + .as("independent of vectoredRead, so it only needs to run once") + .isTrue(); assertEndFailureDoesNotFlush(new IOException("injected end() failure")); } @Test public void testNoFlushWhenEndFailsWithRuntimeException() throws Exception { + assumeThat(vectoredRead) + .as("independent of vectoredRead, so it only needs to run once") + .isTrue(); // Validate that non-IOException failures are also caught and mark the writer aborted. assertEndFailureDoesNotFlush(new RuntimeException("injected end() failure")); } @@ -1606,6 +1614,9 @@ private void assertEndFailureDoesNotFlush(Throwable toThrow) throws Exception { @Test public void testNoFlushWhenRecordWriterCloseFailsWithError() throws Exception { + assumeThat(vectoredRead) + .as("independent of vectoredRead, so it only needs to run once") + .isTrue(); // An Error thrown from close() outside ParquetFileWriter (e.g. finalizeWrite) must abort // before the finally flushes, so an incomplete file is never committed. java.nio.file.Path path = tempDir.resolve(java.util.UUID.randomUUID() + ".tmp"); diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetReader.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetReader.java index 4aee0d0b9d..cf47656e31 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetReader.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetReader.java @@ -23,6 +23,7 @@ import static org.apache.parquet.hadoop.ParquetFileWriter.Mode.OVERWRITE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assumptions.assumeThat; import java.io.IOException; import java.net.URISyntaxException; @@ -60,14 +61,22 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.MethodSource; +@ParameterizedClass(name = "{0}") +@MethodSource("data") public class TestParquetReader { + @Parameter + private Path file; + private static final Path FILE_V1 = createTempFile(); private static final Path FILE_V2 = createTempFile(); private static final Path STATIC_FILE_WITHOUT_COL_INDEXES = @@ -201,6 +210,9 @@ public void closeAllocator() { }) public void testSharedDirectCodecPreservesColumnValues( CompressionCodecName codec, WriterVersion version, boolean dictionaryEnabled) throws IOException { + assumeThat(file) + .as("independent of the input file, so it only needs to run once") + .isEqualTo(FILE_V1); Path path = new Path(tempDir.resolve("compressed.parquet").toUri()); Configuration conf = new Configuration(); MessageType schema = MessageTypeParser.parseMessageType( @@ -266,9 +278,8 @@ public void testSharedDirectCodecPreservesColumnValues( } } - @ParameterizedTest - @MethodSource("data") - public void testCurrentRowIndex(Path file) throws Exception { + @Test + public void testCurrentRowIndex() throws Exception { ParquetReader reader = PhoneBookWriter.createReader(file, FilterCompat.NOOP, allocator); // Fetch row index without processing any row. assertThat(reader.getCurrentRowIndex()).isEqualTo(-1); @@ -289,9 +300,8 @@ public void testCurrentRowIndex(Path file) throws Exception { assertThat(reader.getCurrentRowIndex()).isEqualTo(-1); } - @ParameterizedTest - @MethodSource("data") - public void testCurrentRowGroupIndex(Path file) throws Exception { + @Test + public void testCurrentRowGroupIndex() throws Exception { int expectedRowGroups; try (ParquetFileReader fileReader = ParquetFileReader.open(HadoopInputFile.fromPath(file, new Configuration()))) { @@ -324,9 +334,8 @@ public void testCurrentRowGroupIndex(Path file) throws Exception { } } - @ParameterizedTest - @MethodSource("data") - public void testRangeFiltering(Path file) throws Exception { + @Test + public void testRangeFiltering() throws Exception { long size = fileSize(file); // The readUsers also validates the rowIndex for each returned row. readUsers(file, FilterCompat.NOOP, false, false, size / 2, size); @@ -335,9 +344,8 @@ public void testRangeFiltering(Path file) throws Exception { readUsers(file, FilterCompat.NOOP, true, true, size * 3 / 4, size); } - @ParameterizedTest - @MethodSource("data") - public void testSimpleFiltering(Path file) throws Exception { + @Test + public void testSimpleFiltering() throws Exception { Set idSet = new HashSet<>(); idSet.add(123l); idSet.add(567l); @@ -353,9 +361,8 @@ public void testSimpleFiltering(Path file) throws Exception { assertThat(filteredUsers3).hasSize(1000); } - @ParameterizedTest - @MethodSource("data") - public void testNoFiltering(Path file) throws Exception { + @Test + public void testNoFiltering() throws Exception { assertThat(readUsers(file, FilterCompat.NOOP, false, false)).isEqualTo(DATA); assertThat(readUsers(file, FilterCompat.NOOP, true, false)).isEqualTo(DATA); assertThat(readUsers(file, FilterCompat.NOOP, false, true)).isEqualTo(DATA); @@ -370,33 +377,29 @@ protected ReadSupport getReadSupport() { } } - @ParameterizedTest - @MethodSource("data") - public void testParquetReaderBuilderWithInputFile(Path file) throws Exception { + @Test + public void testParquetReaderBuilderWithInputFile() throws Exception { InputFile inputFile = HadoopInputFile.fromPath(file, new Configuration()); Builder builder = new TestParquetReaderBuilder().withFile(inputFile); assertThat(PhoneBookWriter.readUsers(builder, false)).isEqualTo(DATA); } - @ParameterizedTest - @MethodSource("data") - public void testParquetReaderBuilderValidatesThatInputFileCanNotBeNull(Path file) throws Exception { + @Test + public void testParquetReaderBuilderValidatesThatInputFileCanNotBeNull() throws Exception { assertThatThrownBy(() -> new TestParquetReaderBuilder().withFile(null).build()) .isInstanceOf(NullPointerException.class) .hasMessage("file cannot be null"); } - @ParameterizedTest - @MethodSource("data") - public void testParquetReaderBuilderValidatesThatInputFileIsSet(Path file) throws Exception { + @Test + public void testParquetReaderBuilderValidatesThatInputFileIsSet() throws Exception { assertThatThrownBy(() -> new TestParquetReaderBuilder().build()) .isInstanceOf(IllegalStateException.class) .hasMessage("File or Path must be set"); } - @ParameterizedTest - @MethodSource("data") - public void testParquetReaderBuilderCanNotConfigurePathAndFile(Path file) throws Exception { + @Test + public void testParquetReaderBuilderCanNotConfigurePathAndFile() throws Exception { InputFile inputFile = HadoopInputFile.fromPath(file, new Configuration()); assertThatThrownBy(() -> ParquetReader.builder(new GroupReadSupport(), file) .withFile(inputFile) diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/example/TestInputOutputFormat.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/example/TestInputOutputFormat.java index 9587f1f0a7..a3fa0ab6b3 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/example/TestInputOutputFormat.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/example/TestInputOutputFormat.java @@ -57,7 +57,9 @@ import org.apache.parquet.hadoop.metadata.CompressionCodecName; import org.apache.parquet.schema.MessageTypeParser; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,6 +68,8 @@ * Parameterized on Vectored IO enabled/disabled so can verify that * ranged reads work through the bridge on compatible hadoop versions. */ +@ParameterizedClass(name = "vectored : {0}") +@ValueSource(booleans = {true, false}) public class TestInputOutputFormat { private static final Logger LOG = LoggerFactory.getLogger(TestInputOutputFormat.class); @@ -81,6 +85,9 @@ public class TestInputOutputFormat { private Class> readMapperClass; private Class> writeMapperClass; + @Parameter + private boolean vectoredRead; + @BeforeEach public void setUp() { writeSchema = "message example {\n" + "required int32 line;\n" + "required binary content;\n" + "}"; @@ -93,9 +100,9 @@ public void setUp() { writeMapperClass = WriteMapper.class; } - private Configuration createConf(boolean readType) { + private Configuration createConf() { Configuration conf = new Configuration(); - conf.setBoolean(ParquetInputFormat.HADOOP_VECTORED_IO_ENABLED, readType); + conf.setBoolean(ParquetInputFormat.HADOOP_VECTORED_IO_ENABLED, vectoredRead); return conf; } @@ -233,10 +240,9 @@ private void testReadWrite(Configuration conf, CompressionCodecName codec, Map() { { put("parquet.task.side.metadata", "true"); @@ -259,9 +263,8 @@ public void testReadWriteTaskSideMD(boolean readType) /** * Uses a filter that drops all records to test handling of tasks (mappers) that need to do no work at all */ - @ParameterizedTest(name = "vectored : {0}") - @ValueSource(booleans = {true, false}) - public void testReadWriteTaskSideMDAggressiveFilter(boolean readType) + @Test + public void testReadWriteTaskSideMDAggressiveFilter() throws IOException, ClassNotFoundException, InterruptedException { Configuration conf = new Configuration(); @@ -281,9 +284,8 @@ public void testReadWriteTaskSideMDAggressiveFilter(boolean readType) assertThat(lines).isEmpty(); } - @ParameterizedTest(name = "vectored : {0}") - @ValueSource(booleans = {true, false}) - public void testReadWriteFilter(boolean readType) throws IOException, ClassNotFoundException, InterruptedException { + @Test + public void testReadWriteFilter() throws IOException, ClassNotFoundException, InterruptedException { Configuration conf = new Configuration(); // this filter predicate should keep some records but not all (first 500 characters) @@ -329,10 +331,9 @@ public void testReadWriteFilter(boolean readType) throws IOException, ClassNotFo assertThat(sbFound).asString().isEqualTo(String.join("\n", expected)); } - @ParameterizedTest(name = "vectored : {0}") - @ValueSource(booleans = {true, false}) - public void testProjection(boolean readType) throws Exception { - Configuration conf = createConf(readType); + @Test + public void testProjection() throws Exception { + Configuration conf = createConf(); readSchema = partialSchema; writeMapperClass = PartialWriteMapper.class; runMapReduceJob(conf, CompressionCodecName.GZIP); @@ -350,10 +351,9 @@ private static long value(Job job, String groupName, String name) throws Excepti return (Long) getValue.invoke(counter); } - @ParameterizedTest(name = "vectored : {0}") - @ValueSource(booleans = {true, false}) - public void testReadWriteWithCounter(boolean readType) throws Exception { - Configuration conf = createConf(readType); + @Test + public void testReadWriteWithCounter() throws Exception { + Configuration conf = createConf(); runMapReduceJob(conf, CompressionCodecName.GZIP); assertThat(value(readJob, "parquet", "bytesread")).isPositive(); @@ -364,10 +364,9 @@ public void testReadWriteWithCounter(boolean readType) throws Exception { // not testing the time read counter since it could be zero due to the size of data is too small } - @ParameterizedTest(name = "vectored : {0}") - @ValueSource(booleans = {true, false}) - public void testReadWriteWithoutCounter(boolean readType) throws Exception { - Configuration conf = createConf(readType); + @Test + public void testReadWriteWithoutCounter() throws Exception { + Configuration conf = createConf(); conf.set("parquet.benchmark.time.read", "false"); conf.set("parquet.benchmark.bytes.total", "false"); conf.set("parquet.benchmark.bytes.read", "false"); diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/rewrite/ParquetRewriterTest.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/rewrite/ParquetRewriterTest.java index f9943381d1..22d3444a8a 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/rewrite/ParquetRewriterTest.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/rewrite/ParquetRewriterTest.java @@ -21,7 +21,6 @@ import static java.util.Collections.emptyMap; import static org.apache.parquet.column.ParquetProperties.WriterVersion.PARQUET_1_0; import static org.apache.parquet.column.ParquetProperties.WriterVersion.PARQUET_2_0; -import static org.apache.parquet.schema.LogicalTypeAnnotation.stringType; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.BINARY; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.DOUBLE; import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.FLOAT; @@ -66,9 +65,7 @@ import org.apache.parquet.crypto.ParquetCipher; import org.apache.parquet.crypto.ParquetCryptoRuntimeException; import org.apache.parquet.example.data.Group; -import org.apache.parquet.example.data.GroupFactory; import org.apache.parquet.example.data.simple.SimpleGroup; -import org.apache.parquet.example.data.simple.SimpleGroupFactory; import org.apache.parquet.format.DataPageHeader; import org.apache.parquet.format.DataPageHeaderV2; import org.apache.parquet.format.PageHeader; @@ -77,9 +74,7 @@ import org.apache.parquet.hadoop.ParquetFileReader; import org.apache.parquet.hadoop.ParquetReader; import org.apache.parquet.hadoop.ParquetWriter; -import org.apache.parquet.hadoop.example.ExampleParquetWriter; import org.apache.parquet.hadoop.example.GroupReadSupport; -import org.apache.parquet.hadoop.example.GroupWriteSupport; import org.apache.parquet.hadoop.metadata.BlockMetaData; import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData; import org.apache.parquet.hadoop.metadata.ColumnPath; @@ -104,13 +99,15 @@ import org.apache.parquet.schema.MessageType; import org.apache.parquet.schema.PrimitiveType; import org.apache.parquet.schema.Type; -import org.apache.parquet.schema.Types; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; +@ParameterizedClass(name = "{0}") +@MethodSource("parameters") public class ParquetRewriterTest { private static final class RewriterTestParams { @@ -183,6 +180,9 @@ public String toString() { private EncryptionTestFile gzipEncryptionTestFileWithoutBloomFilterColumn; private EncryptionTestFile uncompressedEncryptionTestFileWithoutBloomFilterColumn; + @Parameter + private RewriterTestParams params; + static Stream parameters() { final int defaultNumRecord = 10000; final int defaultRowsPerPage = defaultNumRecord / 5; @@ -196,7 +196,7 @@ static Stream parameters() { PARQUET_2_0, "PREFETCH_BLOCK", false, defaultNumRecord, defaultRowsPerPage))); } - private void initTestState(RewriterTestParams params) throws IOException { + private void initTestState() throws IOException { this.writerVersion = params.writerVersion(); this.indexCacheStrategy = IndexCache.CacheStrategy.valueOf(params.indexCacheStrategy()); this.usingHadoop = params.usingHadoop(); @@ -261,16 +261,15 @@ private void testPruneSingleColumnTranslateCodec(List inputPaths) throws E } @BeforeEach - public void setUp() { + public void setUp() throws IOException { outputFile = TestFileBuilder.createTempFile("test"); inputFiles = Lists.newArrayList(); inputFilesToJoin = new ArrayList<>(); + initTestState(); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testPruneSingleColumnTranslateCodecSingleFile(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testPruneSingleColumnTranslateCodecSingleFile() throws Exception { addGzipInputFile(); List inputPaths = new ArrayList() { { @@ -280,10 +279,8 @@ public void testPruneSingleColumnTranslateCodecSingleFile(RewriterTestParams par testPruneSingleColumnTranslateCodec(inputPaths); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testPruneSingleColumnTranslateCodecTwoFiles(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testPruneSingleColumnTranslateCodecTwoFiles() throws Exception { addGzipInputFile(); addUncompressedInputFile(); List inputPaths = new ArrayList() { @@ -336,10 +333,8 @@ private void testPruneNullifyTranslateCodec(List inputPaths) throws Except validateRowGroupRowCount(); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testPruneNullifyTranslateCodecSingleFile(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testPruneNullifyTranslateCodecSingleFile() throws Exception { addGzipInputFile(); List inputPaths = new ArrayList() { @@ -350,10 +345,8 @@ public void testPruneNullifyTranslateCodecSingleFile(RewriterTestParams params) testPruneNullifyTranslateCodec(inputPaths); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testPruneNullifyTranslateCodecTwoFiles(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testPruneNullifyTranslateCodecTwoFiles() throws Exception { addGzipInputFile(); addUncompressedInputFile(); @@ -426,10 +419,8 @@ private void testPruneEncryptTranslateCodec(List inputPaths) throws Except validateRowGroupRowCount(); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testPruneEncryptTranslateCodecSingleFile(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testPruneEncryptTranslateCodecSingleFile() throws Exception { addGzipInputFile(); List inputPaths = new ArrayList() { @@ -440,10 +431,8 @@ public void testPruneEncryptTranslateCodecSingleFile(RewriterTestParams params) testPruneEncryptTranslateCodec(inputPaths); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testPruneEncryptTranslateCodecTwoFiles(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testPruneEncryptTranslateCodecTwoFiles() throws Exception { addGzipInputFile(); addUncompressedInputFile(); @@ -456,10 +445,8 @@ public void testPruneEncryptTranslateCodecTwoFiles(RewriterTestParams params) th testPruneEncryptTranslateCodec(inputPaths); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testRewriteWithoutColumnIndexes(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testRewriteWithoutColumnIndexes() throws Exception { List inputPaths = new ArrayList() { { add(new Path(ParquetRewriterTest.class @@ -596,10 +583,8 @@ private void testNullifyAndEncryptColumn(List inputPaths) throws Exception } } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testNullifyEncryptSingleFile(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testNullifyEncryptSingleFile() throws Exception { addGzipInputFile(); List inputPaths = new ArrayList() { @@ -610,10 +595,8 @@ public void testNullifyEncryptSingleFile(RewriterTestParams params) throws Excep testNullifyAndEncryptColumn(inputPaths); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testNullifyEncryptTwoFiles(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testNullifyEncryptTwoFiles() throws Exception { addGzipInputFile(); addUncompressedInputFile(); @@ -626,10 +609,8 @@ public void testNullifyEncryptTwoFiles(RewriterTestParams params) throws Excepti testNullifyAndEncryptColumn(inputPaths); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testMergeTwoFilesOnly(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testMergeTwoFilesOnly() throws Exception { addGzipInputFile(); addUncompressedInputFile(); @@ -674,10 +655,8 @@ public void testMergeTwoFilesOnly(RewriterTestParams params) throws Exception { validateRowGroupRowCount(); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testMergeTwoFilesOnlyRenameColumn(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testMergeTwoFilesOnlyRenameColumn() throws Exception { addGzipInputFile(); addUncompressedInputFile(); @@ -733,58 +712,46 @@ public void testMergeTwoFilesOnlyRenameColumn(RewriterTestParams params) throws } } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testMergeTwoFilesWithDifferentSchema(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testMergeTwoFilesWithDifferentSchema() throws Exception { assertThatThrownBy(() -> testMergeTwoFilesWithDifferentSchemaSetup(true, null, null)) .isInstanceOf(InvalidSchemaException.class) .hasMessageContaining("Input files have different schemas, current file:"); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testMergeTwoFilesToJoinWithDifferentSchema(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testMergeTwoFilesToJoinWithDifferentSchema() throws Exception { assertThatThrownBy(() -> testMergeTwoFilesWithDifferentSchemaSetup(false, null, null)) .isInstanceOf(InvalidSchemaException.class) .hasMessageContaining("Input files have different schemas, current file:"); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testMergeTwoFilesWithWrongDestinationRenamedColumn(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testMergeTwoFilesWithWrongDestinationRenamedColumn() throws Exception { assertThatThrownBy(() -> testMergeTwoFilesWithDifferentSchemaSetup( null, ImmutableMap.of("WrongColumnName", "WrongColumnNameRenamed"), null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Column to rename 'WrongColumnName' is not found in input files schema"); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testMergeTwoFilesWithWrongSourceRenamedColumn(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testMergeTwoFilesWithWrongSourceRenamedColumn() throws Exception { assertThatThrownBy( () -> testMergeTwoFilesWithDifferentSchemaSetup(null, ImmutableMap.of("Name", "DocId"), null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Renamed column target name 'DocId' is already present in a schema"); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testMergeTwoFilesNullifyAndRenamedSameColumn(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testMergeTwoFilesNullifyAndRenamedSameColumn() throws Exception { assertThatThrownBy(() -> testMergeTwoFilesWithDifferentSchemaSetup( null, ImmutableMap.of("Name", "NameRenamed"), ImmutableMap.of("Name", MaskMode.NULLIFY))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Cannot nullify and rename the same column"); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testInputFileReadersClosedWhenLaterInputFileFailsToOpen(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testInputFileReadersClosedWhenLaterInputFileFailsToOpen() throws Exception { MessageType schema = new MessageType("schema", new PrimitiveType(OPTIONAL, INT64, "DocId")); EncryptionTestFile file = new TestFileBuilder(conf, schema) .withNumRecord(numRecord) @@ -923,10 +890,8 @@ public void testMergeTwoFilesWithDifferentSchemaSetup( rewriter = new ParquetRewriter(options); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testRewriteFileWithMultipleBlocks(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testRewriteFileWithMultipleBlocks() throws Exception { addGzipInputFile(); List inputPaths = new ArrayList() { @@ -937,10 +902,8 @@ public void testRewriteFileWithMultipleBlocks(RewriterTestParams params) throws testPruneSingleColumnTranslateCodec(inputPaths); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testPruneSingleColumnTranslateCodecAndEnableBloomFilter(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testPruneSingleColumnTranslateCodecAndEnableBloomFilter() throws Exception { testSingleInputFileSetupWithBloomFilter("DocId"); List inputPaths = new ArrayList() { { @@ -955,10 +918,8 @@ public void testPruneSingleColumnTranslateCodecAndEnableBloomFilter(RewriterTest assertThat(outputBloomFilters).isEqualTo(inputBloomFilters); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testPruneNullifyTranslateCodecAndEnableBloomFilter(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testPruneNullifyTranslateCodecAndEnableBloomFilter() throws Exception { testSingleInputFileSetupWithBloomFilter("DocId", "Links.Forward"); List inputPaths = new ArrayList() { { @@ -980,10 +941,8 @@ public void testPruneNullifyTranslateCodecAndEnableBloomFilter(RewriterTestParam assertThat(outputBloomFilters).isEqualTo(inputBloomFilters); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testPruneEncryptTranslateCodecAndEnableBloomFilter(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testPruneEncryptTranslateCodecAndEnableBloomFilter() throws Exception { testSingleInputFileSetupWithBloomFilter("DocId", "Links.Forward"); List inputPaths = new ArrayList() { { @@ -1005,61 +964,6 @@ public void testPruneEncryptTranslateCodecAndEnableBloomFilter(RewriterTestParam assertThat(outputBloomFilters).isEqualTo(inputBloomFilters); } - @ParameterizedTest(name = "transcode = {0}") - @ValueSource(booleans = {false, true}) - public void testRewritePreservesBloomFiltersForCollidingDotStringPaths(boolean transcode) throws Exception { - conf = new Configuration(); - usingHadoop = true; - Path inputPath = writeBloomFilterPathCollisionFile(); - - RewriteOptions.Builder builder = new RewriteOptions.Builder(conf, List.of(inputPath), new Path(outputFile)); - if (transcode) { - builder.transform(CompressionCodecName.GZIP); - } - - rewriter = new ParquetRewriter(builder.build()); - rewriter.processBlocks(); - rewriter.close(); - - // A codec change rewrites pages through processChunk; leaving the codec unchanged copies chunks - // through appendColumnChunk. Both branches must retain component boundaries even though the two - // columns below have the same dot-separated display name. - Map> inputBloomFilters = allBloomFilters(inputPath.toString(), null); - Map> outputBloomFilters = allOutputBloomFilters(null); - assertThat(outputBloomFilters).containsOnlyKeys(ColumnPath.get("a.b"), ColumnPath.get("a", "b")); - assertThat(outputBloomFilters).isEqualTo(inputBloomFilters); - } - - private Path writeBloomFilterPathCollisionFile() throws IOException { - MessageType schema = Types.buildMessage() - .required(BINARY) - .as(stringType()) - .named("a.b") - .requiredGroup() - .required(BINARY) - .as(stringType()) - .named("b") - .named("a") - .named("msg"); - GroupWriteSupport.setSchema(schema, conf); - GroupFactory factory = new SimpleGroupFactory(schema); - Path inputPath = new Path(TestFileBuilder.createTempFile("bloom-filter-path-collision")); - - try (ParquetWriter writer = ExampleParquetWriter.builder(inputPath) - .withConf(conf) - .withCompressionCodec(CompressionCodecName.UNCOMPRESSED) - .withDictionaryEncoding(false) - .withBloomFilterEnabled(true) - .build()) { - for (int i = 0; i < 100; i++) { - Group group = factory.newGroup().append("a.b", "top-" + i); - group.addGroup("a").append("b", "nested-" + i); - writer.write(group); - } - } - return inputPath; - } - private void testSingleInputFileSetupWithBloomFilter(String... bloomFilterEnabledColumns) throws IOException { testSingleInputFileSetup(bloomFilterEnabledColumns); } @@ -1077,10 +981,8 @@ private void testSingleInputFileSetup(String... bloomFilterEnabledColumns) throw .build()); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testFilesToJoinHaveDifferentRowCount(RewriterTestParams params) throws Exception { - initTestState(params); + @Test + public void testFilesToJoinHaveDifferentRowCount() throws Exception { MessageType schema1 = new MessageType("schema", new PrimitiveType(OPTIONAL, INT64, "DocId")); MessageType schema2 = new MessageType("schema", new PrimitiveType(REQUIRED, BINARY, "Name")); inputFiles = ImmutableList.of( @@ -1098,19 +1000,13 @@ public void testFilesToJoinHaveDifferentRowCount(RewriterTestParams params) thro .hasMessageContaining("The number of rows in each block must match"); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testOneInputFileManyInputFilesToJoinWithJoinColumnsOverwrite(RewriterTestParams params) - throws Exception { - initTestState(params); + @Test + public void testOneInputFileManyInputFilesToJoinWithJoinColumnsOverwrite() throws Exception { testOneInputFileManyInputFilesToJoinSetup(true); } - @ParameterizedTest(name = "{0}") - @MethodSource("parameters") - public void testOneInputFileManyInputFilesToJoinWithoutJoinColumnsOverwrite(RewriterTestParams params) - throws Exception { - initTestState(params); + @Test + public void testOneInputFileManyInputFilesToJoinWithoutJoinColumnsOverwrite() throws Exception { testOneInputFileManyInputFilesToJoinSetup(false); } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/rewrite/TestParquetRewriterBloomFilterPaths.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/rewrite/TestParquetRewriterBloomFilterPaths.java new file mode 100644 index 0000000000..03ecfe8475 --- /dev/null +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/rewrite/TestParquetRewriterBloomFilterPaths.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.parquet.hadoop.rewrite; + +import static org.apache.parquet.schema.LogicalTypeAnnotation.stringType; +import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.BINARY; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; +import org.apache.parquet.ParquetReadOptions; +import org.apache.parquet.column.values.bloomfilter.BloomFilter; +import org.apache.parquet.example.data.Group; +import org.apache.parquet.example.data.GroupFactory; +import org.apache.parquet.example.data.simple.SimpleGroupFactory; +import org.apache.parquet.hadoop.ParquetWriter; +import org.apache.parquet.hadoop.example.ExampleParquetWriter; +import org.apache.parquet.hadoop.example.GroupWriteSupport; +import org.apache.parquet.hadoop.metadata.BlockMetaData; +import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData; +import org.apache.parquet.hadoop.metadata.ColumnPath; +import org.apache.parquet.hadoop.metadata.CompressionCodecName; +import org.apache.parquet.hadoop.metadata.ParquetMetadata; +import org.apache.parquet.hadoop.util.CompressionConverter.TransParquetFileReader; +import org.apache.parquet.hadoop.util.HadoopInputFile; +import org.apache.parquet.hadoop.util.TestFileBuilder; +import org.apache.parquet.io.InputFile; +import org.apache.parquet.schema.MessageType; +import org.apache.parquet.schema.Types; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +public class TestParquetRewriterBloomFilterPaths { + + private final Configuration conf = new Configuration(); + + @ParameterizedTest(name = "transcode = {0}") + @ValueSource(booleans = {false, true}) + public void testRewritePreservesBloomFiltersForCollidingDotStringPaths(boolean transcode) throws Exception { + Path inputPath = writeBloomFilterPathCollisionFile(); + String outputFile = TestFileBuilder.createTempFile("test"); + + RewriteOptions.Builder builder = new RewriteOptions.Builder(conf, List.of(inputPath), new Path(outputFile)); + if (transcode) { + builder.transform(CompressionCodecName.GZIP); + } + + ParquetRewriter rewriter = new ParquetRewriter(builder.build()); + rewriter.processBlocks(); + rewriter.close(); + + // A codec change rewrites pages through processChunk; leaving the codec unchanged copies chunks + // through appendColumnChunk. Both branches must retain component boundaries even though the two + // columns below have the same dot-separated display name. + Map> inputBloomFilters = allBloomFilters(inputPath.toString()); + Map> outputBloomFilters = allBloomFilters(outputFile); + assertThat(outputBloomFilters).containsOnlyKeys(ColumnPath.get("a.b"), ColumnPath.get("a", "b")); + assertThat(outputBloomFilters).isEqualTo(inputBloomFilters); + } + + private Path writeBloomFilterPathCollisionFile() throws IOException { + MessageType schema = Types.buildMessage() + .required(BINARY) + .as(stringType()) + .named("a.b") + .requiredGroup() + .required(BINARY) + .as(stringType()) + .named("b") + .named("a") + .named("msg"); + GroupWriteSupport.setSchema(schema, conf); + GroupFactory factory = new SimpleGroupFactory(schema); + Path inputPath = new Path(TestFileBuilder.createTempFile("bloom-filter-path-collision")); + + try (ParquetWriter writer = ExampleParquetWriter.builder(inputPath) + .withConf(conf) + .withCompressionCodec(CompressionCodecName.UNCOMPRESSED) + .withDictionaryEncoding(false) + .withBloomFilterEnabled(true) + .build()) { + for (int i = 0; i < 100; i++) { + Group group = factory.newGroup().append("a.b", "top-" + i); + group.addGroup("a").append("b", "nested-" + i); + writer.write(group); + } + } + return inputPath; + } + + private Map> allBloomFilters(String path) throws Exception { + Map> allBloomFilters = new HashMap<>(); + ParquetReadOptions readOptions = ParquetReadOptions.builder().build(); + InputFile inputFile = HadoopInputFile.fromPath(new Path(path), conf); + try (TransParquetFileReader reader = new TransParquetFileReader(inputFile, readOptions)) { + ParquetMetadata metadata = reader.getFooter(); + for (BlockMetaData blockMetaData : metadata.getBlocks()) { + for (ColumnChunkMetaData columnChunkMetaData : blockMetaData.getColumns()) { + BloomFilter bloomFilter = reader.readBloomFilter(columnChunkMetaData); + if (bloomFilter != null) { + allBloomFilters + .computeIfAbsent(columnChunkMetaData.getPath(), k -> new ArrayList<>()) + .add(bloomFilter); + } + } + } + } + return allBloomFilters; + } +}