From f0e2368f333accd2e8f4e2fb685e4872e3706c49 Mon Sep 17 00:00:00 2001 From: Krisso Date: Tue, 30 Apr 2024 00:25:23 +0200 Subject: [PATCH] Populate methods now always have 'customization' parameter because deserialize-method(s) of nested records may generate another populate methods that require 'customization' (at least for compilation). This commits contains the fix. --- ...FastSpecificDeserializerGeneratorTest.java | 2 - ...ericDeserializer_1090641932_438987109.java | 4 +- ...ricDeserializer_1932590611_1452595291.java | 4 +- ...ficDeserializer_1753906665_1009500237.java | 120 ++++++++++++++++++ .../fastserde/FastDeserializerGenerator.java | 5 +- 5 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/RecordWithOneNullableText_SpecificDeserializer_1753906665_1009500237.java diff --git a/fastserde/avro-fastserde-tests-common/src/test/java/com/linkedin/avro/fastserde/FastSpecificDeserializerGeneratorTest.java b/fastserde/avro-fastserde-tests-common/src/test/java/com/linkedin/avro/fastserde/FastSpecificDeserializerGeneratorTest.java index fbe3eeb92..26baa8787 100644 --- a/fastserde/avro-fastserde-tests-common/src/test/java/com/linkedin/avro/fastserde/FastSpecificDeserializerGeneratorTest.java +++ b/fastserde/avro-fastserde-tests-common/src/test/java/com/linkedin/avro/fastserde/FastSpecificDeserializerGeneratorTest.java @@ -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; @@ -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 diff --git a/fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/FastGenericDeserializerGeneratorTest_shouldSkipRemovedNestedRecord_GenericDeserializer_1090641932_438987109.java b/fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/FastGenericDeserializerGeneratorTest_shouldSkipRemovedNestedRecord_GenericDeserializer_1090641932_438987109.java index 569f8b259..4fa77763b 100644 --- a/fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/FastGenericDeserializerGeneratorTest_shouldSkipRemovedNestedRecord_GenericDeserializer_1090641932_438987109.java +++ b/fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/FastGenericDeserializerGeneratorTest_shouldSkipRemovedNestedRecord_GenericDeserializer_1090641932_438987109.java @@ -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(); diff --git a/fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/FastGenericDeserializerGeneratorTest_shouldSkipRemovedRecord_GenericDeserializer_1932590611_1452595291.java b/fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/FastGenericDeserializerGeneratorTest_shouldSkipRemovedRecord_GenericDeserializer_1932590611_1452595291.java index c45bcfd33..abe582512 100644 --- a/fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/FastGenericDeserializerGeneratorTest_shouldSkipRemovedRecord_GenericDeserializer_1932590611_1452595291.java +++ b/fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/FastGenericDeserializerGeneratorTest_shouldSkipRemovedRecord_GenericDeserializer_1932590611_1452595291.java @@ -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(); diff --git a/fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/RecordWithOneNullableText_SpecificDeserializer_1753906665_1009500237.java b/fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/RecordWithOneNullableText_SpecificDeserializer_1753906665_1009500237.java new file mode 100644 index 000000000..7f959624c --- /dev/null +++ b/fastserde/avro-fastserde-tests111/build/codegen/java/com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_11/RecordWithOneNullableText_SpecificDeserializer_1753906665_1009500237.java @@ -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 +{ + + 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)); + } + } + } + +} diff --git a/fastserde/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastDeserializerGenerator.java b/fastserde/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastDeserializerGenerator.java index 941add56a..5b2059792 100644 --- a/fastserde/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastDeserializerGenerator.java +++ b/fastserde/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastDeserializerGenerator.java @@ -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);