etseidl commented on code in PR #7404:
URL: https://github.com/apache/arrow-rs/pull/7404#discussion_r2049744027


##########
arrow-array/src/array/variant_array.rs:
##########
@@ -0,0 +1,628 @@
+// 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.
+
+use crate::array::print_long_array;
+use crate::builder::{ArrayBuilder, BinaryBuilder};
+use crate::{Array, ArrayRef};
+use arrow_buffer::{Buffer, NullBuffer, OffsetBuffer, ScalarBuffer};
+use arrow_data::{ArrayData, ArrayDataBuilder};
+use arrow_schema::{ArrowError, DataType, Field};
+
+#[cfg(feature = "canonical_extension_types")]
+use arrow_schema::extension::Variant;
+use std::sync::Arc;
+use std::any::Any;
+
+/// An array of Variant values.
+///
+/// The Variant extension type stores data as two binary values: metadata and 
value.
+/// This array stores each Variant as a concatenated binary value (metadata + 
value).
+///
+/// # Example
+///
+/// ```
+/// use arrow_array::VariantArray;
+/// use arrow_schema::extension::Variant;
+/// use arrow_array::Array; // Import the Array trait
+///
+/// // Create metadata and value for each variant
+/// let metadata = vec![
+///     0x01,  // header: version=1, sorted=0, offset_size=1
+///     0x01,  // dictionary_size = 1
+///     0x00,  // offset 0
+///     0x03,  // offset 3
+///     b'k', b'e', b'y'  // dictionary bytes
+/// ];
+/// let variant_type = Variant::new(metadata.clone(), vec![]);
+/// 
+/// // Create variants with different values
+/// let variants = vec![
+///     Variant::new(metadata.clone(), b"null".to_vec()),
+///     Variant::new(metadata.clone(), b"true".to_vec()),
+///     Variant::new(metadata.clone(), b"{\"a\": 1}".to_vec()),
+/// ];
+/// 
+/// // Create a VariantArray
+/// let variant_array = VariantArray::from_variants(variant_type, 
variants.clone()).expect("Failed to create VariantArray");
+///
+/// // Access variants from the array
+/// assert_eq!(variant_array.len(), 3);
+/// let retrieved = variant_array.value(0).expect("Failed to get value");
+/// assert_eq!(retrieved.metadata(), &metadata);
+/// assert_eq!(retrieved.value(), b"null");
+/// ```
+#[cfg(feature = "canonical_extension_types")]
+pub mod variant_array_module {
+    use super::*;
+
+    /// An array of Variant values.
+    ///
+    /// The Variant extension type stores data as two binary values: metadata 
and value.
+    /// This array stores each Variant as a concatenated binary value 
(metadata + value).
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// use arrow_array::VariantArray;
+    /// use arrow_schema::extension::Variant;
+    /// use arrow_array::Array; // Import the Array trait
+    ///
+    /// // Create metadata and value for each variant
+    /// let metadata = vec![
+    ///     0x01,  // header: version=1, sorted=0, offset_size=1
+    ///     0x01,  // dictionary_size = 1
+    ///     0x00,  // offset 0
+    ///     0x03,  // offset 3
+    ///     b'k', b'e', b'y'  // dictionary bytes
+    /// ];
+    /// let variant_type = Variant::new(metadata.clone(), vec![]);
+    /// 
+    /// // Create variants with different values
+    /// let variants = vec![
+    ///     Variant::new(metadata.clone(), b"null".to_vec()),
+    ///     Variant::new(metadata.clone(), b"true".to_vec()),
+    ///     Variant::new(metadata.clone(), b"{\"a\": 1}".to_vec()),
+    /// ];
+    /// 
+    /// // Create a VariantArray
+    /// let variant_array = VariantArray::from_variants(variant_type, 
variants.clone()).expect("Failed to create VariantArray");
+    ///
+    /// // Access variants from the array
+    /// assert_eq!(variant_array.len(), 3);
+    /// let retrieved = variant_array.value(0).expect("Failed to get value");
+    /// assert_eq!(retrieved.metadata(), &metadata);
+    /// assert_eq!(retrieved.value(), b"null");
+    /// ```
+    #[derive(Clone, Debug)]
+    pub struct VariantArray {

Review Comment:
   That PR is proof of concept to help get a change to the Parquet spec across 
the finish line. The format changes there, while including the Variant 
additions, also have not-yet-released bits. It's probably not worth waiting on 
those changes, and instead regen off of the last release version of parquet 
format (2.11.0), which appears to be commit 
`848302e179d7bb52a64caea6a058b3c08212787c`.
   
   



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to