Skip to content

Commit

Permalink
Populate methods now always have 'customization' parameter because
Browse files Browse the repository at this point in the history
deserialize-method(s) of nested records may generate another
populate methods that require 'customization' (at least for compilation).

This commits contains the fix.
  • Loading branch information
krisso-rtb committed Apr 30, 2024
1 parent 96cd780 commit f0e2368
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;
import org.testng.collections.Lists;
import org.testng.internal.collections.Pair;
Expand Down Expand Up @@ -882,7 +881,6 @@ void deserializeNullableFieldsPreviouslySerializedAsNotNull(boolean useFastSeria
Assert.assertEquals(outerRecord2.toString(), outerRecord1.toString());
}

@Ignore
@Test(groups = {"deserializationTest"})
void deserializeWithSchemaMissingDeeplyNestedRecord() throws IOException {
// duplicates prepare() just in case - .avsc files used here assume FIELDS_PER_POPULATION_METHOD is 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public void deserializesubSubRecord0(Object reuse, Decoder decoder, DatumReaderC
throws IOException
{
decoder.skipString();
populate_subSubRecord0((decoder));
populate_subSubRecord0((customization), (decoder));
}

private void populate_subSubRecord0(Decoder decoder)
private void populate_subSubRecord0(DatumReaderCustomization customization, Decoder decoder)
throws IOException
{
decoder.skipString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ public void deserializesubRecord20(Object reuse, Decoder decoder, DatumReaderCus
throws IOException
{
decoder.skipString();
populate_subRecord20((decoder));
populate_subRecord20((customization), (decoder));
}

private void populate_subRecord20(Decoder decoder)
private void populate_subRecord20(DatumReaderCustomization customization, Decoder decoder)
throws IOException
{
decoder.skipString();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@

package com.linkedin.avro.fastserde.generated.deserialization.AVRO_1_11;

import java.io.IOException;
import com.linkedin.avro.fastserde.FastDeserializer;
import com.linkedin.avro.fastserde.customized.DatumReaderCustomization;
import com.linkedin.avro.fastserde.generated.avro.RecordWithOneNullableText;
import org.apache.avro.Schema;
import org.apache.avro.io.Decoder;
import org.apache.avro.util.Utf8;

public class RecordWithOneNullableText_SpecificDeserializer_1753906665_1009500237
implements FastDeserializer<RecordWithOneNullableText>
{

private final Schema readerSchema;

public RecordWithOneNullableText_SpecificDeserializer_1753906665_1009500237(Schema readerSchema) {
this.readerSchema = readerSchema;
}

public RecordWithOneNullableText deserialize(RecordWithOneNullableText reuse, Decoder decoder, DatumReaderCustomization customization)
throws IOException
{
return deserializeRecordWithOneNullableText0((reuse), (decoder), (customization));
}

public RecordWithOneNullableText deserializeRecordWithOneNullableText0(Object reuse, Decoder decoder, DatumReaderCustomization customization)
throws IOException
{
RecordWithOneNullableText RecordWithOneNullableTextAndDeeplyNestedRecord;
if ((reuse)!= null) {
RecordWithOneNullableTextAndDeeplyNestedRecord = ((RecordWithOneNullableText)(reuse));
} else {
RecordWithOneNullableTextAndDeeplyNestedRecord = new RecordWithOneNullableText();
}
int unionIndex0 = (decoder.readIndex());
if (unionIndex0 == 0) {
decoder.readNull();
RecordWithOneNullableTextAndDeeplyNestedRecord.put(0, null);
} else {
if (unionIndex0 == 1) {
Utf8 charSequence0;
Object oldString0 = RecordWithOneNullableTextAndDeeplyNestedRecord.get(0);
if (oldString0 instanceof Utf8) {
charSequence0 = (decoder).readString(((Utf8) oldString0));
} else {
charSequence0 = (decoder).readString(null);
}
RecordWithOneNullableTextAndDeeplyNestedRecord.put(0, charSequence0);
} else {
throw new RuntimeException(("Illegal union index for 'text': "+ unionIndex0));
}
}
populate_RecordWithOneNullableTextAndDeeplyNestedRecord0((RecordWithOneNullableTextAndDeeplyNestedRecord), (customization), (decoder));
return RecordWithOneNullableTextAndDeeplyNestedRecord;
}

private void populate_RecordWithOneNullableTextAndDeeplyNestedRecord0(RecordWithOneNullableText RecordWithOneNullableTextAndDeeplyNestedRecord, DatumReaderCustomization customization, Decoder decoder)
throws IOException
{
int unionIndex1 = (decoder.readIndex());
if (unionIndex1 == 0) {
decoder.readNull();
} else {
if (unionIndex1 == 1) {
deserializeNestedRecord0(null, (decoder), (customization));
} else {
throw new RuntimeException(("Illegal union index for 'nestedField': "+ unionIndex1));
}
}
}

public void deserializeNestedRecord0(Object reuse, Decoder decoder, DatumReaderCustomization customization)
throws IOException
{
int unionIndex2 = (decoder.readIndex());
if (unionIndex2 == 0) {
decoder.readNull();
} else {
if (unionIndex2 == 1) {
decoder.skipString();
} else {
throw new RuntimeException(("Illegal union index for 'sampleText1': "+ unionIndex2));
}
}
populate_NestedRecord0((customization), (decoder));
}

private void populate_NestedRecord0(DatumReaderCustomization customization, Decoder decoder)
throws IOException
{
int unionIndex3 = (decoder.readIndex());
if (unionIndex3 == 0) {
decoder.readNull();
} else {
if (unionIndex3 == 1) {
deserializeDeeplyNestedRecord0(null, (decoder), (customization));
} else {
throw new RuntimeException(("Illegal union index for 'deeplyNestedField': "+ unionIndex3));
}
}
}

public void deserializeDeeplyNestedRecord0(Object reuse, Decoder decoder, DatumReaderCustomization customization)
throws IOException
{
int unionIndex4 = (decoder.readIndex());
if (unionIndex4 == 0) {
decoder.readNull();
} else {
if (unionIndex4 == 1) {
decoder.skipString();
} else {
throw new RuntimeException(("Illegal union index for 'deeplyDeeplyNestedText': "+ unionIndex4));
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,17 @@ private void processRecord(JVar recordSchemaVar, String recordName, final Schema
popMethod._throws(IOException.class);
if (recordAction.getShouldRead()) {
popMethod.param(recordClass, recordName);
popMethod.param(codeModel.ref(DatumReaderCustomization.class), VAR_NAME_FOR_CUSTOMIZATION);
}
popMethod.param(codeModel.ref(DatumReaderCustomization.class), VAR_NAME_FOR_CUSTOMIZATION);
popMethod.param(Decoder.class, DECODER);
popMethodBody = popMethod.body();

JInvocation invocation = methodBody.invoke(popMethod);
if (recordAction.getShouldRead()) {
invocation.arg(JExpr.direct(recordName));
invocation.arg(customizationSupplier.get());
}
// even if recordAction.getShouldRead() == false we need to generate 'customization' argument for javac purposes
invocation.arg(customizationSupplier.get());
invocation.arg(JExpr.direct(DECODER));
}
FieldAction action = seekFieldAction(recordAction.getShouldRead(), field, actionIterator);
Expand Down

0 comments on commit f0e2368

Please sign in to comment.