Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions parquet-variant-compute/src/variant_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl VariantArray {
/// binary_view
///
/// 3. An optional field named `typed_value` which can be any primitive type
/// or be a list, large_list, list_view or struct
/// or be a list, large_list, fixed_size_list, list_view or struct
///
/// NOTE: It is also permissible for the metadata field to be
/// Dictionary-Encoded, preferably (but not required) with an index type of
Expand Down Expand Up @@ -1236,7 +1236,7 @@ fn canonicalize_and_verify_data_type(data_type: &DataType) -> Result<Cow<'_, Dat

// UUID maps to 16-byte fixed-size binary; no other width is allowed
FixedSizeBinary(16) => borrow!(),
FixedSizeBinary(_) | FixedSizeList(..) => fail!(),
FixedSizeBinary(_) => fail!(),

// List-like containers and struct are allowed, maps and unions are not
List(field) => match canonicalize_and_verify_field(field)? {
Expand All @@ -1255,6 +1255,10 @@ fn canonicalize_and_verify_data_type(data_type: &DataType) -> Result<Cow<'_, Dat
Cow::Borrowed(_) => borrow!(),
Cow::Owned(new_field) => Cow::Owned(DataType::LargeListView(new_field)),
},
FixedSizeList(field, size) => match canonicalize_and_verify_field(field)? {
Cow::Borrowed(_) => borrow!(),
Cow::Owned(new_field) => Cow::Owned(DataType::FixedSizeList(new_field, *size)),
},
// Struct is used by the internal layout, and can also represent a shredded variant object.
Struct(fields) => {
// Avoid allocation unless at least one field changes, to avoid unnecessary deep cloning
Expand Down Expand Up @@ -1334,8 +1338,8 @@ mod test {
use super::*;
use arrow::array::{
BinaryArray, BinaryViewArray, Decimal32Array, Decimal64Array, Decimal128Array,
FixedSizeBinaryArray, Int32Array, Int64Array, LargeBinaryArray, LargeListArray,
LargeListViewArray, ListArray, ListViewArray, Time64MicrosecondArray,
FixedSizeBinaryArray, FixedSizeListArray, Int32Array, Int64Array, LargeBinaryArray,
LargeListArray, LargeListViewArray, ListArray, ListViewArray, Time64MicrosecondArray,
};
use arrow::buffer::{OffsetBuffer, ScalarBuffer};
use arrow_schema::{Field, Fields};
Expand Down Expand Up @@ -1535,6 +1539,10 @@ mod test {
DataType::LargeList(make_item_binary_view()),
DataType::ListView(make_item_binary_view()),
DataType::LargeListView(make_item_binary_view()),
// Fixed-size list items
DataType::FixedSizeList(make_item_binary(), 2),
DataType::FixedSizeList(make_large_binary(), 2),
DataType::FixedSizeList(make_item_binary_view(), 2),
];

for input in cases {
Expand Down Expand Up @@ -1577,6 +1585,12 @@ mod test {
values,
None,
)) as ArrayRef,
Arc::new(FixedSizeListArray::new(
Arc::new(Field::new("item", DataType::Int64, true)),
2,
Arc::new(Int64Array::from(vec![Some(1), None, Some(3), Some(4)])),
None,
)) as ArrayRef,
];

for typed_value in typed_values {
Expand Down
17 changes: 14 additions & 3 deletions parquet-variant-compute/src/variant_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// under the License.
use arrow::{
array::{
self, Array, ArrayRef, GenericListArray, GenericListViewArray, ListLikeArray, StructArray,
UInt64Array, make_array,
self, Array, ArrayRef, FixedSizeListArray, GenericListArray, GenericListViewArray,
ListLikeArray, StructArray, UInt64Array, make_array,
},
buffer::NullBuffer,
compute::{CastOptions, take},
Expand Down Expand Up @@ -171,6 +171,9 @@ pub(crate) fn follow_shredded_path_element(
DataType::LargeListView(_) => take_list_like_index_as_shredding_state::<
GenericListViewArray<i64>,
>(typed_value.as_ref(), *index)?,
DataType::FixedSizeList(_, _) => take_list_like_index_as_shredding_state::<
FixedSizeListArray,
>(typed_value.as_ref(), *index)?,
_ => {
// JSONPath semantics: indexing a non-list yields no match.
return Ok(missing_path_step());
Expand Down Expand Up @@ -1937,12 +1940,13 @@ mod test {
type ShreddedListLikeArrayGen = fn() -> ArrayRef;
type ShreddedListLikeCase = (&'static str, ShreddedListLikeArrayGen);

fn shredded_list_like_cases() -> [ShreddedListLikeCase; 4] {
fn shredded_list_like_cases() -> [ShreddedListLikeCase; 5] {
[
("list", shredded_list_variant_array),
("large_list", shredded_large_list_variant_array),
("list_view", shredded_list_view_variant_array),
("large_list_view", shredded_large_list_view_variant_array),
("fixed_size_list", shredded_fixed_size_list_variant_array),
]
}

Expand Down Expand Up @@ -2108,6 +2112,13 @@ mod test {
))))
}

fn shredded_fixed_size_list_variant_array() -> ArrayRef {
shredded_list_like_variant_array(DataType::FixedSizeList(
Arc::new(Field::new("item", DataType::Utf8, true)),
2,
))
}

fn shredded_struct_with_list_variant_array() -> ArrayRef {
let json_rows: ArrayRef = Arc::new(StringArray::from(vec![
Some(r#"{"a": ["comedy", "drama"]}"#),
Expand Down
Loading