Skip to content

Commit 955f7b7

Browse files
fix test issues
1 parent 32232e9 commit 955f7b7

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

hudi-common/src/main/java/org/apache/hudi/common/table/read/FileGroupReaderSchemaHandler.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ HoodieSchema generateRequiredSchema(DeleteContext deleteContext) {
170170
//might need to change this if other queries than mor have mandatory fields
171171
if (!readerContext.getHasLogFiles()) {
172172
if (hasInstantRange && !findNestedField(requestedSchema, HoodieRecord.COMMIT_TIME_METADATA_FIELD).isPresent()) {
173-
List<HoodieSchemaField> addedFields = new ArrayList<>();
174-
addedFields.add(getField(this.tableSchema, HoodieRecord.COMMIT_TIME_METADATA_FIELD));
173+
List<HoodieSchemaField> addedFields = Collections.singletonList(getField(this.tableSchema, HoodieRecord.COMMIT_TIME_METADATA_FIELD));
175174
return appendFieldsToSchemaDedupNested(requestedSchema, addedFields);
176175
}
177176
return requestedSchema;
@@ -288,21 +287,16 @@ static Pair<List<HoodieSchemaField>, List<HoodieSchemaField>> getDataAndMetaCols
288287

289288
public HoodieSchema createSchemaFromFields(List<HoodieSchemaField> fields) {
290289
//fields have positions set, so we need to remove them due to avro setFields implementation
291-
for (int i = 0; i < fields.size(); i++) {
292-
HoodieSchemaField curr = fields.get(i);
293-
fields.set(i, createNewSchemaField(curr));
294-
}
295-
return createNewSchemaFromFieldsWithReference(tableSchema, fields);
290+
List<HoodieSchemaField> newFields = new ArrayList<>(fields.size());
291+
fields.forEach(f -> newFields.add(createNewSchemaField(f)));
292+
return createNewSchemaFromFieldsWithReference(tableSchema, newFields);
296293
}
297294

298295
/**
299296
* Get {@link Schema.Field} from {@link Schema} by field name.
300297
*/
301298
private static HoodieSchemaField getField(HoodieSchema schema, String fieldName) {
302299
Option<HoodieSchemaField> foundFieldOpt = findNestedField(schema, fieldName);
303-
if (!foundFieldOpt.isPresent()) {
304-
throw new IllegalArgumentException("Field: " + fieldName + " does not exist in the table schema");
305-
}
306-
return foundFieldOpt.get();
300+
return foundFieldOpt.orElseThrow(() -> new IllegalArgumentException("Field: " + fieldName + " does not exist in the table schema"));
307301
}
308302
}

hudi-common/src/test/java/org/apache/hudi/common/table/read/buffer/BaseTestFileGroupRecordBuffer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ protected static KeyBasedFileGroupRecordBuffer<IndexedRecord> buildKeyBasedFileG
118118
});
119119
FileGroupReaderSchemaHandler<IndexedRecord> fileGroupReaderSchemaHandler = mock(FileGroupReaderSchemaHandler.class);
120120
when(fileGroupReaderSchemaHandler.getRequiredSchema()).thenReturn(SCHEMA);
121+
when(fileGroupReaderSchemaHandler.getSchemaForUpdates()).thenReturn(SCHEMA);
121122
when(fileGroupReaderSchemaHandler.getInternalSchema()).thenReturn(InternalSchema.getEmptyInternalSchema());
122123
when(fileGroupReaderSchemaHandler.getDeleteContext()).thenReturn(new DeleteContext(props, SCHEMA));
123124
readerContext.setSchemaHandler(fileGroupReaderSchemaHandler);

hudi-common/src/test/java/org/apache/hudi/common/table/read/buffer/TestFileGroupRecordBufferLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public void testDefaultFileGroupBufferRecordLoader(String fileGroupRecordBufferT
7272
FileGroupReaderSchemaHandler<IndexedRecord> fileGroupReaderSchemaHandler = mock(FileGroupReaderSchemaHandler.class);
7373
when(fileGroupReaderSchemaHandler.getRequiredSchema()).thenReturn(SCHEMA);
7474
when(fileGroupReaderSchemaHandler.getRequestedSchema()).thenReturn(SCHEMA);
75+
when(fileGroupReaderSchemaHandler.getSchemaForUpdates()).thenReturn(SCHEMA);
7576
when(fileGroupReaderSchemaHandler.getInternalSchema()).thenReturn(InternalSchema.getEmptyInternalSchema());
7677
DeleteContext deleteContext = mock(DeleteContext.class);
7778
when(deleteContext.getCustomDeleteMarkerKeyValue()).thenReturn(Option.empty());

0 commit comments

Comments
 (0)