@@ -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}
0 commit comments