kbendick commented on a change in pull request #2943:
URL: https://github.com/apache/iceberg/pull/2943#discussion_r683801334
##########
File path: api/src/main/java/org/apache/iceberg/Schema.java
##########
@@ -93,11 +93,39 @@ public Schema(int schemaId, List<NestedField> columns,
Map<String, Integer> alia
this.schemaId = schemaId;
this.struct = StructType.of(columns);
this.aliasToId = aliases != null ? ImmutableBiMap.copyOf(aliases) : null;
+
+ // validate IdentifierField
+ if (identifierFieldIds != null) {
+ Map<Integer, Integer> idToParent = TypeUtil.indexParents(this.struct);
+ identifierFieldIds.forEach(id -> validateIdentifierField(id,
this.lazyIdToField(), idToParent));
+ }
+
this.identifierFieldIds = identifierFieldIds != null ?
Ints.toArray(identifierFieldIds) : new int[0];
lazyIdToName();
}
+ protected static void validateIdentifierField(int fieldId, Map<Integer,
Types.NestedField> idToField,
+ Map<Integer, Integer>
idToParent) {
+ Types.NestedField field = idToField.get(fieldId);
+ Preconditions.checkArgument(field.type().isPrimitiveType(),
+ "Cannot add field %s as an identifier field: not a primitive type
field", field.name());
+ Preconditions.checkArgument(field.isRequired(),
+ "Cannot add field %s as an identifier field: not a required field",
field.name());
+ Preconditions.checkArgument(!Types.DoubleType.get().equals(field.type()) &&
+ !Types.FloatType.get().equals(field.type()),
Review comment:
Should this be an `||`? Correct me if I'm wrong / need more coffee, but
we're checking that the field type is neither double nor float.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]