nbalajee commented on a change in pull request #2309:
URL: https://github.com/apache/hudi/pull/2309#discussion_r549443776
##########
File path:
hudi-common/src/test/java/org/apache/hudi/avro/TestHoodieAvroUtils.java
##########
@@ -207,4 +208,82 @@ public void testAddingAndRemovingMetadataFields() {
Schema schemaWithoutMetaCols =
HoodieAvroUtils.removeMetadataFields(schemaWithMetaCols);
assertEquals(schemaWithoutMetaCols.getFields().size(),
NUM_FIELDS_IN_EXAMPLE_SCHEMA);
}
+
+ @Test
+ public void testRewriteToEvolvedNestedRecord() throws Exception {
+ // schema definition for inner record
+ Schema nestedSchema =
SchemaBuilder.record("inner_rec").fields().requiredDouble("color_id").endRecord();
+ Schema evolvedNestedSchema =
SchemaBuilder.record("inner_rec").fields().requiredDouble("color_id")
+ .optionalString("color_name").endRecord();
+
+ // schema definition for outer record
+ Schema recordSchema =
SchemaBuilder.record("outer_rec").fields().requiredDouble("timestamp")
+
.requiredString("_row_key").requiredString("non_pii_col").name("color_rec").type(nestedSchema)
+ .noDefault().requiredString("pii_col").endRecord();
+ Schema evolvedRecordSchema =
SchemaBuilder.record("outer_rec").fields().requiredDouble("timestamp")
+
.requiredString("_row_key").requiredString("non_pii_col").name("color_rec").type(evolvedNestedSchema)
+ .noDefault().requiredString("pii_col").endRecord();
+
+ // populate inner record, with fewer fields
+ GenericRecord nestedRec = new GenericData.Record(nestedSchema);
+ nestedRec.put("color_id", 55.5);
+
+ // populate outer record
+ GenericRecord rec = new GenericData.Record(recordSchema);
+ rec.put("timestamp", 3.5);
+ rec.put("_row_key", "key1");
+ rec.put("non_pii_col", "val1");
+ rec.put("color_rec", nestedRec);
+ rec.put("pii_col", "val2");
+
+ // rewrite record with less number of fields into an evolved record (with
optional fields added).
+ try {
+ GenericRecord newRecord =
HoodieAvroUtils.rewriteRecordWithOnlyNewSchemaFields(rec, evolvedRecordSchema);
+ assertEquals(newRecord.get("pii_col"), "val2");
+
assertEquals(((GenericRecord)newRecord.get("color_rec")).get("color_name"),
null);
Review comment:
Swapped the parameters to fix assertEquals.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]