@Test public void testJsonNodeNullWithDefaultValues() { List<Schema.Field> fields = new ArrayList<>(); Schema initialSchema = Schema.createRecord("test_record", "test record", "org.test.namespace", false); Schema.Field field1 = new Schema.Field("key", HoodieAvroUtils.METADATA_FIELD_SCHEMA, "", JsonProperties.NULL_VALUE); Schema.Field field2 = new Schema.Field("key1", HoodieAvroUtils.METADATA_FIELD_SCHEMA, "", JsonProperties.NULL_VALUE); Schema.Field field3 = new Schema.Field("key2", HoodieAvroUtils.METADATA_FIELD_SCHEMA, "", JsonProperties.NULL_VALUE); fields.add(field1); fields.add(field2); fields.add(field3); initialSchema.setFields(fields); GenericRecord rec = new GenericData.Record(initialSchema); rec.put("key", "val"); rec.put("key1", "val1"); rec.put("key2", "val2"); List<Schema.Field> evolvedFields = new ArrayList<>(); Schema evolvedSchema = Schema.createRecord("evolved_record", "evolved record", "org.evolved.namespace", false); Schema.Field evolvedField1 = new Schema.Field("key", HoodieAvroUtils.METADATA_FIELD_SCHEMA, "", JsonProperties.NULL_VALUE); Schema.Field evolvedField2 = new Schema.Field("key1", HoodieAvroUtils.METADATA_FIELD_SCHEMA, "", JsonProperties.NULL_VALUE); Schema.Field evolvedField3 = new Schema.Field("key2", HoodieAvroUtils.METADATA_FIELD_SCHEMA, "", JsonProperties.NULL_VALUE); Schema.Field evolvedField4 = new Schema.Field("evolved_field", HoodieAvroUtils.METADATA_FIELD_SCHEMA, "", NullNode.getInstance()); Schema.Field evolvedField5 = new Schema.Field("evolved_field1", HoodieAvroUtils.METADATA_FIELD_SCHEMA, "", JsonProperties.NULL_VALUE); evolvedFields.add(evolvedField1); evolvedFields.add(evolvedField2); evolvedFields.add(evolvedField3); evolvedFields.add(evolvedField4); evolvedFields.add(evolvedField5); evolvedSchema.setFields(evolvedFields); GenericRecord rec1 = HoodieAvroUtils.rewriteRecord(rec, evolvedSchema); assertNull(rec1.get("evolved_field")); assertNull(rec1.get("evolved_field1")); }
public static GenericRecord rewriteRecord(GenericRecord record, Schema newSchema) { return rewrite(record, getCombinedFieldsToWrite(record.getSchema(), newSchema), newSchema); }
HoodieAvroUtils { public static GenericRecord rewriteRecord(GenericRecord record, Schema newSchema) { return rewrite(record, getCombinedFieldsToWrite(record.getSchema(), newSchema), newSchema); } }
HoodieAvroUtils { public static GenericRecord rewriteRecord(GenericRecord record, Schema newSchema) { return rewrite(record, getCombinedFieldsToWrite(record.getSchema(), newSchema), newSchema); }  }
HoodieAvroUtils { public static GenericRecord rewriteRecord(GenericRecord record, Schema newSchema) { return rewrite(record, getCombinedFieldsToWrite(record.getSchema(), newSchema), newSchema); }  static byte[] avroToBytes(GenericRecord record); static byte[] indexedRecordToBytes(T record); static byte[] avroToJson(GenericRecord record, boolean pretty); static GenericRecord bytesToAvro(byte[] bytes, Schema schema); static GenericRecord bytesToAvro(byte[] bytes, Schema writerSchema, Schema readerSchema); static GenericRecord jsonBytesToAvro(byte[] bytes, Schema schema); static boolean isMetadataField(String fieldName); static Schema createHoodieWriteSchema(Schema originalSchema); static Schema createHoodieWriteSchema(String originalSchema); static Schema addMetadataFields(Schema schema); static Schema removeMetadataFields(Schema schema); static String addMetadataColumnTypes(String hiveColumnTypes); static Schema getRecordKeySchema(); static Schema getRecordKeyPartitionPathSchema(); static GenericRecord addHoodieKeyToRecord(GenericRecord record, String recordKey, String partitionPath,
      String fileName); static Schema appendNullSchemaFields(Schema schema, List<String> newFieldNames); static GenericRecord addCommitMetadataToRecord(GenericRecord record, String instantTime, String commitSeqno); static GenericRecord stitchRecords(GenericRecord left, GenericRecord right, Schema stitchedSchema); static GenericRecord rewriteRecord(GenericRecord record, Schema newSchema); static GenericRecord rewriteRecordWithOnlyNewSchemaFields(GenericRecord record, Schema newSchema); static byte[] compress(String text); static String decompress(byte[] bytes); static Schema generateProjectionSchema(Schema originalSchema, List<String> fieldNames); static String getNestedFieldValAsString(GenericRecord record, String fieldName, boolean returnNullIfNotFound); static Object getNestedFieldVal(GenericRecord record, String fieldName, boolean returnNullIfNotFound); static Schema getNullSchema(); static String sanitizeName(String name); }
HoodieAvroUtils { public static GenericRecord rewriteRecord(GenericRecord record, Schema newSchema) { return rewrite(record, getCombinedFieldsToWrite(record.getSchema(), newSchema), newSchema); }  static byte[] avroToBytes(GenericRecord record); static byte[] indexedRecordToBytes(T record); static byte[] avroToJson(GenericRecord record, boolean pretty); static GenericRecord bytesToAvro(byte[] bytes, Schema schema); static GenericRecord bytesToAvro(byte[] bytes, Schema writerSchema, Schema readerSchema); static GenericRecord jsonBytesToAvro(byte[] bytes, Schema schema); static boolean isMetadataField(String fieldName); static Schema createHoodieWriteSchema(Schema originalSchema); static Schema createHoodieWriteSchema(String originalSchema); static Schema addMetadataFields(Schema schema); static Schema removeMetadataFields(Schema schema); static String addMetadataColumnTypes(String hiveColumnTypes); static Schema getRecordKeySchema(); static Schema getRecordKeyPartitionPathSchema(); static GenericRecord addHoodieKeyToRecord(GenericRecord record, String recordKey, String partitionPath,
      String fileName); static Schema appendNullSchemaFields(Schema schema, List<String> newFieldNames); static GenericRecord addCommitMetadataToRecord(GenericRecord record, String instantTime, String commitSeqno); static GenericRecord stitchRecords(GenericRecord left, GenericRecord right, Schema stitchedSchema); static GenericRecord rewriteRecord(GenericRecord record, Schema newSchema); static GenericRecord rewriteRecordWithOnlyNewSchemaFields(GenericRecord record, Schema newSchema); static byte[] compress(String text); static String decompress(byte[] bytes); static Schema generateProjectionSchema(Schema originalSchema, List<String> fieldNames); static String getNestedFieldValAsString(GenericRecord record, String fieldName, boolean returnNullIfNotFound); static Object getNestedFieldVal(GenericRecord record, String fieldName, boolean returnNullIfNotFound); static Schema getNullSchema(); static String sanitizeName(String name); static final Schema METADATA_FIELD_SCHEMA; static final Schema RECORD_KEY_SCHEMA; }