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_r265711747
##########
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:
> I guess you are suggesting we now start using this.
Right.
> do you see a major benefit to it?
Code reuse. But it would only make sense if `findNestedField()` is called
many times. The first call to `findNestedField()` would build the indexes and
consult them. Then any subsequent call to `findNestedField()` would just
consult the cached Maps.
----------------------------------------------------------------
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]