Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nisargthakkar committed Dec 6, 2024
1 parent bf8ed8e commit 60afc7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class FastDeserializerGeneratorTest {
@Test
public void testSchemaForFixedField() throws IOException, InterruptedException {
public void testDeserializationOfFixedField() throws IOException, InterruptedException {
if (Utils.isAvro14()) {
throw new SkipException("Avro 1.4 doesn't have schemas for GenericFixed type");
}
Expand All @@ -27,7 +27,9 @@ public void testSchemaForFixedField() throws IOException, InterruptedException {
Schema readerSchema = AvroCompatibilityHelper.parse("{\"type\":\"record\",\"name\":\"topLevelRecord\",\"fields\":[{\"name\":\"fixedField\",\"type\":{\"type\":\"fixed\",\"name\":\"FixedType\",\"size\":5,\"newField\": \"New field to change something\"}}]}");

GenericRecord writtenRecord = new GenericData.Record(writerSchema);
writtenRecord.put("fixedField", AvroCompatibilityHelper.newFixed(writerSchema.getField("fixedField").schema(), new byte[]{1,2,3,4,5}));

byte[] writtenFixedFieldData = new byte[]{1,2,3,4,5};
writtenRecord.put("fixedField", AvroCompatibilityHelper.newFixed(writerSchema.getField("fixedField").schema(), writtenFixedFieldData));

byte[] writeBytes = serialize(writtenRecord);

Expand All @@ -42,6 +44,7 @@ public void testSchemaForFixedField() throws IOException, InterruptedException {

Schema fixedFieldSchema = AvroSchemaUtil.getDeclaredSchema(fixedField);
Assert.assertNotNull(fixedFieldSchema, "Schema for field must always be set.");
Assert.assertEquals(((GenericFixed)((GenericData.Record) data).get("fixedField")).bytes(), writtenFixedFieldData);
}

private byte[] serialize(GenericRecord record) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,24 @@ private void processSimpleType(Schema schema, Schema readerSchema, JBlock method
processEnum(readerSchema, methodBody, action, putExpressionIntoParent);
break;
case FIXED:
// to preserve reader fixed specific options use reader field schema
final Schema fixedFieldSchema;
if (action.getShouldRead() && readerSchema != null && Schema.Type.FIXED.equals(readerSchema.getType())) {
processFixed(readerSchema, methodBody, action, putExpressionIntoParent, reuseSupplier);
// to preserve reader-specific options use reader field schema
fixedFieldSchema = readerSchema;
} else {
processFixed(schema, methodBody, action, putExpressionIntoParent, reuseSupplier);
fixedFieldSchema = schema;
}
processFixed(fixedFieldSchema, methodBody, action, putExpressionIntoParent, reuseSupplier);
break;
default:
// to preserve reader string specific options use reader field schema
final Schema primitiveFieldSchema;
if (action.getShouldRead() && readerSchema != null && Schema.Type.STRING.equals(readerSchema.getType())) {
processPrimitive(readerSchema, methodBody, action, putExpressionIntoParent, reuseSupplier);
// to preserve reader-specific options use reader field schema
primitiveFieldSchema = readerSchema;
} else {
processPrimitive(schema, methodBody, action, putExpressionIntoParent, reuseSupplier);
primitiveFieldSchema = schema;
}
processPrimitive(primitiveFieldSchema, methodBody, action, putExpressionIntoParent, reuseSupplier);
break;
}
}
Expand Down

0 comments on commit 60afc7f

Please sign in to comment.