aokolnychyi commented on code in PR #15297:
URL: https://github.com/apache/iceberg/pull/15297#discussion_r2814016424
##########
api/src/main/java/org/apache/iceberg/types/TypeUtil.java:
##########
@@ -601,6 +601,52 @@ public interface GetID {
int get(int oldId);
}
+ /**
+ * Creates a function that reassigns specified field IDs.
+ *
+ * <p>This is useful for merging schemas where some field IDs in one schema
might conflict with
+ * IDs already in use by another schema. The function will reassign the
provided IDs to new unused
+ * IDs, while preserving other IDs.
+ *
+ * @param conflictingIds the set of conflicting field IDs that should be
reassigned
+ * @param usedIds the set of field IDs that are already in use and cannot be
reused
+ * @return a function that maps old IDs to new IDs while resolving conflicts
+ */
+ public static GetID reassignConflictingIds(Set<Integer> conflictingIds,
Set<Integer> usedIds) {
+ return new ReassignConflictingIds(conflictingIds, usedIds);
+ }
+
+ private static class ReassignConflictingIds implements GetID {
+ private final Set<Integer> conflictingIds;
+ private final Set<Integer> usedIds;
+ private final AtomicInteger nextId;
+
+ private ReassignConflictingIds(Set<Integer> conflictingIds, Set<Integer>
usedIds) {
+ this.conflictingIds = conflictingIds;
+ this.usedIds = usedIds;
+ this.nextId = new AtomicInteger(usedIds.size()); // assume sequential
assignment
Review Comment:
I think it should be fine but you are right, better to move it into a
separate change. Reverted.
##########
api/src/main/java/org/apache/iceberg/types/TypeUtil.java:
##########
@@ -601,6 +601,52 @@ public interface GetID {
int get(int oldId);
}
+ /**
+ * Creates a function that reassigns specified field IDs.
+ *
+ * <p>This is useful for merging schemas where some field IDs in one schema
might conflict with
+ * IDs already in use by another schema. The function will reassign the
provided IDs to new unused
+ * IDs, while preserving other IDs.
+ *
+ * @param conflictingIds the set of conflicting field IDs that should be
reassigned
+ * @param usedIds the set of field IDs that are already in use and cannot be
reused
+ * @return a function that maps old IDs to new IDs while resolving conflicts
Review Comment:
Agreed, updated.
--
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]