mapleFU commented on code in PR #41765:
URL: https://github.com/apache/arrow/pull/41765#discussion_r2015547101
##########
cpp/src/parquet/arrow/arrow_schema_test.cc:
##########
@@ -740,6 +740,36 @@ TEST_F(TestConvertParquetSchema, ParquetNestedSchema2) {
ASSERT_NO_FATAL_FAILURE(CheckFlatSchema(arrow_schema));
}
+TEST_F(TestConvertParquetSchema, ParquetUndefinedType) {
+ std::vector<NodePtr> parquet_fields;
+
+ // Make a node and intentionally modify it such that it comes back
+ // as NoLogicalType::Make()
+ NodePtr node = PrimitiveNode::Make("undefined", Repetition::OPTIONAL,
+ StringLogicalType::Make(),
Type::BYTE_ARRAY);
+
+ format::SchemaElement string_intermediary;
+ node->ToParquet(&string_intermediary);
+
+ string_intermediary.logicalType.__isset.STRING = false;
+ node = PrimitiveNode::FromParquet(&string_intermediary);
+ parquet_fields.push_back(std::move(node));
+
+ // With default options, this should error
+ ASSERT_NOT_OK(ConvertSchema(parquet_fields));
+
+ // With an opt-in, the field should be converted according to its storage
+ ArrowReaderProperties props;
+ props.set_convert_undefined_logical_types(true);
+ ASSERT_OK(ConvertSchema(parquet_fields, nullptr, props));
Review Comment:
should we check `result_schema_` after convert?
##########
cpp/src/parquet/arrow/arrow_schema_test.cc:
##########
@@ -740,6 +740,36 @@ TEST_F(TestConvertParquetSchema, ParquetNestedSchema2) {
ASSERT_NO_FATAL_FAILURE(CheckFlatSchema(arrow_schema));
}
+TEST_F(TestConvertParquetSchema, ParquetUndefinedType) {
+ std::vector<NodePtr> parquet_fields;
+
+ // Make a node and intentionally modify it such that it comes back
+ // as NoLogicalType::Make()
+ NodePtr node = PrimitiveNode::Make("undefined", Repetition::OPTIONAL,
+ StringLogicalType::Make(),
Type::BYTE_ARRAY);
+
+ format::SchemaElement string_intermediary;
+ node->ToParquet(&string_intermediary);
+
+ string_intermediary.logicalType.__isset.STRING = false;
+ node = PrimitiveNode::FromParquet(&string_intermediary);
+ parquet_fields.push_back(std::move(node));
+
+ // With default options, this should error
+ ASSERT_NOT_OK(ConvertSchema(parquet_fields));
Review Comment:
Should we also check the error message?
##########
cpp/src/parquet/arrow/schema_internal.cc:
##########
@@ -191,10 +191,18 @@ Result<std::shared_ptr<ArrowType>> FromInt64(const
LogicalType& logical_type) {
Result<std::shared_ptr<ArrowType>> GetArrowType(
Type::type physical_type, const LogicalType& logical_type, int type_length,
const ArrowReaderProperties& reader_properties) {
- if (logical_type.is_invalid() || logical_type.is_null()) {
+ if (logical_type.is_null()) {
return ::arrow::null();
}
+ if (logical_type.is_invalid() &&
reader_properties.convert_undefined_logical_types()) {
Review Comment:
What about:
```
if (logical_type.is_invalid()) {
if (reader_properties.convert_undefined_logical_types()) {
}
return Status::NotImplemented("...");
}
```
##########
cpp/src/parquet/properties.h:
##########
@@ -1003,9 +1004,23 @@ class PARQUET_EXPORT ArrowReaderProperties {
void set_should_load_statistics(bool should_load_statistics) {
should_load_statistics_ = should_load_statistics;
}
+
/// Return whether loading statistics as much as possible.
bool should_load_statistics() const { return should_load_statistics_; }
+ /// Convert undefined logical types as their underlying physical type
+ ///
+ /// When enabled, the Arrow reader will use the underlying physical type
Review Comment:
use the underlying physical type to deduce the arrow type?
--
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]