wgtmac commented on code in PR #45866:
URL: https://github.com/apache/arrow/pull/45866#discussion_r2014358848
##########
cpp/src/parquet/arrow/schema.cc:
##########
@@ -1053,6 +1060,29 @@ Result<bool> ApplyOriginalMetadata(const Field&
origin_field, SchemaField* infer
// inferred_type is arrow::extension::json(arrow::utf8())
auto origin_storage_field =
origin_field.WithType(ex_type.storage_type());
+ // Apply metadata recursively to storage type
+ RETURN_NOT_OK(ApplyOriginalStorageMetadata(*origin_storage_field,
inferred));
+ inferred->field = inferred->field->WithType(origin_type);
+ } else if (inferred_type->id() == ::arrow::Type::FIXED_SIZE_BINARY &&
Review Comment:
These branches are growing longer while they look pretty similar. Not sure
if we can refactor it a little bit to look nicer.
##########
cpp/src/parquet/arrow/arrow_schema_test.cc:
##########
@@ -948,6 +949,68 @@ TEST_F(TestConvertParquetSchema,
ParquetSchemaArrowExtensions) {
}
}
+TEST_F(TestConvertParquetSchema, ParquetSchemaArrowUuidExtension) {
+ std::vector<NodePtr> parquet_fields;
+ parquet_fields.push_back(PrimitiveNode::Make("uuid", Repetition::OPTIONAL,
+ LogicalType::UUID(),
+
ParquetType::FIXED_LEN_BYTE_ARRAY, 16));
+
+ {
+ // Parquet file does not contain Arrow schema.
+ // By default, field should be treated as fixed_size_binary(16) in Arrow.
+ auto arrow_schema =
+ ::arrow::schema({::arrow::field("uuid",
::arrow::fixed_size_binary(16), true)});
+ std::shared_ptr<KeyValueMetadata> metadata{};
+ ASSERT_OK(ConvertSchema(parquet_fields, metadata));
+ CheckFlatSchema(arrow_schema);
+ }
+
+ {
+ // Parquet file does not contain Arrow schema.
+ // If Arrow extensions are enabled, field will be interpreted as uuid()
+ // extension field.
+ ArrowReaderProperties props;
+ props.set_arrow_extensions_enabled(true);
+ auto arrow_schema =
+ ::arrow::schema({::arrow::field("uuid", ::arrow::extension::uuid(),
true)});
+ std::shared_ptr<KeyValueMetadata> metadata{};
+ ASSERT_OK(ConvertSchema(parquet_fields, metadata, props));
+ CheckFlatSchema(arrow_schema);
+ }
+
+ {
+ // Parquet file contains Arrow schema.
+ // uuid will be interpreted as uuid() field
+ ArrowReaderProperties props;
+ props.set_arrow_extensions_enabled(false);
+ std::shared_ptr<KeyValueMetadata> field_metadata =
Review Comment:
Why the above two cases do not include field_metadata? Does it fail in the
CheckFlatSchema because restored schema does not carry it?
--
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]