zhedoubushishi opened a new pull request #2232: URL: https://github.com/apache/hudi/pull/2232
## *Tips* - *Thank you very much for contributing to Apache Hudi.* - *Please review https://hudi.apache.org/contributing.html before opening a pull request.* ## What is the purpose of the pull request JIRA https://issues.apache.org/jira/browse/HUDI-1375 This CR fix the bug in HoodieAvroUtils.removeMetadataFields() method. The root cause for this bug is when using Schema$RecordSchema.setFields(), it requires the position of each field must be -1: https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/Schema.java#L908. But filteredFields already set the position in each field. So that's why it throws the exception. Looks like we cannot manually reset the position to -1. But when initializing a new Field, the position by default will be -1. So we can create a new field with the same value as before. ## Brief change log Fix bug and add a test case to cover. ## Verify this pull request This change added tests and can be verified as follows: - w/o the code change in ```HoodieAvroUtils.java```, the unit test won't pass: ``` [INFO] Results: [INFO] [ERROR] Errors: [ERROR] TestHoodieAvroUtils.testAddingAndRemovingMetadataFields:207 ยป AvroRuntime Fiel... [INFO] [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0 ``` - with the code change in ```HoodieAvroUtils.java```, the unit test could pass: ``` [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running org.apache.hudi.avro.TestHoodieAvroUtils [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.346 s - in org.apache.hudi.avro.TestHoodieAvroUtils [INFO] [INFO] Results: [INFO] [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 ``` ## Committer checklist - [x] Has a corresponding JIRA in PR title & commit - [x] Commit message is descriptive of the change - [ ] CI is green - [ ] Necessary doc changes done or have another open PR - [ ] For large changes, please consider breaking it into sub-tasks under an umbrella JIRA. ---------------------------------------------------------------- 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]
