Skip to content

Commit

Permalink
[fast-avro][bugfix] Delegating setSchema() call to coldDeserializer f…
Browse files Browse the repository at this point in the history
…rom FastGenericDatumReader.

It's needed to deserialize 1st record(s) from file using DataFileStream.
  • Loading branch information
krisso-rtb committed Jan 18, 2024
1 parent 1af1995 commit 3261c32
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.linkedin.avro.fastserde.customized.DatumReaderCustomization;
import java.io.IOException;

import org.apache.avro.Schema;
import org.apache.avro.io.Decoder;

import static com.linkedin.avro.fastserde.customized.DatumReaderCustomization.*;
Expand All @@ -17,5 +19,15 @@ default T deserialize(T reuse, Decoder d) throws IOException {
return deserialize(reuse, d, DEFAULT_DATUM_READER_CUSTOMIZATION);
}

/**
* Set the writer's schema.
* @see org.apache.avro.io.DatumReader#setSchema(Schema)
*/
default void setSchema(Schema writerSchema) {
// Implement this method only in vanilla-avro-based classes (e.g. fallback scenario).
// Normally for generated deserializers it doesn't make sense.
throw new UnsupportedOperationException("Can't change schema for already generated class.");
}

T deserialize(T reuse, Decoder d, DatumReaderCustomization customization) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public void setSchema(Schema schema) {
if (readerSchema == null) {
readerSchema = writerSchema;
}

coldDeserializer.setSchema(schema);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public FastDeserializerWithAvroSpecificImpl(Schema writerSchema, Schema readerSc
this.runtimeClassGenerationDone = runtimeClassGenerationDone;
}

@Override
public void setSchema(Schema writerSchema) {
this.customizedDatumReader.setSchema(writerSchema);
}

@Override
public V deserialize(V reuse, Decoder d, DatumReaderCustomization customization) throws IOException {
if (failFast) {
Expand Down Expand Up @@ -103,6 +108,11 @@ public FastDeserializerWithAvroGenericImpl(Schema writerSchema, Schema readerSch
this.runtimeClassGenerationDone = runtimeClassGenerationDone;
}

@Override
public void setSchema(Schema writerSchema) {
customizedDatumReader.setSchema(writerSchema);
}

@Override
public V deserialize(V reuse, Decoder d, DatumReaderCustomization customization) throws IOException {
if (failFast) {
Expand Down

0 comments on commit 3261c32

Please sign in to comment.