uros-b commented on code in PR #17513:
URL: https://github.com/apache/iceberg/pull/17513#discussion_r3719651255
##########
api/src/main/java/org/apache/iceberg/types/TypeUtil.java:
##########
@@ -291,6 +291,28 @@ public static List<Types.NestedField>
ancestorFields(Schema schema, int fieldId)
return parents;
}
+ /**
+ * Returns whether a field can evaluate to null within the given schema.
+ *
+ * <p>A field can be null if it is declared optional, or if it is nested
inside an optional field.
+ * For example, a required field inside an optional struct is effectively
null whenever that
+ * struct is null.
+ *
+ * <p>If the field is not present in the schema, this method returns true
because its nullability
+ * cannot be determined.
+ *
+ * @param schema The schema that contains the field ID
+ * @param fieldId The field ID to check
+ * @return true if the field may be null, false if it cannot be null
+ */
+ public static boolean isNullable(Schema schema, int fieldId) {
+ Types.NestedField field = schema.findField(fieldId);
Review Comment:
```suggestion
Preconditions.checkNotNull(schema, "Schema cannot be null");
Types.NestedField field = schema.findField(fieldId);
```
--
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]