You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/03/22 18:10:15 UTC
[GitHub] [iceberg] kbendick commented on a change in pull request #4372: API: Fix NPE when validating identifier fields
kbendick commented on a change in pull request #4372:
URL: https://github.com/apache/iceberg/pull/4372#discussion_r832472999
##########
File path: api/src/main/java/org/apache/iceberg/Schema.java
##########
@@ -109,6 +109,8 @@ public Schema(int schemaId, List<NestedField> columns, Map<String, Integer> alia
static void validateIdentifierField(int fieldId, Map<Integer, Types.NestedField> idToField,
Map<Integer, Integer> idToParent) {
Types.NestedField field = idToField.get(fieldId);
+ Preconditions.checkArgument(field != null,
+ "Can not add filedId %d as an identifier field: field not exists", fieldId);
Review comment:
Nit: `Can not` -> `Cannot`.
RE the phrasing: In this case, the phrasing does match the rest of the file, though it's not what we normally use in Iceberg. Normally we use `{Problem} {Cause}` and possibly `{Problem} {Cause}: {relevant value}`. And the messages ideally read as plain English phrases.
So it's abnormal to see the `:` in the middle, but it does match the rest of the file. I would say `Cannot add identifier partition field from missing fieldId: %d` and then let the rest be inferred from the stack trace, as adding a partition field is what the user is trying to do here.
But in this case, your phrasing is similar to the rest of the file so it's not the worst phrasing.
So I'd update `Cannot` and `fieldId` typos and then add the test. The phrase is easy to update, but the test is needed regardless.
##########
File path: api/src/main/java/org/apache/iceberg/Schema.java
##########
@@ -109,6 +109,8 @@ public Schema(int schemaId, List<NestedField> columns, Map<String, Integer> alia
static void validateIdentifierField(int fieldId, Map<Integer, Types.NestedField> idToField,
Map<Integer, Integer> idToParent) {
Types.NestedField field = idToField.get(fieldId);
+ Preconditions.checkArgument(field != null,
+ "Can not add filedId %d as an identifier field: field not exists", fieldId);
Review comment:
+1 to adding a unit test in `TestSchemaUpdate` alongside the others.
Here's an example testing similar preconditions in this file that you can adapt your unit test to:
https://github.com/apache/iceberg/blob/fafe33a60c0ce44fb635ff4dfb8663cce42383c1/core/src/test/java/org/apache/iceberg/TestSchemaUpdate.java#L623-L630
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org