nastra commented on code in PR #14270:
URL: https://github.com/apache/iceberg/pull/14270#discussion_r2415711686
##########
api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java:
##########
@@ -849,4 +849,99 @@ public void testReassignDocWithType(Type testType) {
Schema reassignedSchema = TypeUtil.reassignDoc(schema, docSourceSchema);
assertThat(reassignedSchema.asStruct()).isEqualTo(docSourceSchema.asStruct());
}
+
+ @Test
+ public void findParentsInEmptySchema() {
+ assertThat(TypeUtil.findParents(new Schema(), -1)).isEmpty();
+ assertThat(TypeUtil.findParents(new Schema(), 1)).isEmpty();
+ }
+
+ @Test
+ public void findParentsInNonNestedSchema() {
+ Schema schema =
+ new Schema(
+ required(0, "a", Types.IntegerType.get()), required(1, "A",
Types.IntegerType.get()));
+
+ assertThat(TypeUtil.findParents(schema, 0)).isEmpty();
+ assertThat(TypeUtil.findParents(schema, 1)).isEmpty();
+ }
+
+ @Test
+ public void findParentsInNestedSchema() {
+ Types.NestedField innerPreferences =
+ optional(
+ 8,
+ "inner_preferences",
+ Types.StructType.of(
+ required(12, "feature3", Types.BooleanType.get()),
+ optional(13, "feature4", Types.BooleanType.get())));
+ Types.NestedField preferences =
+ optional(
+ 3,
+ "preferences",
+ Types.StructType.of(
+ required(6, "feature1", Types.BooleanType.get()),
+ optional(7, "feature2", Types.BooleanType.get()),
+ innerPreferences));
+
+ // define locations map with all nested fields
+ Types.StructType locationsKeyStruct =
+ Types.StructType.of(
+ required(20, "address", Types.StringType.get()),
+ required(21, "city", Types.StringType.get()),
+ required(22, "state", Types.StringType.get()),
+ required(23, "zip", IntegerType.get()));
+ Types.StructType locationsValueStruct =
+ Types.StructType.of(
+ required(14, "lat", Types.FloatType.get()),
+ required(15, "long", Types.FloatType.get()));
+ Types.NestedField locationsKey = required(9, "key", locationsKeyStruct);
+ Types.NestedField locationsValue = required(10, "value",
locationsValueStruct);
+ Types.NestedField locations =
+ required(
+ 4,
+ "locations",
+ Types.MapType.ofRequired(9, 10, locationsKeyStruct,
locationsValueStruct));
+
+ // define points list with all nested fields
+ Types.StructType pointsStruct =
+ Types.StructType.of(
+ required(16, "x", Types.LongType.get()), required(17, "y",
Types.LongType.get()));
+ Types.NestedField pointsElement = optional(11, "element", pointsStruct);
+ Types.NestedField points = optional(5, "points",
Types.ListType.ofOptional(11, pointsStruct));
+
+ Types.NestedField id = required(1, "id", IntegerType.get());
+ Types.NestedField data = optional(2, "data", Types.StringType.get());
+ Schema schema = new Schema(id, data, preferences, locations, points);
+
+ // non-nested fields don't have parents
+ assertThat(TypeUtil.findParents(schema, id.fieldId())).isEmpty();
+ assertThat(TypeUtil.findParents(schema, data.fieldId())).isEmpty();
+
+ // verify preferences struct and all of its nested fields (6-8, 12+13)
+ assertThat(TypeUtil.findParents(schema, preferences.fieldId())).isEmpty();
+ assertThat(TypeUtil.findParents(schema, 6)).containsExactly(preferences);
+ assertThat(TypeUtil.findParents(schema, 7)).containsExactly(preferences);
+ assertThat(TypeUtil.findParents(schema, innerPreferences.fieldId()))
+ .containsExactly(preferences);
+ assertThat(TypeUtil.findParents(schema,
12)).containsExactly(innerPreferences, preferences);
+ assertThat(TypeUtil.findParents(schema,
13)).containsExactly(innerPreferences, preferences);
+
+ // verify locations map and all of its nested fields (IDs 20-23 and 14+15)
+ assertThat(TypeUtil.findParents(schema, locations.fieldId())).isEmpty();
+ assertThat(TypeUtil.findParents(schema,
locationsKey.fieldId())).containsExactly(locations);
+ assertThat(TypeUtil.findParents(schema, 20)).containsExactly(locationsKey,
locations);
+ assertThat(TypeUtil.findParents(schema, 21)).containsExactly(locationsKey,
locations);
+ assertThat(TypeUtil.findParents(schema, 22)).containsExactly(locationsKey,
locations);
+ assertThat(TypeUtil.findParents(schema, 23)).containsExactly(locationsKey,
locations);
+ assertThat(TypeUtil.findParents(schema,
locationsValue.fieldId())).containsExactly(locations);
+ assertThat(TypeUtil.findParents(schema,
14)).containsExactly(locationsValue, locations);
+ assertThat(TypeUtil.findParents(schema,
15)).containsExactly(locationsValue, locations);
+
+ // verify points list and all of its nested fields (IDs 14-16)
Review Comment:
oops yes, I forgot to update the comment, thanks for spotting
##########
api/src/main/java/org/apache/iceberg/expressions/UnboundPredicate.java:
##########
@@ -155,6 +158,11 @@ private Expression bindUnaryOperation(BoundTerm<T>
boundTerm) {
}
}
+ private boolean allParentFieldsAreRequired(StructType struct, int fieldId) {
Review Comment:
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]