Skip to content
Draft
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
18 changes: 6 additions & 12 deletions parquet/src/arrow/arrow_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2933,16 +2933,6 @@ mod tests {
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(),
Expand All @@ -2954,8 +2944,12 @@ mod tests {
)
.unwrap();

let data = DictionaryArray::<K>::new(keys, Arc::new(values));
let batch = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(data)]).unwrap();
let data = Arc::new(DictionaryArray::<K>::new(keys, Arc::new(values))) as ArrayRef;
one_column_roundtrip(Arc::clone(&data), true);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From the reproduction, added one_column_roundtrip() usage here to test roundtrip where one of the cases is disabling dictionary encoding entirely

Rest of test changes is just restructuring


let field = Field::new("a", data.data_type().clone(), false);
let schema = Schema::new(vec![field]);
let batch = RecordBatch::try_new(Arc::new(schema), vec![data]).unwrap();
roundtrip(batch, None);
}

Expand Down
12 changes: 11 additions & 1 deletion parquet/src/arrow/buffer/dictionary_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,18 @@ impl<K: ArrowNativeType + Ord, V: OffsetSizeTrait> DictionaryBuffer<K, V> {
ArrowType::Dictionary(k, v) => (k, v.as_ref().clone()),
_ => unreachable!(),
};
let array = if let ArrowType::FixedSizeBinary(size) = value_type {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Matching what was done above in the Self::Dict path:

let values = if let ArrowType::FixedSizeBinary(size) = **value_type {
let binary = values.as_binary::<i32>();
Arc::new(FixedSizeBinaryArray::new(
size,
binary.values().clone(),
binary.nulls().cloned(),
)) as _
} else {
values
};

This is because values.into_array() assumed a generic byte offset array:

/// Converts this into an [`ArrayRef`] with the provided `data_type` and `null_buffer`
pub fn into_array(self, null_buffer: Option<Buffer>, data_type: ArrowType) -> ArrayRef {
let array_data_builder = ArrayDataBuilder::new(data_type)
.len(self.len())
.add_buffer(Buffer::from_vec(self.offsets))
.add_buffer(Buffer::from_vec(self.values))
.null_bit_buffer(null_buffer);
let data = match cfg!(debug_assertions) {
true => array_data_builder.build().unwrap(),
false => unsafe { array_data_builder.build_unchecked() },
};
make_array(data)
}

Which is the wrong structure for a fixedsizebinary array (we don't have offsets buffer, etc.)

let array = values.into_array(null_buffer, ArrowType::Binary);
let array = array.as_binary::<i32>();
Arc::new(FixedSizeBinaryArray::new(
size,
array.values().clone(),
array.nulls().cloned(),
)) as _
} else {
values.into_array(null_buffer, value_type)
};

let array = values.into_array(null_buffer, value_type);
pack_values(key_type, &array)
}
}
Expand Down
Loading