rdblue commented on a change in pull request #627: Update indexing to handle
nested lists
URL: https://github.com/apache/incubator-iceberg/pull/627#discussion_r345338993
##########
File path: api/src/main/java/org/apache/iceberg/types/IndexByName.java
##########
@@ -20,53 +20,99 @@
package org.apache.iceberg.types;
import com.google.common.base.Joiner;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import java.util.List;
+import java.util.Deque;
import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.function.Supplier;
import org.apache.iceberg.Schema;
+import org.apache.iceberg.exceptions.ValidationException;
-public class IndexByName extends TypeUtil.SchemaVisitor<Map<String, Integer>> {
+public class IndexByName extends TypeUtil.CustomOrderSchemaVisitor<Map<String,
Integer>> {
private static final Joiner DOT = Joiner.on(".");
+ private final Deque<String> fieldNames = Lists.newLinkedList();
private final Map<String, Integer> nameToId = Maps.newHashMap();
@Override
- public Map<String, Integer> schema(Schema schema, Map<String, Integer>
structResult) {
- return nameToId;
+ public Map<String, Integer> schema(Schema schema, Supplier<Map<String,
Integer>> structResult) {
+ return structResult.get();
}
@Override
- public Map<String, Integer> struct(Types.StructType struct, List<Map<String,
Integer>> fieldResults) {
+ public Map<String, Integer> struct(Types.StructType struct,
Iterable<Map<String, Integer>> fieldResults) {
+ // iterate through the fields to update the index for each one, use size
to avoid errorprone failure
+ Lists.newArrayList(fieldResults).size();
return nameToId;
}
@Override
- public Map<String, Integer> field(Types.NestedField field, Map<String,
Integer> fieldResult) {
+ public Map<String, Integer> field(Types.NestedField field,
Supplier<Map<String, Integer>> fieldResult) {
+ withName(field.name(), fieldResult::get);
Review comment:
I think it's pretty clear from the definition of `withName` that this is
updating the parent names before getting the child results.
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]