Fokko commented on code in PR #12211:
URL: https://github.com/apache/iceberg/pull/12211#discussion_r1950799826
##########
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:
This branch is not covered by tests
--
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]