Skip to content

Commit

Permalink
[fast-avro] Populate methods now always have 'customization' parameter
Browse files Browse the repository at this point in the history
because 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 May 6, 2024
1 parent 8ee90fe commit ff2c378
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "record",
"name": "RecordWithOneNullableTextAndDeeplyNestedRecord",
"namespace": "com.linkedin.avro.fastserde.generated.avro",
"doc": "Used in tests of fast-serde to verify populate-methods works correctly with DatumReaderCustomization. Just like OuterRecordWith2NestedBetaRecords but with one field more.",
"doc": "Used in tests of fast-serde to verify populate-methods works correctly with DatumReaderCustomization.",
"fields": [
{
"name": "text",
Expand Down Expand Up @@ -48,7 +48,8 @@
}
]
}
]
],
"doc": "One more level of nested-records is needed to generate deserialize*() method called by populate*() method"
}
]
}
Expand Down
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 @@ -904,20 +903,11 @@ void deserializeWithSchemaMissingDeeplyNestedRecord() throws IOException {

// when (serialized reach record is read with schema without 'nestedField')
BinaryDecoder decoder = AvroCompatibilityHelper.newBinaryDecoder(serializedReachRecord);
/*- Below is commented out due to fast-serde compilation error:
avro-util/fastserde/avro-fastserde-tests111/./build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/RecordWithOneNullableText_SpecificDeserializer_1753906665_1009500237.java:98: error: cannot find symbol
deserializeDeeplyNestedRecord0(null, (decoder), (customization));
^
symbol: variable customization
location: class RecordWithOneNullableText_SpecificDeserializer_1753906665_1009500237
RecordWithOneNullableText liteRecord = decodeRecordFast(readerSchema, writerSchema, decoder);

// then (fast-serde compilation and deserialization succeeds)
Assert.assertNotNull(liteRecord);
Assert.assertEquals(getField(liteRecord, "text").toString(), "I am from reach record");
*/
}

/**
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
Expand Up @@ -9,13 +9,13 @@
import org.apache.avro.io.Decoder;
import org.apache.avro.util.Utf8;

public class RecordWithOneNullableText_SpecificDeserializer_1753906665_1009500237
public class RecordWithOneNullableText_SpecificDeserializer_2111230429_1009500237
implements FastDeserializer<RecordWithOneNullableText>
{

private final Schema readerSchema;

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

Expand Down Expand Up @@ -84,10 +84,10 @@ public void deserializeNestedRecord0(Object reuse, Decoder decoder, DatumReaderC
throw new RuntimeException(("Illegal union index for 'sampleText1': "+ unionIndex2));
}
}
populate_NestedRecord0((decoder));
populate_NestedRecord0((customization), (decoder));
}

private void populate_NestedRecord0(Decoder decoder)
private void populate_NestedRecord0(DatumReaderCustomization customization, Decoder decoder)
throws IOException
{
int unionIndex3 = (decoder.readIndex());
Expand Down
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 ff2c378

Please sign in to comment.