Fokko commented on code in PR #12211:
URL: https://github.com/apache/iceberg/pull/12211#discussion_r1950808951
##########
core/src/main/java/org/apache/iceberg/SchemaUpdate.java:
##########
@@ -322,17 +303,45 @@ public UpdateSchema updateColumnDoc(String name, String
doc) {
// merge with a rename or update, if present
int fieldId = field.fieldId();
- Types.NestedField update = updates.get(fieldId);
- if (update != null) {
- updates.put(
- fieldId,
- Types.NestedField.of(fieldId, update.isOptional(), update.name(),
update.type(), doc));
- } else {
- updates.put(
- fieldId,
- Types.NestedField.of(fieldId, field.isOptional(), field.name(),
field.type(), doc));
+ Types.NestedField newField =
Types.NestedField.from(field).withDoc(doc).build();
+ updates.put(fieldId, newField);
+
+ return this;
+ }
+
+ @Override
+ public UpdateSchema updateColumnDefault(String name, Object newDefault) {
+ Types.NestedField field = findForUpdate(name);
+ Preconditions.checkArgument(field != null, "Cannot update missing column:
%s", name);
+ Preconditions.checkArgument(
+ !deletes.contains(field.fieldId()),
+ "Cannot update a column that will be deleted: %s",
+ field.name());
+
+ boolean isAdded = isAdded(name);
+
+ try {
+ if (!isAdded
+ && Objects.equals(
+ field.writeDefault(),
Expressions.lit(newDefault).to(field.type()).value())) {
+ return this;
+ }
+ } catch (RuntimeException ignored) {
+ // if the comparison failed, try to set the new default
+ }
Review Comment:
Why not just check on a `null`? Swallowing the `RuntimeException` makes me
nervous.
```suggestion
if (!isAdded) {
Literal<?> def =
Expressions.lit(newDefault).to(Types.IntegerType.get());
if (Objects.equals(field.writeDefault(), def.value())) {
// Write and default are equal, no need to update initial default
return this;
}
}
```
--
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]