Repository navigation
GH-55287: [C++][Parquet] Write fixed-size lists faster - #55251
MashrafeeAryan wants to merge 7 commits into
Conversation
Compare writing fixed-size lists of floats with writing the same values as a flat column. Test six list sizes with V1 and V2 pages.
Add an encoder helper that writes the same value many times. Check that it produces the same bytes as writing values one at a time.
Write a repeated definition level without first building an array. Add tests for matching bytes and invalid inputs.
Use the fixed list size to write the start and continuation markers. Check that the encoded bytes match the existing encoder.
Skip temporary marker arrays for supported fixed-size lists without nulls. Keep the existing path for other inputs. Test matching output, lower memory use, and fallback cases.
|
|
|
|
|
|
|
|
2 similar comments
|
|
|
|
| const auto& type = | ||
| checked_cast<const ::arrow::FixedSizeListType&>(*arrays.front()->type()); | ||
| if (type.list_size() <= 0) { | ||
| return false; |
There was a problem hiding this comment.
check if it's legal
| int PutRepeated(uint64_t value, int count); | ||
|
|
||
| /// Flushes any pending values to the underlying buffer. | ||
| /// Returns the total number of bytes written |
There was a problem hiding this comment.
Say the buffer size is this size. check if that is good. if not increase the size.
There was a problem hiding this comment.
Thanks for working on this @MashrafeeAryan! The fast path looks promising. I did a first review.
To fast path optimization I'd add also caching of page levels when we can. I suppose it wouldn't work with CDC (which is rarely used), but it should be make things even faster. See proposed approach here: gist.
|
|
||
| inline int RleBitPackedEncoder::PutRepeated(uint64_t value, int count) { | ||
| ARROW_DCHECK_GE(count, 0); | ||
| ARROW_DCHECK(bit_width_ == 64 || value < (uint64_t{1} << bit_width_)); |
There was a problem hiding this comment.
For consistency, see line 1502 above.
| ARROW_DCHECK(bit_width_ == 64 || value < (uint64_t{1} << bit_width_)); | |
| ARROW_DCHECK(bit_width_ == 64 || value < (1ULL << bit_width_)); |
| while (encoded < count && !buffer_full_) { | ||
| if (current_value_ == value && repeat_count_ > 8) { |
There was a problem hiding this comment.
You could flatten the while condition and move things around some more
while (encoded < count && !(current_value_ == value && repeat_count_ > 8)) {|
|
||
| // Check that all chunks contain supported fixed-size lists with no missing values | ||
| bool CanWriteFixedSizeLists(const std::vector<std::shared_ptr<Array>>& arrays) { | ||
| if (arrays.empty() || arrays.front()->type_id() != ::arrow::Type::FIXED_SIZE_LIST) { |
There was a problem hiding this comment.
This rejects extension arrays whose storage type is fixed-size. The generic path would unwrap extension arrays via array.storage() in path_internal.cc.
| break; | ||
| default: | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Is there a reason to limit this to these four types? We have more fixed size length types. Howw about something like:
const auto& value_type = *type.value_type();
if (::arrow::is_nested(value_type.id()) ||
::arrow::is_base_binary_like(value_type.id()) ||
::arrow::is_binary_view_like(value_type.id()) ||
value_type.id() == ::arrow::Type::DICTIONARY ||
value_type.id() == ::arrow::Type::EXTENSION) {
return false;
}| if (!array->type()->Equals(arrays.front()->type())) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
IIUC these arrays come from a chunked array and we can expect them to be of the same type. Please double check me.
| const auto& type = checked_cast<const ::arrow::FixedSizeListType&>( | ||
| *fixed_size_lists_.front()->type()); | ||
| auto fast_ctx = *ctx; | ||
| fast_ctx.fixed_size_list_size = type.list_size(); |
There was a problem hiding this comment.
Adding list size to ArrowWriteContext is not ideal. Can we pass it in another way?
| fast_ctx.fixed_size_list_size = type.list_size(); | ||
| for (const auto& array : fixed_size_lists_) { | ||
| const auto& lists = checked_cast<const ::arrow::FixedSizeListArray&>(*array); | ||
| // Take only the numbers belonging to this slice of lists |
There was a problem hiding this comment.
nit
| // Take only the numbers belonging to this slice of lists | |
| // Take only the values belonging to this slice of lists |
| } | ||
| return std::make_unique<ArrowColumnWriterV2>(std::move(builders), column_index, | ||
| leaf_count, row_group_writer); | ||
| // Check every chunk before choosing one writing path for the column |
There was a problem hiding this comment.
Please add a comment explaining why buffered row groups are excluded.
Rationale for this change
While saving fixed-size lists to a Parquet file, it does extra work and takes time. Each value in the list gets a definition level and a repetition level. However, for a list of size n with no nulls, those levels are fully predictable. So we avoid creating markers for definition levels and repetition levels to save time writing fixed-size lists.
What changes are included in this PR?
Are these changes tested?
Yes all of these are tested
Are there any user-facing changes?
Supports fixed-size lists write faster and use less temporary memory.
Was AI used for this PR?
I haves used Codex and Caludef or reviewing and debugging.
PR code and description written by:
Reviewed before submission by:
Related Issue: rok#60