Skip to content
Merged
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
9 changes: 6 additions & 3 deletions parquet/src/arrow/array_reader/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,12 @@ fn build_primitive_reader(
}
_ => make_byte_array_reader(page_iterator, column_desc, arrow_type)?,
},
PhysicalType::FIXED_LEN_BYTE_ARRAY => {
make_fixed_len_byte_array_reader(page_iterator, column_desc, arrow_type)?
}
PhysicalType::FIXED_LEN_BYTE_ARRAY => match arrow_type {
Some(DataType::Dictionary(_, _)) => {
make_byte_array_dictionary_reader(page_iterator, column_desc, arrow_type)?
}
_ => make_fixed_len_byte_array_reader(page_iterator, column_desc, arrow_type)?,
},
};
Ok(Some(reader))
}
Expand Down
16 changes: 8 additions & 8 deletions parquet/src/arrow/array_reader/byte_array_dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ pub fn make_byte_array_dictionary_reader(
ArrowType::Dictionary(key_type, value_type) => {
make_reader! {
(pages, column_desc, data_type) => match (key_type.as_ref(), value_type.as_ref()) {
(ArrowType::UInt8, ArrowType::Binary | ArrowType::Utf8) => (u8, i32),
(ArrowType::UInt8, ArrowType::Binary | ArrowType::Utf8 | ArrowType::FixedSizeBinary(_)) => (u8, i32),
(ArrowType::UInt8, ArrowType::LargeBinary | ArrowType::LargeUtf8) => (u8, i64),
(ArrowType::Int8, ArrowType::Binary | ArrowType::Utf8) => (i8, i32),
(ArrowType::Int8, ArrowType::Binary | ArrowType::Utf8 | ArrowType::FixedSizeBinary(_)) => (i8, i32),
(ArrowType::Int8, ArrowType::LargeBinary | ArrowType::LargeUtf8) => (i8, i64),
(ArrowType::UInt16, ArrowType::Binary | ArrowType::Utf8) => (u16, i32),
(ArrowType::UInt16, ArrowType::Binary | ArrowType::Utf8 | ArrowType::FixedSizeBinary(_)) => (u16, i32),
(ArrowType::UInt16, ArrowType::LargeBinary | ArrowType::LargeUtf8) => (u16, i64),
(ArrowType::Int16, ArrowType::Binary | ArrowType::Utf8) => (i16, i32),
(ArrowType::Int16, ArrowType::Binary | ArrowType::Utf8 | ArrowType::FixedSizeBinary(_)) => (i16, i32),
(ArrowType::Int16, ArrowType::LargeBinary | ArrowType::LargeUtf8) => (i16, i64),
(ArrowType::UInt32, ArrowType::Binary | ArrowType::Utf8) => (u32, i32),
(ArrowType::UInt32, ArrowType::Binary | ArrowType::Utf8 | ArrowType::FixedSizeBinary(_)) => (u32, i32),
(ArrowType::UInt32, ArrowType::LargeBinary | ArrowType::LargeUtf8) => (u32, i64),
(ArrowType::Int32, ArrowType::Binary | ArrowType::Utf8) => (i32, i32),
(ArrowType::Int32, ArrowType::Binary | ArrowType::Utf8 | ArrowType::FixedSizeBinary(_)) => (i32, i32),
(ArrowType::Int32, ArrowType::LargeBinary | ArrowType::LargeUtf8) => (i32, i64),
(ArrowType::UInt64, ArrowType::Binary | ArrowType::Utf8) => (u64, i32),
(ArrowType::UInt64, ArrowType::Binary | ArrowType::Utf8 | ArrowType::FixedSizeBinary(_)) => (u64, i32),
(ArrowType::UInt64, ArrowType::LargeBinary | ArrowType::LargeUtf8) => (u64, i64),
(ArrowType::Int64, ArrowType::Binary | ArrowType::Utf8) => (i64, i32),
(ArrowType::Int64, ArrowType::Binary | ArrowType::Utf8 | ArrowType::FixedSizeBinary(_)) => (i64, i32),
(ArrowType::Int64, ArrowType::LargeBinary | ArrowType::LargeUtf8) => (i64, i64),
}
}
Expand Down
7 changes: 5 additions & 2 deletions parquet/src/arrow/arrow_writer/byte_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use crate::schema::types::ColumnDescPtr;
use crate::util::bit_util::num_required_bits;
use crate::util::interner::{Interner, Storage};
use arrow_array::{
Array, ArrayAccessor, BinaryArray, BinaryViewArray, DictionaryArray, LargeBinaryArray,
LargeStringArray, StringArray, StringViewArray,
Array, ArrayAccessor, BinaryArray, BinaryViewArray, DictionaryArray, FixedSizeBinaryArray,
LargeBinaryArray, LargeStringArray, StringArray, StringViewArray,
};
use arrow_schema::DataType;

Expand Down Expand Up @@ -85,6 +85,9 @@ macro_rules! downcast_op {
DataType::LargeBinary => {
downcast_dict_op!(key, LargeBinaryArray, $array, $op$(, $arg)*)
}
DataType::FixedSizeBinary(_) => {
downcast_dict_op!(key, FixedSizeBinaryArray, $array, $op$(, $arg)*)
}
d => unreachable!("cannot downcast {} dictionary value to byte array", d),
},
d => unreachable!("cannot downcast {} to byte array", d),
Expand Down
48 changes: 48 additions & 0 deletions parquet/src/arrow/arrow_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,9 @@ impl ArrowColumnWriterFactory {
ArrowDataType::Utf8View | ArrowDataType::BinaryView => {
out.push(bytes(leaves.next().unwrap())?)
}
ArrowDataType::FixedSizeBinary(_) => {
out.push(bytes(leaves.next().unwrap())?)
}
_ => {
out.push(col(leaves.next().unwrap())?)
}
Expand Down Expand Up @@ -1333,6 +1336,7 @@ mod tests {
use arrow_buffer::{i256, IntervalDayTime, IntervalMonthDayNano, NullBuffer};
use arrow_schema::Fields;
use half::f16;
use num::{FromPrimitive, ToPrimitive};

use crate::basic::Encoding;
use crate::data_type::AsBytes;
Expand Down Expand Up @@ -1911,6 +1915,50 @@ mod tests {
roundtrip(batch, Some(SMALL_SIZE / 2));
}

#[test]
fn test_fixed_size_binary_in_dict() {
fn test_fixed_size_binary_in_dict_inner<K>()
where
K: ArrowDictionaryKeyType,
K::Native: FromPrimitive + ToPrimitive + TryFrom<u8>,
<<K as arrow_array::ArrowPrimitiveType>::Native as TryFrom<u8>>::Error: std::fmt::Debug,
{
let field = Field::new(
"a",
DataType::Dictionary(
Box::new(K::DATA_TYPE),
Box::new(DataType::FixedSizeBinary(4)),
),
false,
);
let schema = Schema::new(vec![field]);

let keys: Vec<K::Native> = vec![
K::Native::try_from(0u8).unwrap(),
K::Native::try_from(0u8).unwrap(),
K::Native::try_from(1u8).unwrap(),
];
let keys = PrimitiveArray::<K>::from_iter_values(keys);
let values = FixedSizeBinaryArray::try_from_iter(
vec![vec![0, 0, 0, 0], vec![1, 1, 1, 1]].into_iter(),
)
.unwrap();

let data = DictionaryArray::<K>::new(keys, Arc::new(values));
let batch = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(data)]).unwrap();
roundtrip(batch, None);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified this is doing a read/write round trip

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes thanks for checking @alamb.

Sorry, I should have replied earlier to your other comment about this and confirmed that we already had the roundtrip test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries -- it was my bad for missing it

}

test_fixed_size_binary_in_dict_inner::<UInt8Type>();
test_fixed_size_binary_in_dict_inner::<UInt16Type>();
test_fixed_size_binary_in_dict_inner::<UInt32Type>();
test_fixed_size_binary_in_dict_inner::<UInt16Type>();
test_fixed_size_binary_in_dict_inner::<Int8Type>();
test_fixed_size_binary_in_dict_inner::<Int16Type>();
test_fixed_size_binary_in_dict_inner::<Int32Type>();
test_fixed_size_binary_in_dict_inner::<Int64Type>();
}

#[test]
fn test_empty_dict() {
let struct_fields = Fields::from(vec![Field::new(
Expand Down
9 changes: 9 additions & 0 deletions parquet/src/arrow/buffer/dictionary_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ impl<K: ArrowNativeType + Ord, V: OffsetSizeTrait> DictionaryBuffer<K, V> {
}
}

let ArrowType::Dictionary(_, value_type) = data_type else {
unreachable!()
};
let values = if let ArrowType::FixedSizeBinary(size) = **value_type {
arrow_cast::cast(&values, &ArrowType::FixedSizeBinary(size)).unwrap()
} else {
values
};

let builder = ArrayDataBuilder::new(data_type.clone())
.len(keys.len())
.add_buffer(Buffer::from_vec(keys))
Expand Down
Loading