kbendick commented on a change in pull request #1336:
URL: https://github.com/apache/iceberg/pull/1336#discussion_r479703009



##########
File path: api/src/main/java/org/apache/iceberg/types/IndexByName.java
##########
@@ -25,39 +25,64 @@
 import org.apache.iceberg.Schema;
 import org.apache.iceberg.exceptions.ValidationException;
 import org.apache.iceberg.relocated.com.google.common.base.Joiner;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
 import org.apache.iceberg.relocated.com.google.common.collect.Lists;
 import org.apache.iceberg.relocated.com.google.common.collect.Maps;
 
 public class IndexByName extends TypeUtil.SchemaVisitor<Map<String, Integer>> {
   private static final Joiner DOT = Joiner.on(".");
 
   private final Deque<String> fieldNames = Lists.newLinkedList();
+  private final Deque<String> shortFieldNames = Lists.newLinkedList();
   private final Map<String, Integer> nameToId = Maps.newHashMap();
+  private final Map<String, Integer> shortNameToId = Maps.newHashMap();
+
+  public Map<String, Integer> byName() {
+    ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder();
+    builder.putAll(nameToId);
+    // add all short names that do not conflict with canonical names
+    shortNameToId.entrySet().stream()
+        .filter(entry -> !nameToId.containsKey(entry.getKey()))
+        .forEach(builder::put);
+    return builder.build();
+  }
+
+  public Map<Integer, String> byId() {

Review comment:
       It does somewhat seem implied that this isn't a bijection (and that long 
names are returned) via `Canonical names, not short names are returned, for 
example 'list.element.field' instead of 'list.field'.`
   
   Perhaps it might be specifically useful to call this out in the `@return` 
via something like `@return A  map from field ID to the long / canonical field 
name.`?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to