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


##########
arrow-schema/src/extension/canonical/variant.rs:
##########
@@ -0,0 +1,233 @@
+// 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.
+
+//! Variant
+//!
+//! <https://arrow.apache.org/docs/format/CanonicalExtensions.html#variant>
+
+use base64::engine::Engine as _;
+use base64::engine::general_purpose::STANDARD;
+use crate::{extension::ExtensionType, ArrowError, DataType};
+
+/// The extension type for `Variant`.
+///
+/// Extension name: `arrow.variant`.
+///
+/// The storage type of this extension is **Binary or LargeBinary**.
+/// A Variant is a flexible structure that can store **Primitives, Arrays, or 
Objects**.
+/// It is stored as **two binary values**: `metadata` and `value`.
+///
+/// The **metadata field is required** and must be a valid Variant metadata 
string.
+/// The **value field is required** and contains the serialized Variant data.
+///
+/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#variant>
+#[derive(Debug, Clone, PartialEq)]
+pub struct Variant {
+    metadata: Vec<u8>, // Required binary metadata
+    value: Vec<u8>, // Required binary value
+}
+
+impl Variant {
+    /// Creates a new `Variant` with metadata and value.
+    pub fn new(metadata: Vec<u8>, value: Vec<u8>) -> Self {
+        Self { metadata, value }
+    }
+
+    /// Creates a Variant representing an empty structure.
+    pub fn empty() -> Result<Self, ArrowError> {
+        Err(ArrowError::InvalidArgumentError(
+            "Variant cannot be empty because metadata and value are 
required".to_owned(),
+        ))
+    }
+
+    /// Returns the metadata as a byte array.
+    pub fn metadata(&self) -> &[u8] {
+        &self.metadata
+    }
+
+    /// Returns the value as an byte array.
+    pub fn value(&self) -> &[u8] {
+        &self.value
+    }
+
+    /// Sets the value of the Variant.
+    pub fn set_value(mut self, value: Vec<u8>) -> Self {
+        self.value = value;
+        self
+    }
+}
+
+impl ExtensionType for Variant {
+    const NAME: &'static str = "arrow.variant";
+
+    type Metadata = Vec<u8>; // Metadata is directly Vec<u8>
+
+    fn metadata(&self) -> &Self::Metadata {
+        &self.metadata
+    }
+
+    fn serialize_metadata(&self) -> Option<String> {
+        Some(STANDARD.encode(&self.metadata)) // Encode metadata as STANDARD 
string

Review Comment:
   Yeah, you're right. The ExtensionType metadata and the Variant metadata are 
not related. Right now the ExtensionType metadata isn’t storing anything 
meaningful.



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