gaborkaszab commented on code in PR #15786:
URL: https://github.com/apache/iceberg/pull/15786#discussion_r3084746716
##########
api/src/test/java/org/apache/iceberg/TestSchema.java:
##########
@@ -312,4 +314,97 @@ public void testIndexFieldsNestedSchema() {
assertThat(fields.get(5).name()).isEqualTo("email");
assertThat(((Types.StructType) fields.get(2).type()).fields()).hasSize(3);
}
+
+ @Test
+ void testFindFieldInMap() {
+ Schema schema =
+ new Schema(
+ required(1, "id", Types.IntegerType.get()),
+ optional(2, "data", Types.StringType.get()),
+ required(
+ 4,
+ "locations",
+ Types.MapType.ofRequired(
+ 10,
+ 11,
+ Types.StructType.of(
+ required(20, "address", Types.StringType.get()),
+ required(21, "city", Types.StringType.get()),
+ required(22, "state", Types.StringType.get()),
+ required(23, "zip", Types.IntegerType.get())),
+ Types.StructType.of(
+ required(12, "lat", Types.FloatType.get()),
+ required(13, "long", Types.FloatType.get()))),
+ "map of address to coordinate"),
+ optional(
+ 7,
+ "properties",
+ Types.MapType.ofOptional(18, 19, Types.StringType.get(),
Types.StringType.get()),
+ "string map of properties"));
+
+ // canonical paths — key and value container fields
+ assertThat(schema.findField("locations.key"))
+ .isNotNull()
+ .extracting(Types.NestedField::fieldId)
+ .isEqualTo(10);
+ assertThat(schema.findField("locations.value"))
+ .isNotNull()
+ .extracting(Types.NestedField::fieldId)
+ .isEqualTo(11);
+
+ // canonical paths — key struct sub-fields
+ assertThat(schema.findField("locations.key.address"))
+ .isNotNull()
+ .extracting(Types.NestedField::fieldId)
+ .isEqualTo(20);
+ assertThat(schema.findField("locations.key.zip"))
+ .isNotNull()
+ .extracting(Types.NestedField::fieldId)
+ .isEqualTo(23);
+
+ // canonical paths — value struct sub-fields
+ assertThat(schema.findField("locations.value.lat"))
+ .isNotNull()
+ .extracting(Types.NestedField::fieldId)
+ .isEqualTo(12);
+ assertThat(schema.findField("locations.value.long"))
+ .isNotNull()
+ .extracting(Types.NestedField::fieldId)
+ .isEqualTo(13);
+
+ // short names — "value" dropped for struct value fields
+ assertThat(schema.findField("locations.lat"))
Review Comment:
I get this. My point is that what happens when we have fields with the same
name both on the key and the value side.
Following your example let's say you have `lat` on both sides.
```
Types.MapType.ofRequired(
10,
11,
Types.StructType.of(
required(20, "address", Types.StringType.get()),
required(21, "city", Types.StringType.get()),
required(22, "state", Types.StringType.get()),
required(23, "zip", Types.IntegerType.get()),
required(30, "lat", Types.FloatType.get())
),
Types.StructType.of(
required(12, "lat", Types.FloatType.get()),
required(13, "long", Types.FloatType.get())))
```
Previous this PR, `schema.findField("locations.lat")` returned the one with
ID 12, with this PR we apparently get the one with ID 30. This seems a behavior
change, or even a breaking change.
I don't think we want to introduce something that might break existing code,
unless I miss something here.
--
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]