-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-12996: Add bytes_read() to StreamingReader #10509
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,6 +216,74 @@ TEST(StreamingReaderTests, NestedParallelism) { | |
| TestNestedParallelism(thread_pool, table_factory); | ||
| } | ||
|
|
||
| TEST(StreamingReaderTest, BytesRead) { | ||
| ASSERT_OK_AND_ASSIGN(auto thread_pool, internal::ThreadPool::Make(1)); | ||
| auto table_buffer = | ||
| std::make_shared<Buffer>("a,b,c\n123,456,789\n101,112,131\n415,161,718\n"); | ||
|
|
||
| // Basic read without any skips and small block size | ||
| { | ||
| auto input = std::make_shared<io::BufferReader>(table_buffer); | ||
|
|
||
| auto read_options = ReadOptions::Defaults(); | ||
| read_options.block_size = 20; | ||
| ASSERT_OK_AND_ASSIGN( | ||
| auto streaming_reader, | ||
| StreamingReader::Make(io::default_io_context(), input, read_options, | ||
| ParseOptions::Defaults(), ConvertOptions::Defaults())); | ||
| std::shared_ptr<RecordBatch> batch; | ||
| int64_t bytes = 6; // Size of header | ||
| do { | ||
| ASSERT_EQ(bytes, streaming_reader->bytes_read()); | ||
| ASSERT_OK(streaming_reader->ReadNext(&batch)); | ||
| bytes += 12; // Add size of each row | ||
| } while (batch); | ||
| ASSERT_EQ(42, streaming_reader->bytes_read()); | ||
| } | ||
|
|
||
| // Interaction of skip_rows and bytes_read() | ||
| { | ||
| auto input = std::make_shared<io::BufferReader>(table_buffer); | ||
|
|
||
| auto read_options = ReadOptions::Defaults(); | ||
| read_options.skip_rows = 2; | ||
| ASSERT_OK_AND_ASSIGN( | ||
| auto streaming_reader, | ||
| StreamingReader::Make(io::default_io_context(), input, read_options, | ||
| ParseOptions::Defaults(), ConvertOptions::Defaults())); | ||
| std::shared_ptr<RecordBatch> batch; | ||
| // first two rows and third row as header | ||
| ASSERT_EQ(30, streaming_reader->bytes_read()); | ||
| ASSERT_OK(streaming_reader->ReadNext(&batch)); | ||
| ASSERT_NE(batch.get(), nullptr); | ||
| ASSERT_EQ(42, streaming_reader->bytes_read()); | ||
| ASSERT_OK(streaming_reader->ReadNext(&batch)); | ||
| ASSERT_EQ(batch.get(), nullptr); | ||
| } | ||
|
|
||
| // Interaction of skip_rows_after_names and bytes_read() | ||
| { | ||
| auto input = std::make_shared<io::BufferReader>(table_buffer); | ||
|
|
||
| auto read_options = ReadOptions::Defaults(); | ||
| read_options.skip_rows_after_names = 2; | ||
|
|
||
| ASSERT_OK_AND_ASSIGN( | ||
| auto streaming_reader, | ||
| StreamingReader::Make(io::default_io_context(), input, read_options, | ||
| ParseOptions::Defaults(), ConvertOptions::Defaults())); | ||
| std::shared_ptr<RecordBatch> batch; | ||
|
|
||
| // Just header | ||
| ASSERT_EQ(6, streaming_reader->bytes_read()); | ||
| ASSERT_OK(streaming_reader->ReadNext(&batch)); | ||
| ASSERT_NE(batch.get(), nullptr); | ||
| ASSERT_EQ(42, streaming_reader->bytes_read()); | ||
| ASSERT_OK(streaming_reader->ReadNext(&batch)); | ||
| ASSERT_EQ(batch.get(), nullptr); | ||
| } | ||
| } | ||
|
||
|
|
||
| TEST(CountRowsAsync, Basics) { | ||
| constexpr int NROWS = 4096; | ||
| ASSERT_OK_AND_ASSIGN(auto table_buffer, MakeSampleCsvBuffer(NROWS)); | ||
|
|
||
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.
The docstring may be a bit imprecise here. If there is some readahead going on, is it included in the result? Or is it the number of bytes corresponding to the batches already consumed by the caller?
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.
I think
bytes_readmeans "bytes the CSV reader is completely finished with". So serial readahead (e.g. the readahead happening on the I/O context or "data read but not parsed or decoded") should not be included. Caller consumption should be irrelevant.For parallel readahead (e.g. the CSV reader reading/parsing/decoding multiple batches of data at the same time) then my opinion is that
bytes_readshould be incremented as soon as a batch is ready to be delivered (even if there are other batches in front of it that aren't ready).Perhaps
bytes_processedorbytes_finishedwould remove the ambiguity? Or maybe just a clearer docstring.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.
A clearer docstring would be fine with me.
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.
I updated it to