clesaec commented on code in PR #1776:
URL: https://github.com/apache/avro/pull/1776#discussion_r927632833
##########
lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java:
##########
@@ -234,8 +234,16 @@ protected Object convert(Object datum, Schema schema,
LogicalType type, Conversi
* representations.
*/
protected Object readRecord(Object old, Schema expected, ResolvingDecoder
in) throws IOException {
- final Object record = data.newRecord(old, expected);
- final Object state = data.getRecordState(record, expected);
+ final Schema realSchema;
+ if (expected.hasChild()) {
+ int index = in.readExtends();
+ realSchema = expected.findInHierachy(index);
+ } else {
+ realSchema = expected;
+ }
Review Comment:
You were right, so now writer will always write the "extends" symbol if
schema has child.
##########
lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumWriter.java:
##########
@@ -229,8 +230,17 @@ protected AvroTypeException
addAvroTypeMsg(AvroTypeException e, String s) {
* representations.
*/
protected void writeRecord(Schema schema, Object datum, Encoder out) throws
IOException {
- Object state = data.getRecordState(datum, schema);
- for (Field f : schema.getFields()) {
+ final Schema realSchema;
+ if (datum instanceof GenericRecord && schema.hasChild()) {
+ realSchema = ((GenericRecord) datum).getSchema();
+ } else {
+ realSchema = schema;
+ }
+ if (!Objects.equals(realSchema, schema)) {
+ out.writeExtends(realSchema.getIndex());
+ }
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]