mukund-thakur commented on code in PR #15786:
URL: https://github.com/apache/iceberg/pull/15786#discussion_r3088285948
##########
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 see. I get your point now. Thanks for review!
--
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]