aromanenko-dev commented on a change in pull request #14644:
URL: https://github.com/apache/beam/pull/14644#discussion_r621316454
##########
File path:
sdks/java/io/parquet/src/main/java/org/apache/beam/sdk/io/parquet/ParquetIO.java
##########
@@ -1166,6 +1168,8 @@ public static Sink sink(Schema schema) {
abstract Builder setRowGroupSize(int rowGroupSize);
+ abstract Builder setAvroDataModel(Class<? extends GenericData>
modelClass);
Review comment:
The similar question - can we just pass `GenericData` here because of
`withAvroDataModel(GenericData)`?
##########
File path:
sdks/java/io/parquet/src/test/java/org/apache/beam/sdk/io/parquet/ParquetIOTest.java
##########
@@ -506,6 +506,53 @@ public void
testWriteAndReadwithSplitUsingReflectDataSchemaWithDataModel() {
readPipeline.run().waitUntilFinish();
}
+ @Test
+ public void testWriteAndReadUsingGenericDataSchemaWithDataModel() {
+ Schema schema = new Schema.Parser().parse(SCHEMA_STRING);
+
+ List<GenericRecord> records = generateGenericRecords(1000);
+ mainPipeline
+ .apply(Create.of(records).withCoder(AvroCoder.of(schema)))
+ .apply(
+ FileIO.<GenericRecord>write()
+
.via(ParquetIO.sink(schema).withAvroDataModel(GenericData.get()))
+ .to(temporaryFolder.getRoot().getAbsolutePath()));
+ mainPipeline.run().waitUntilFinish();
+
+ PCollection<GenericRecord> readBack =
+ readPipeline.apply(
+ ParquetIO.read(schema)
+ .withAvroDataModel(GenericData.get())
+ .from(temporaryFolder.getRoot().getAbsolutePath() + "/*"));
+
+ PAssert.that(readBack).containsInAnyOrder(records);
+ readPipeline.run().waitUntilFinish();
+ }
+
+ @Test
+ public void testWriteAndReadwithSplitUsingGenericDataSchemaWithDataModel() {
Review comment:
Can we expect a different behaviour using `.withSplit()`? If not then
probably one of the tests is unneeded.
##########
File path:
sdks/java/io/parquet/src/main/java/org/apache/beam/sdk/io/parquet/ParquetIO.java
##########
@@ -1210,6 +1221,13 @@ public void open(WritableByteChannel channel) throws
IOException {
.withWriteMode(OVERWRITE)
.withConf(SerializableConfiguration.newConfiguration(getConfiguration()))
.withRowGroupSize(getRowGroupSize());
+ if (getAvroDataModel() != null) {
+ try {
+ builder.withDataModel(buildModelObject(getAvroDataModel()));
+ } catch (ReflectiveOperationException e) {
+ LOG.warn("Couldn't set the model: " + e.getMessage());
Review comment:
Don't we need to fail a pipeline here?
##########
File path:
sdks/java/io/parquet/src/main/java/org/apache/beam/sdk/io/parquet/ParquetIO.java
##########
@@ -1154,6 +1154,8 @@ public static Sink sink(Schema schema) {
abstract int getRowGroupSize();
+ abstract @Nullable Class<? extends GenericData> getAvroDataModel();
Review comment:
Can we just return `GenericData` here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]