Skip to content

GH-55305: [C++][Parquet] Avoid unnecessary copies when building data pages - #55306

Open
HuaHuaY wants to merge 2 commits into
apache:mainfrom
HuaHuaY:avoid_useless_copy
Open

HuaHuaY wants to merge 2 commits into
apache:mainfrom
HuaHuaY:avoid_useless_copy

Conversation

@HuaHuaY

@HuaHuaY HuaHuaY commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Avoid two unnecessary buffer copies.

What changes are included in this PR?

  1. BuildDataPageV1 uses the values buffer directly when there are no definition or repetition levels.
  2. BuildDataPageV2 removes the unnecessarily copy of combined when buffering dictionary-encoded pages.

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Copilot AI balanced review requested due to automatic review settings October 29, 2026 04:00
@HuaHuaY
HuaHuaY requested review from pitrou and wgtmac as code owners October 29, 2026 04:00
@github-actions github-actions Bot added the awaiting review Awaiting review label Oct 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Required, non-repeated columns still compress the unpopulated uncompressed_data_ buffer instead of the encoded values, producing invalid compressed V1 pages with mismatched declared uncompressed sizes.

1 open issue
What changed in this PR

This PR reduces unnecessary buffer copying when the C++ Parquet writer builds data pages.

Changes:

  • Reuses the values buffer for uncompressed V1 pages without definition or repetition levels.
  • Removes an unused buffer copy when buffering dictionary-encoded V2 pages.
File Description
cpp/​src/​parquet/​column_writer.cc Avoids redundant copies in V1 and V2 data-page construction.

Review effort: Balanced

Comment thread cpp/src/parquet/column_writer.cc Outdated
@HuaHuaY
HuaHuaY force-pushed the avoid_useless_copy branch from fb71ca5 to d5297ba Compare October 29, 2026 04:08
Copilot AI balanced review requested due to automatic review settings October 29, 2026 04:08
@HuaHuaY
HuaHuaY force-pushed the avoid_useless_copy branch from d5297ba to 67ccca0 Compare October 29, 2026 04:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the removal of redundant Parquet data-page buffer copies.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Oct 29, 2026
Comment thread cpp/src/parquet/column_writer.cc Outdated
// if dictionary encoding has fallen back to PLAIN
if (has_dictionary_ && !fallback_) { // Save pages until end of dictionary encoding
PARQUET_ASSIGN_OR_THROW(auto data_copy,
combined->CopySlice(0, combined->size(), allocator_));

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.

So data_copy was unused? 🤨

@HuaHuaY HuaHuaY Oct 29, 2026 •

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.

I checked the git history and suspect that the author of BuildDataPageV2 copied BuildDataPageV1 and modified it, failing to notice the unused variable. Meanwhile, clang-tidy didn't flag any warning here either.

@HuaHuaY
HuaHuaY force-pushed the avoid_useless_copy branch from 67ccca0 to da8eb30 Compare October 29, 2026 09:31
Copilot AI balanced review requested due to automatic review settings October 29, 2026 09:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the Parquet writer’s buffer-copy optimization.

No open issues 🎉

Review effort: Balanced

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.

4 participants