Rich-T-kid commented on code in PR #11877:
URL: https://github.com/apache/arrow-rs/pull/11877#discussion_r4463395486


##########
parquet/src/arrow/file_type.rs:
##########
@@ -0,0 +1,356 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Arrow extension type for the Parquet [`FILE`] logical type.
+//!
+//! [`FILE`]: 
https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#file
+
+use arrow_schema::extension::ExtensionType;
+use arrow_schema::{ArrowError, DataType};
+
+/// Arrow extension type for the Parquet [`FILE`] logical type.
+///
+/// A `FILE` value is a reference to a range of bytes, stored inline or in an
+/// external file. Its Arrow storage type is a struct whose fields are a subset
+/// of the following, each nullable, identified by name, in any order:
+///
+/// | Field          | Arrow type                                  |
+/// |----------------|---------------------------------------------|
+/// | `uri`          | `Utf8`, `LargeUtf8`, or `Utf8View`          |
+/// | `offset`       | `Int64`                                     |
+/// | `size`         | `Int64`                                     |
+/// | `content_type` | `Utf8`, `LargeUtf8`, or `Utf8View`          |
+/// | `checksum`     | `Utf8`, `LargeUtf8`, or `Utf8View`          |
+/// | `inline`       | `Binary`, `LargeBinary`, or `BinaryView`    |
+///
+/// When reading, a `FILE`-annotated group is returned as a struct with this
+/// extension type. When writing, a struct field with this extension type is
+/// written as a `FILE`-annotated group.
+///
+/// If the file has an embedded Arrow schema, a reader takes each field's
+/// metadata from it rather than from the Parquet annotation. A 
`FILE`-annotated
+/// group that the embedded schema describes as a plain struct is then read
+/// without this extension type. To get the extension type in that case, read
+/// with [`ArrowReaderOptions::with_skip_arrow_metadata`] set to `true`.
+///
+/// The extension name is `arrow.parquet.file`, which is the intended name for
+/// a canonical Arrow extension type; it is not yet standardized.
+///
+/// [`FILE`]: 
https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#file
+/// [`ArrowReaderOptions::with_skip_arrow_metadata`]: 
crate::arrow::arrow_reader::ArrowReaderOptions::with_skip_arrow_metadata
+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
+pub struct FileType;
+
+impl ExtensionType for FileType {
+    const NAME: &'static str = "arrow.parquet.file";
+
+    type Metadata = &'static str;
+
+    fn metadata(&self) -> &Self::Metadata {
+        &""
+    }
+
+    fn serialize_metadata(&self) -> Option<String> {
+        Some(String::new())
+    }
+
+    fn deserialize_metadata(_metadata: Option<&str>) -> Result<Self::Metadata, 
ArrowError> {
+        Ok("")
+    }

Review Comment:
   FileType serializes its metadata as an empty string, but this accepts every 
metadata value. Since `logical_type_for_struct` relies on 
`has_valid_extension_type`, a field carrying arbitrary or potentially 
incompatible future metadata is still written as Parquet FILE.



##########
parquet/src/arrow/schema/extension.rs:
##########
@@ -129,19 +137,23 @@ pub(crate) fn has_extension_type(parquet_type: &Type) -> 
bool {
 /// files whose annotation does not carry version 1. The value written is
 /// [`parquet_variant::VARIANT_SPEC_VERSION`], the same version stamped into
 /// every metadata header.
-#[cfg(feature = "variant_experimental")]
+#[cfg(any(feature = "variant_experimental", feature = "file_experimental"))]

Review Comment:
   should we also update the doc comment here or is it still accurate?



-- 
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]

Reply via email to