Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't re-use ReflectData in AvroCoder #4951

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.spotify.scio.util.ScioUtil
import org.apache.avro.Schema
import org.apache.avro.generic.GenericRecord
import org.apache.avro.io.{DatumReader, DatumWriter}
import org.apache.avro.reflect.{ReflectDatumReader, ReflectDatumWriter}
import org.apache.avro.reflect.{ReflectData, ReflectDatumReader, ReflectDatumWriter}
import org.apache.avro.specific.{SpecificData, SpecificFixed, SpecificRecord}
import org.apache.beam.sdk.coders.Coder.NonDeterministicException
import org.apache.beam.sdk.coders.{AtomicCoder, CustomCoder, StringUtf8Coder}
Expand Down Expand Up @@ -153,7 +153,8 @@ trait AvroCoders {
override def apply(writer: Schema, reader: Schema): DatumReader[T] = {
// create the datum writer using the schema api
// class API might be unsafe. See schemaForClass
val datumReader = new ReflectDatumReader[T](schemaForClass(clazz).get);
val schema = schemaForClass(clazz).get
val datumReader = new ReflectDatumReader[T](schema, schema, new ReflectData())
clairemcginty marked this conversation as resolved.
Show resolved Hide resolved
datumReader.setExpected(reader)
datumReader.setSchema(writer)
// for backward compat, add logical type support by default
Expand All @@ -164,7 +165,7 @@ trait AvroCoders {
override def apply(writer: Schema): DatumWriter[T] = {
// create the datum writer using the schema api
// class API might be unsafe. See schemaForClass
val datumWriter = new ReflectDatumWriter[T](schemaForClass(clazz).get)
val datumWriter = new ReflectDatumWriter[T](schemaForClass(clazz).get, new ReflectData())
clairemcginty marked this conversation as resolved.
Show resolved Hide resolved
datumWriter.setSchema(writer)
// for backward compat, add logical type support by default
AvroUtils.addLogicalTypeConversions(datumWriter.getData)
Expand Down