-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-6964: [C++][Dataset] Add multithread support to Scanner::ToTable #5721
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
fsaintjacques
wants to merge
1
commit into
apache:master
from
fsaintjacques:ARROW-6964-parallel-scanner-to-table
Closed
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,16 +27,22 @@ | |
| #include "arrow/dataset/type_fwd.h" | ||
| #include "arrow/dataset/visibility.h" | ||
| #include "arrow/memory_pool.h" | ||
| #include "arrow/util/thread_pool.h" | ||
|
|
||
| namespace arrow { | ||
|
|
||
| class Table; | ||
|
|
||
| namespace internal { | ||
| class TaskGroup; | ||
| }; | ||
|
|
||
| namespace dataset { | ||
|
|
||
| /// \brief Shared state for a Scan operation | ||
| struct ARROW_DS_EXPORT ScanContext { | ||
| MemoryPool* pool = arrow::default_memory_pool(); | ||
| internal::ThreadPool* thread_pool = arrow::internal::GetCpuThreadPool(); | ||
|
||
| }; | ||
|
|
||
| class RecordBatchProjector; | ||
|
|
@@ -47,6 +53,10 @@ class ARROW_DS_EXPORT ScanOptions { | |
|
|
||
| static std::shared_ptr<ScanOptions> Defaults(); | ||
|
|
||
| // Indicate if the Scanner should make use of the ThreadPool found in the | ||
| // ScanContext. | ||
| bool use_threads = false; | ||
|
|
||
| // Filter | ||
| std::shared_ptr<Expression> filter; | ||
| // Evaluator for Filter | ||
|
|
@@ -109,18 +119,34 @@ Status ScanTaskIteratorFromRecordBatch(std::vector<std::shared_ptr<RecordBatch>> | |
| /// yield scan_task | ||
| class ARROW_DS_EXPORT Scanner { | ||
| public: | ||
| Scanner(DataSourceVector sources, std::shared_ptr<ScanOptions> options, | ||
| std::shared_ptr<ScanContext> context) | ||
| : sources_(std::move(sources)), | ||
| options_(std::move(options)), | ||
| context_(std::move(context)) {} | ||
|
|
||
| virtual ~Scanner() = default; | ||
|
|
||
| /// \brief The Scan operator returns a stream of ScanTask. The caller is | ||
| /// responsible to dispatch/schedule said tasks. Tasks should be safe to run | ||
| /// in a concurrent fashion and outlive the iterator. | ||
| virtual ScanTaskIterator Scan() = 0; | ||
|
|
||
| virtual ~Scanner() = default; | ||
|
|
||
| /// \brief Convert a Scanner into a Table. | ||
| /// | ||
| /// \param[out] out output parameter | ||
| /// | ||
| /// Use this convenience utility with care. This will serially materialize the | ||
| /// Scan result in memory before creating the Table. | ||
| Status ToTable(std::shared_ptr<Table>* out); | ||
|
|
||
| protected: | ||
| /// \brief Return a TaskGroup according to ScanContext thread rules. | ||
| std::shared_ptr<internal::TaskGroup> TaskGroup() const; | ||
|
|
||
| DataSourceVector sources_; | ||
| std::shared_ptr<ScanOptions> options_; | ||
| std::shared_ptr<ScanContext> context_; | ||
| }; | ||
|
|
||
| /// \brief SimpleScanner is a trivial Scanner implementation that flattens | ||
|
|
@@ -141,16 +167,9 @@ class ARROW_DS_EXPORT SimpleScanner : public Scanner { | |
| SimpleScanner(std::vector<std::shared_ptr<DataSource>> sources, | ||
| std::shared_ptr<ScanOptions> options, | ||
| std::shared_ptr<ScanContext> context) | ||
| : sources_(std::move(sources)), | ||
| options_(std::move(options)), | ||
| context_(std::move(context)) {} | ||
| : Scanner(std::move(sources), std::move(options), std::move(context)) {} | ||
|
|
||
| ScanTaskIterator Scan() override; | ||
|
|
||
| private: | ||
| std::vector<std::shared_ptr<DataSource>> sources_; | ||
| std::shared_ptr<ScanOptions> options_; | ||
| std::shared_ptr<ScanContext> context_; | ||
| }; | ||
|
|
||
| /// \brief ScannerBuilder is a factory class to construct a Scanner. It is used | ||
|
|
@@ -188,6 +207,10 @@ class ARROW_DS_EXPORT ScannerBuilder { | |
| Status Filter(std::shared_ptr<Expression> filter); | ||
| Status Filter(const Expression& filter); | ||
|
|
||
| /// \brief Indicate if the Scanner should make use of the available | ||
| /// ThreadPool found in ScanContext; | ||
| Status UseThreads(bool use_threads = true); | ||
|
|
||
| /// \brief Return the constructed now-immutable Scanner object | ||
| Status Finish(std::unique_ptr<Scanner>* out) const; | ||
|
|
||
|
|
||
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
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.
Maybe it's time to expose a common
ResourceContextclass that has a MemoryPool and a ThreadPool?