xabriel commented on a change in pull request #123: Add support for struct
field based filtering
URL: https://github.com/apache/incubator-iceberg/pull/123#discussion_r264371396
##########
File path:
api/src/main/java/com/netflix/iceberg/expressions/UnboundPredicate.java
##########
@@ -132,4 +134,36 @@ public Expression bind(Types.StructType struct, boolean
caseSensitive) {
}
return new BoundPredicate<>(op(), new BoundReference<>(struct,
field.fieldId()), lit);
}
+
+ private Types.NestedField findNestedField(Types.StructType struct, String
expressionFieldPath,
+ boolean caseSensitive) {
+
+ String[] nestedFields = expressionFieldPath.split("\\.");
+ String lastFieldInPath = nestedFields[nestedFields.length - 1];
+
+ Types.StructType subField = struct;
+ int i=0;
+
+ Type nextFieldType = caseSensitive ?
subField.field(nestedFields[i]).type() :
+ subField.caseInsensitiveField(nestedFields[i]).type();
+
+ if (!(nextFieldType instanceof Types.StructType)) {
+ // we don't handle non-struct nested fields yet
+ return null;
+ }
+
+ while(nextFieldType instanceof Types.StructType && i <
nestedFields.length) {
+
+ subField = caseSensitive ?
subField.field(nestedFields[i]).type().asStructType() :
+ subField.caseInsensitiveField(nestedFields[i]).type().asStructType();
+
+ i++;
+
+ nextFieldType = caseSensitive ? subField.field(nestedFields[i]).type() :
+ subField.caseInsensitiveField(nestedFields[i]).type();
+ }
+
+ return subField.field(lastFieldInPath);
+
+ }
Review comment:
Now that we need to recurse, I wonder if it makes sense to reuse the indexes
available in `TypeUtils`:
https://github.com/apache/incubator-iceberg/blob/0c9c63140e838875dc8cc52a57be2c8f24ad9975/api/src/main/java/com/netflix/iceberg/types/TypeUtil.java#L78-L84
so that this code simplifies to:
```java
Integer idx = indexByName.get(expressionFieldPath);
Types.NestedField field = indexById.get(idx);
```
That code doesn't check for non-struct parents; we'd have to perhaps create
a custom Indexer. Also we would need to calculate the index lazily and perhaps
cache it ( As in the `Schema`, see
https://github.com/apache/incubator-iceberg/blob/master/api/src/main/java/com/netflix/iceberg/Schema.java#L59-L71
)
----------------------------------------------------------------
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]