Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 47 additions & 101 deletions parquet-avro/src/test/java/org/apache/parquet/avro/TestReadWrite.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -190,20 +195,24 @@ static Stream<Arguments> 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);
Expand All @@ -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());

Expand All @@ -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());

Expand All @@ -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());

Expand Down Expand Up @@ -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)));
Expand All @@ -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());

Expand All @@ -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)));
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -847,12 +817,8 @@ public void write(Map<String, Object> 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)));
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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));
Expand Down
Loading