davidradl commented on code in PR #28115:
URL: https://github.com/apache/flink/pull/28115#discussion_r3428100658


##########
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/RegistryWriterAvroDeserializationSchema.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.flink.formats.avro;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.formats.avro.utils.MutableByteArrayInputStream;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericDatumReader;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.io.BinaryDecoder;
+import org.apache.avro.io.DecoderFactory;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.Objects;
+
+/**
+ * Deserialization schema that deserializes from Avro binary format using a 
{@link SchemaCoder} to
+ * resolve the writer schema dynamically per record. Unlike {@link
+ * RegistryAvroDeserializationSchema} which projects records into a fixed 
reader schema, this class
+ * uses the writer schema as both reader and writer — preserving all fields 
as-is.
+ *
+ * <p>Designed for use cases where the Avro schema is not known at table 
creation time and varies
+ * per record.
+ */
+public class RegistryWriterAvroDeserializationSchema
+        implements DeserializationSchema<GenericRecord> {
+
+    private static final long serialVersionUID = 1L;
+
+    private final SchemaCoder.SchemaCoderProvider schemaCoderProvider;
+
+    private transient SchemaCoder schemaCoder;
+    private transient MutableByteArrayInputStream inputStream;
+    private transient BinaryDecoder decoder;
+    private transient GenericDatumReader<GenericRecord> datumReader;
+
+    public RegistryWriterAvroDeserializationSchema(
+            SchemaCoder.SchemaCoderProvider schemaCoderProvider) {
+        this.schemaCoderProvider = Objects.requireNonNull(schemaCoderProvider);
+    }
+
+    @Override
+    public void open(InitializationContext context) throws Exception {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        GenericData genericData = new GenericData(cl);
+        this.datumReader = new GenericDatumReader<>(null, null, genericData);

Review Comment:
   I am curious, if open is called twice on the same or different threads on 
this object, then these transient variables would be overwritten.  



-- 
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]

Reply via email to