steveniemitz commented on code in PR #22718:
URL: https://github.com/apache/beam/pull/22718#discussion_r984824334
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.java:
##########
@@ -573,6 +577,60 @@ public static TypedRead<TableRow>
readTableRowsWithSchema() {
BigQueryUtils.tableRowFromBeamRow());
}
+ @VisibleForTesting
+ static class GenericDatumTransformer<T> implements DatumReader<T> {
+ private final SerializableFunction<SchemaAndRecord, T> parseFn;
+ private final TableSchema tableSchema;
+ private final GenericDatumReader<T> reader;
+ private org.apache.avro.Schema writerSchema;
+
+ public GenericDatumTransformer(
+ SerializableFunction<SchemaAndRecord, T> parseFn,
+ TableSchema tableSchema,
+ org.apache.avro.Schema writer,
+ org.apache.avro.Schema reader) {
+ this.parseFn = parseFn;
+ this.tableSchema = tableSchema;
+ this.setSchema(writer);
+ this.reader = new GenericDatumReader<>(this.writerSchema, reader);
+ }
+
+ @Override
+ public void setSchema(org.apache.avro.Schema schema) {
+ this.writerSchema = schema;
+ }
+
+ @Override
+ public T read(T reuse, Decoder in) throws IOException {
+ GenericRecord record = (GenericRecord) this.reader.read(reuse, in);
+ return parseFn.apply(new SchemaAndRecord(record, tableSchema));
+ }
+ }
+
+ @VisibleForTesting
+ private static class DatumReaderWrapper<T> implements DatumReader<T> {
+ private final DatumReader<T> reader;
+ private org.apache.avro.Schema writerSchema;
+
+ public DatumReaderWrapper(
+ org.apache.avro.Schema writerSchema,
+ org.apache.avro.Schema readerSchema,
+ AvroSource.DatumReaderFactory<T> factory) {
+ this.setSchema(writerSchema);
+ this.reader = factory.apply(this.writerSchema, readerSchema);
+ }
+
+ @Override
+ public void setSchema(org.apache.avro.Schema schema) {
+ this.writerSchema = schema;
Review Comment:
this should recreate the reader also, otherwise the schema change doesn't do
anything.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]