-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fast-avro][deserializer] Populate methods always with 'customization…
…' argument (#557) * 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). TDD approach - this commit adds unit test which fails and shows where the issue actually is. * [fast-avro] 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.
- Loading branch information
1 parent
49a61e2
commit b0fc4f9
Showing
7 changed files
with
248 additions
and
11 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
fastserde/avro-fastserde-tests-common/src/test/avro/recordWith2Fields.avsc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"type": "record", | ||
"name": "RecordWithOneNullableText", | ||
"namespace": "com.linkedin.avro.fastserde.generated.avro", | ||
"doc": "Used in tests of fast-serde to verify populate-methods works correctly with DatumReaderCustomization.", | ||
"fields": [ | ||
{ | ||
"name": "text", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null, | ||
"doc": "Corresponds with recordWith2FieldsAndDeeplyNestedRecord.avsc" | ||
} | ||
] | ||
} |
60 changes: 60 additions & 0 deletions
60
...rde/avro-fastserde-tests-common/src/test/avro/recordWith2FieldsAndDeeplyNestedRecord.avsc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"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.", | ||
"fields": [ | ||
{ | ||
"name": "text", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null, | ||
"doc": "Corresponds with recordWith2Fields.avsc" | ||
}, | ||
{ | ||
"name": "nestedField", | ||
"type": [ | ||
"null", | ||
{ | ||
"name": "NestedRecord", | ||
"type": "record", | ||
"fields": [ | ||
{ | ||
"name": "sampleText1", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null, | ||
"doc": "field just to make crowd and force FastDeserializerGenerator to create populate*() method" | ||
}, | ||
{ | ||
"name": "deeplyNestedField", | ||
"type": [ | ||
"null", | ||
{ | ||
"name": "DeeplyNestedRecord", | ||
"type": "record", | ||
"fields": [ | ||
{ | ||
"name": "deeplyDeeplyNestedText", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
} | ||
] | ||
} | ||
], | ||
"doc": "One more level of nested-records is needed to generate deserialize*() method called by populate*() method" | ||
} | ||
] | ||
} | ||
], | ||
"default": null | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...ation/AVRO_1_11/RecordWithOneNullableText_SpecificDeserializer_2111230429_1009500237.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_2111230429_1009500237 | ||
implements FastDeserializer<RecordWithOneNullableText> | ||
{ | ||
|
||
private final Schema readerSchema; | ||
|
||
public RecordWithOneNullableText_SpecificDeserializer_2111230429_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)); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters