-
Notifications
You must be signed in to change notification settings - Fork 83
fix(parquet): lazily load pending repdefs during page seek #625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oarap
wants to merge
1
commit into
bytedance:main
Choose a base branch
from
oarap:parquet-repdef-lazy-load
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1504,6 +1504,66 @@ TEST_F(ParquetReaderTest, skip) { | |
| EXPECT_EQ(0, rowReader->next(1000, result)); | ||
| } | ||
|
|
||
| TEST_F(ParquetReaderTest, sparseSkipAcrossRepeatedPagesWithBatchedRepDefs) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI — I ran sparseSkipAcrossRepeatedPagesWithBatchedRepDefs on main without this patch |
||
| constexpr int32_t kNumRows = 6'000; | ||
| constexpr int32_t kTargetRow = 5'000; | ||
| const std::string payload(256, 'x'); | ||
|
|
||
| auto ids = makeFlatVector<int64_t>( | ||
| kNumRows, [](auto row) { return static_cast<int64_t>(row); }); | ||
| std::vector<std::string> values; | ||
| values.reserve(kNumRows); | ||
| std::vector<std::vector<StringView>> arrays; | ||
| arrays.reserve(kNumRows); | ||
| for (auto i = 0; i < kNumRows; ++i) { | ||
| values.push_back(fmt::format("{}-{}", i, payload)); | ||
| arrays.push_back({StringView(values.back())}); | ||
| } | ||
|
|
||
| auto rowType = ROW({"id", "items"}, {BIGINT(), ARRAY(VARCHAR())}); | ||
| auto data = makeRowVector({ids, makeArrayVector<StringView>(arrays)}); | ||
|
|
||
| auto tempFile = exec::test::TempFilePath::create(); | ||
| auto writeFile = | ||
| std::make_unique<LocalWriteFile>(tempFile->path, true, false); | ||
| auto sink = std::make_unique<dwio::common::WriteFileSink>( | ||
| std::move(writeFile), tempFile->path); | ||
|
|
||
| bytedance::bolt::parquet::WriterOptions writerOptions; | ||
| writerOptions.memoryPool = rootPool_.get(); | ||
| writerOptions.enableDictionary = false; | ||
| writerOptions.dataPageSize = 1024; | ||
| writerOptions.columnDataPageSizeMap["items.list.element"] = 1024; | ||
| writerOptions.writeBatchBytes = 1ULL << 30; | ||
| writerOptions.minBatchSize = 1; | ||
| auto writer = std::make_unique<bytedance::bolt::parquet::Writer>( | ||
| std::move(sink), writerOptions, rowType); | ||
| writer->write(data); | ||
| writer->close(); | ||
|
|
||
| bytedance::bolt::dwio::common::ReaderOptions readerOptions{leafPool_.get()}; | ||
| readerOptions.setFileSchema(rowType); | ||
| readerOptions.setFileFormat(dwio::common::FileFormat::PARQUET); | ||
| auto reader = createReader(tempFile->path, readerOptions); | ||
|
|
||
| auto rowReaderOpts = getReaderOpts(rowType); | ||
| rowReaderOpts.setDecodeRepDefPageCount(1); | ||
| rowReaderOpts.setParquetRepDefMemoryLimit(1); | ||
| auto scanSpec = makeScanSpec(rowType); | ||
| scanSpec->getOrCreateChild(Subfield("id")) | ||
| ->setFilter(exec::equal(kTargetRow)); | ||
| rowReaderOpts.setScanSpec(scanSpec); | ||
| auto rowReader = reader->createRowReader(rowReaderOpts); | ||
|
|
||
| VectorPtr result = BaseVector::create(rowType, 0, leafPool_.get()); | ||
| ASSERT_NO_THROW({ | ||
| auto rowsRead = rowReader->next(1, result); | ||
| ASSERT_EQ(rowsRead, 1); | ||
| }); | ||
|
|
||
| assertEqualVectorPart(data, result, kTargetRow); | ||
| } | ||
|
|
||
| TEST_F(ParquetReaderTest, readVarbinaryFromFLBA) { | ||
| const std::string filename("varbinary_flba.parquet"); | ||
| const std::string sample(getExampleFilePath(filename)); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice fix — I hit the exact same crash in production and arrived at a similar conclusion.
I considered an alternative placement: doing the loadMoreRepDefs() loop in seekToPage(),
right before readPageHeader() (i.e., the caller side), rather than inside setPageRowInfo()
(the callee/crash site). I ended up going with that approach in #635
Trade-off I'd like to discuss:
Your approach (callee-side): More defensively robust — protects the CHECK_LT regardless
of how setPageRowInfo is reached. If a future code path forgets to preload, this still
saves the day.
Caller-side approach: Keeps setPageRowInfo() as a pure metadata lookup with no I/O side-effects. The invariant becomes: "seekToPage is the page lifecycle owner and must guarantee repdef coverage before entering the next page." This preserves the fail-fast semantics of BOLT_CHECK_LT for genuinely broken invariants.
My concern with the callee-side fix is that if a future path forgets to preload and there happen to be
leftover batches, the callee-side fix would silently mask the bug.
Not a blocker — both approaches fix the production crash correctly. Just wanted to flag
this trade-off for the discussion. Happy to hear your thoughts, and feel free to check
#635 for the alternative implementation.