Skip to content

GH-55685: [C++][Parquet] Fix DeltaLengthByteArrayEncoder memory pool tracking and zero-length UnsafeAppend - #55686

Open
ryanvickr wants to merge 2 commits into
apache:mainfrom
ryanvickr:gh-55685-dlba-encoder-pool-and-zero-len
Open

ryanvickr wants to merge 2 commits into
apache:mainfrom
ryanvickr:gh-55685-dlba-encoder-pool-and-zero-len

Conversation

@ryanvickr

@ryanvickr ryanvickr commented Nov 20, 2026 •

Copy link
Copy Markdown

Rationale for this change

DeltaLengthByteArrayEncoder currently overwrites the caller's MemoryPool* with default_memory_pool() in its constructor initializer list (affecting both DELTA_LENGTH_BYTE_ARRAY and DELTA_BYTE_ARRAY's suffix_encoder_), and calls BufferBuilder::UnsafeAppend on zero-length ByteArray items (which triggers UB under UBSan when ptr == nullptr).

Split out from #55488 so these fixes can be reviewed separately from the PutBinaryArray optimization.

What changes are included in this PR?

  • Forward pool directly in DeltaLengthByteArrayEncoder's constructor instead of reassigning it to default_memory_pool().
  • Skip sink_.Reserve / sink_.UnsafeAppend for zero-length items in DeltaLengthByteArrayEncoder::Put(const ByteArray*, int).

Are these changes tested?

Yes, added a unit test in cpp/src/parquet/encoding_test.cc for zero-length ByteArray(0, nullptr) inputs.

Are there any user-facing changes?

Callers passing a custom MemoryPool* when encoding DELTA_LENGTH_BYTE_ARRAY or DELTA_BYTE_ARRAY columns will now have encoder allocations tracked on that pool.

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

Closes #55685

@wgtmac wgtmac 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.

Mostly LGTM. I've left a comment w.r.t the test.

Comment thread cpp/src/parquet/encoding_test.cc Outdated
}
}

TEST(DeltaLengthByteArrayEncodingAdHoc, UsesProvidedMemoryPool) {

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.

IMHO, we can remove this test.

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.

Agreed, and the test is very long-winded as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed.

Comment thread cpp/src/parquet/encoding_test.cc Outdated
const std::string abc = "abc";
std::vector<ByteArray> mixed = {
ByteArray(0, nullptr),
ByteArray(3, reinterpret_cast<const uint8_t*>(abc.data())),

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.

I think you can just write ByteArray(abc) or, at worse, ByteArray(std::string_view(abc))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, simplified to ByteArray("abc").

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.

[C++][Parquet] Fix DeltaLengthByteArrayEncoder memory pool tracking and zero-length UnsafeAppend

3 participants