wgtmac commented on code in PR #49218:
URL: https://github.com/apache/arrow/pull/49218#discussion_r2792376765
##########
cpp/src/parquet/arrow/arrow_schema_test.cc:
##########
@@ -2018,6 +2019,50 @@ TEST_F(TestConvertRoundTrip,
FieldIdPreserveAllColumnTypes) {
ASSERT_EQ(thrift_field_ids, expected_field_ids);
}
+TEST_F(TestConvertRoundTrip, MapNestedFieldMetadataPreserved) {
+ auto key_meta = ::arrow::key_value_metadata({"k"}, {"v"});
+ auto inner_meta = ::arrow::key_value_metadata({"inner_k"}, {"inner_v"});
+
+ auto map_key = ::arrow::field("key", UTF8, /*nullable=*/false, key_meta);
+ auto map_value = ::arrow::field(
+ "value",
+ ::arrow::struct_({::arrow::field("inner", INT64, /*nullable=*/true,
inner_meta)}),
+ /*nullable=*/true, inner_meta);
+ auto sorted_map =
+ std::make_shared<::arrow::MapType>(map_key, map_value,
/*keys_sorted=*/true);
+ auto arrow_schema = ::arrow::schema(
+ {::arrow::field("m", sorted_map, /*nullable=*/true,
FieldIdMetadata(99))});
+
+ std::shared_ptr<SchemaDescriptor> parquet_schema;
+ ASSERT_OK(ToParquetSchema(arrow_schema.get(),
*::parquet::default_writer_properties(),
+ &parquet_schema));
+
+ std::shared_ptr<KeyValueMetadata> kv_metadata;
+ ASSERT_OK(ArrowSchemaToParquetMetadata(arrow_schema, kv_metadata));
+
+ std::shared_ptr<::arrow::Schema> restored_schema;
+ ASSERT_OK(FromParquetSchema(parquet_schema.get(), ArrowReaderProperties(),
kv_metadata,
+ &restored_schema));
+ ASSERT_EQ(restored_schema->num_fields(), 1);
+
+ auto restored_map =
::arrow::internal::checked_pointer_cast<::arrow::MapType>(
+ restored_schema->field(0)->type());
+ ASSERT_EQ(GetFieldId(*restored_schema->field(0)), 99);
+
+ ASSERT_TRUE(restored_map->keys_sorted());
Review Comment:
I didn't use this approach because it will fail at comparing map type
metadata fingerprint. The reason is that
`"key_value"` is always used when converting arrow map type to parquet map
type:
https://github.com/apache/arrow/blob/bc489218164218387c9728b89497c80d41eb1c00/cpp/src/parquet/arrow/schema.cc#L126
but Arrow map type uses `"entries"`:
https://github.com/apache/arrow/blob/bc489218164218387c9728b89497c80d41eb1c00/cpp/src/arrow/type.cc#L1041
Fixing this requires larger effort and may break existing applications.
--
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]