alamb commented on code in PR #12245:
URL: https://github.com/apache/arrow-rs/pull/12245#discussion_r4573834103
##########
parquet-variant-compute/src/variant_array.rs:
##########
@@ -1313,33 +1286,25 @@ mod test {
use arrow::array::{
BinaryArray, BinaryDictionaryBuilder, BinaryRunBuilder,
BinaryViewArray, Decimal32Array,
Decimal64Array, Decimal128Array, FixedSizeBinaryArray,
FixedSizeListArray, Int8Array,
- Int32Array, Int64Array, LargeBinaryArray, LargeListArray,
LargeListViewArray, ListArray,
- ListViewArray, StringArray, Time64MicrosecondArray,
+ Int64Array, LargeBinaryArray, LargeListArray, LargeListViewArray,
ListArray, ListViewArray,
+ StringArray, Time64MicrosecondArray, UInt8Array,
};
use arrow::buffer::{OffsetBuffer, ScalarBuffer};
use arrow_schema::{Field, Fields};
use parquet_variant::{EMPTY_VARIANT_METADATA_BYTES, ShortString};
#[test]
- fn invalid_not_a_struct_array() {
- let array = make_binary_view_array();
- // Should fail because the input is not a StructArray
- let err = VariantArray::try_new(&array);
- assert_eq!(
- err.unwrap_err().to_string(),
- "Invalid argument error: Invalid VariantArray: requires
StructArray as input"
- );
- }
-
- #[test]
- fn invalid_missing_metadata() {
- let fields = Fields::from(vec![Field::new("value",
DataType::BinaryView, true)]);
- let array = StructArray::new(fields, vec![make_binary_view_array()],
None);
- // Should fail because the StructArray does not contain a 'metadata'
field
- let err = VariantArray::try_new(&array);
+ fn invalid_storage_checked_before_canonicalizing() {
+ // `UInt8` is also an illegal shredded type, but the storage error
must win
+ let array = StructArrayAssembler::new()
+ .with_field("metadata", make_binary_view_array(), false)
+ .with_field("value", Arc::new(UInt8Array::from(vec![1])), true)
+ .build()
+ .unwrap();
+ let err = VariantArray::try_new(&array).unwrap_err();
assert_eq!(
- err.unwrap_err().to_string(),
- "Invalid argument error: Invalid VariantArray: StructArray must
contain a 'metadata' field"
+ err.to_string(),
+ "Invalid argument error: VariantType data type mismatch, expected
Struct with binary \"metadata\" and binary \"value\" and/or \"typed_value\"
fields, found Struct(\"metadata\": non-null BinaryView, \"value\": UInt8)"
Review Comment:
nit is I think the old message was more specific and less verbose
It would be nice if we could retain it
##########
parquet-variant-compute/src/variant_array.rs:
##########
@@ -274,39 +255,31 @@ impl VariantArray {
/// - A new instance of `VariantArray`.
///
/// # Errors:
- /// - If the `StructArray` does not contain the required fields
+ /// - If the data type is not valid [`VariantType`] storage
///
/// # Requirements of the `StructArray`
Review Comment:
This is somewhat redundant with what is on VariantType.
It might make sense to pull this information into `VariantType` and then
just link the documentation to `VariantType` now that you have centralized the
code too
##########
arrow-schema/src/extension/canonical/variant.rs:
##########
@@ -13,6 +13,12 @@ use crate::{ArrowError, DataType};
/// See [`VariantArray`] in the `parquet-variant-compute` crate for more
examples
/// of using this extension type.
///
+/// The storage type must be a struct with a binary `metadata` field and at
+/// least one of a binary `value` field or a `typed_value` field. Nullability
Review Comment:
is the mention of nullability really necessary here?
--
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]