Skip to content

Commit

Permalink
[AMORO-2375] Add more detail exception log In SchemaUtil.selectInOrder (
Browse files Browse the repository at this point in the history
apache#2493)

* [AMORO-2375] Add more detail exception log In SchemaUtil.selectInOrder

* [AMORO-2375] Add more detail exception log In SchemaUtil.selectInOrder

* refactor code
  • Loading branch information
tcodehuber authored Jan 16, 2024
1 parent 4a84406 commit 91d5371
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/com/netease/arctic/utils/SchemaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,23 @@ public static Schema fillUpIdentifierFields(
public static Schema selectInOrder(Schema baseSchema, List<String> fieldNames) {
Preconditions.checkNotNull(fieldNames);
Preconditions.checkNotNull(baseSchema);
validateSchemaFields(baseSchema, fieldNames);

int schemaId = baseSchema.schemaId();
List<Types.NestedField> fields =
fieldNames.stream().map(baseSchema::findField).collect(Collectors.toList());

return new Schema(schemaId, fields);
}

private static void validateSchemaFields(Schema schema, List<String> requiredFields) {
Set<String> existingFields =
schema.columns().stream().map(Types.NestedField::name).collect(Collectors.toSet());
for (String requiredField : requiredFields) {
if (!existingFields.contains(requiredField)) {
throw new IllegalArgumentException(
"The required field in schema is missing: " + requiredField);
}
}
}
}

0 comments on commit 91d5371

Please sign in to comment.