scovich commented on code in PR #7921:
URL: https://github.com/apache/arrow-rs/pull/7921#discussion_r2204684924


##########
parquet-variant-compute/src/shredding.rs:
##########
@@ -0,0 +1,364 @@
+// 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 arrow_schema::{ArrowError, DataType, Fields};
+
+// Keywords defined by the shredding spec
+pub const METADATA: &str = "metadata";
+pub const VALUE: &str = "value";
+pub const TYPED_VALUE: &str = "typed_value";
+
+pub fn validate_value_and_typed_value(
+    fields: &Fields,
+    allow_both_null: bool,
+) -> Result<(), ArrowError> {
+    let value_field_res = fields.iter().find(|f| f.name() == VALUE);
+    let typed_value_field_res = fields.iter().find(|f| f.name() == 
TYPED_VALUE);
+
+    if !allow_both_null {
+        if let (None, None) = (value_field_res, typed_value_field_res) {
+            return Err(ArrowError::InvalidArgumentError(
+                "Invalid VariantArray: StructArray must contain either `value` 
or `typed_value` fields or both.".to_string()
+            ));
+        }
+    }
+
+    if let Some(value_field) = value_field_res {
+        // if !value_field.is_nullable() {
+        //     return Err(ArrowError::InvalidArgumentError(
+        //         "Expected value field to be nullable".to_string(),
+        //     ));
+        // }

Review Comment:
   What I don't know, is what should happen with `metadata` in a variant that 
shredded as a deeply nested struct, where one or more of those struct fields 
happen to be variant typed (which in turn can also be shredded further, and 
which can _also_ contain variant fields of their own?
   ```
   v: VARIANT {
      metadata: BINARY,
      value: BINARY,
      typed_value: {
          a: STRUCT {
              b: STRUCT {
                  c: STRUCT {
                      w: VARIANT {
                          metadata: BINARY, << --- ???
                          value: BINARY,
                          typed_value: STRUCT {
                              x: STRUCT {
                                  y: STRUCT {
                                      z: STRUCT {
                                          u: VARIANT {
                                              metadata: BINARY, <<--- ???
                                              value: BINARY,
                                          }
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
          }
      }
   }
   ```
   The 
[spec](https://github.com/apache/parquet-format/blob/master/VariantShredding.md#variant-metadata)
 says that 
   > Variant metadata is stored in the top-level Variant group in a binary 
metadata column regardless of whether the Variant value is shredded.
   > 
   > All value columns within the Variant must use the same metadata. All field 
names of a Variant, whether shredded or not, must be present in the metadata.
   
   I'm pretty sure that means `w` and `u` must _not_ have `metadata` columns -- 
because they are still "inside" `v`. 
   
   Even if one tried to store path names of `u` inside all three `metadata` 
columns, the field ids would disagree unless we forced `u.metadata` and 
`w.metadata` to be copies of `v.metadata`. Easy enough to do that in arrow-rs 
(all array data are anyway Arc), but what about the actual parquet file??



##########
parquet-variant-compute/src/shredding.rs:
##########
@@ -0,0 +1,364 @@
+// 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 arrow_schema::{ArrowError, DataType, Fields};
+
+// Keywords defined by the shredding spec
+pub const METADATA: &str = "metadata";
+pub const VALUE: &str = "value";
+pub const TYPED_VALUE: &str = "typed_value";
+
+pub fn validate_value_and_typed_value(
+    fields: &Fields,
+    allow_both_null: bool,
+) -> Result<(), ArrowError> {
+    let value_field_res = fields.iter().find(|f| f.name() == VALUE);
+    let typed_value_field_res = fields.iter().find(|f| f.name() == 
TYPED_VALUE);
+
+    if !allow_both_null {
+        if let (None, None) = (value_field_res, typed_value_field_res) {
+            return Err(ArrowError::InvalidArgumentError(
+                "Invalid VariantArray: StructArray must contain either `value` 
or `typed_value` fields or both.".to_string()
+            ));
+        }
+    }
+
+    if let Some(value_field) = value_field_res {
+        // if !value_field.is_nullable() {
+        //     return Err(ArrowError::InvalidArgumentError(
+        //         "Expected value field to be nullable".to_string(),
+        //     ));
+        // }

Review Comment:
   Spec 
[says](https://github.com/apache/parquet-format/blob/master/VariantShredding.md#value-shredding)
 that both can be nullable:
   > ```
   > required group measurement (VARIANT) {
   >   required binary metadata;
   >   optional binary value;
   >   optional int64 typed_value;
   > }
   > ```



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