Skip to content

GH-55287: [C++][Parquet] Write fixed-size lists faster - #55251

Draft
MashrafeeAryan wants to merge 7 commits into
apache:mainfrom
MashrafeeAryan:fast-path-fixed-list
Draft

MashrafeeAryan wants to merge 7 commits into
apache:mainfrom
MashrafeeAryan:fast-path-fixed-list

Conversation

@MashrafeeAryan

@MashrafeeAryan MashrafeeAryan commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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?

  • Added a fast writing path for fixed-size lists
  • Encode definition and repetition levels directly without building temporary marker arrays
  • Calculate row counts and levels using the list size
  • Keep the existing writing part for unsupported cases
  • Add a benchmark to compare fixed-size-list writes with flat columns to show how much extra work writing lists used to add
  • Add tests to check byte-identical output

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:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Related Issue: rok#60

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.
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #34510 has been automatically assigned in GitHub to PR creator.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #34510 has been automatically assigned in GitHub to PR creator.

@MashrafeeAryan MashrafeeAryan changed the title GH-34510: [C++][Parquet] Write fixed-size lists faster GH-55287: [C++][Parquet] Write fixed-size lists faster Oct 27, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55287 has been automatically assigned in GitHub to PR creator.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55287 has no components, please add labels for components.

2 similar comments
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55287 has no components, please add labels for components.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55287 has no components, please add labels for components.

const auto& type =
checked_cast<const ::arrow::FixedSizeListType&>(*arrays.front()->type());
if (type.list_size() <= 0) {
return false;

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.

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

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.

Say the buffer size is this size. check if that is good. if not increase the size.

@rok rok left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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_));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For consistency, see line 1502 above.

Suggested change
ARROW_DCHECK(bit_width_ == 64 || value < (uint64_t{1} << bit_width_));
ARROW_DCHECK(bit_width_ == 64 || value < (1ULL << bit_width_));

Comment on lines +1537 to +1538
while (encoded < count && !buffer_full_) {
if (current_value_ == value && repeat_count_ > 8) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;
}

Comment on lines +158 to +160
if (!array->type()->Equals(arrays.front()->type())) {
return false;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit

Suggested change
// 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a comment explaining why buffered row groups are excluded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants