Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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(); | ||
Member 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. Maybe this should be a task group instead of a thread pool. Then users can pass a serial task group to signal single threaded operation | ||
| }; | ||
| 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; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -125,8 +125,14 @@ TEST_F(TestSimpleScanner, ToTable) { | ||
| auto scanner = std::make_shared<SimpleScanner>(sources, options_, ctx_); | ||
| std::shared_ptr<Table> actual; | ||
| ASSERT_OK(scanner->ToTable(&actual)); | ||
| AssertTablesEqual(*expected, *actual); | ||
| // There is no guarantee on the ordering when using multiple threads, but | ||
| // since the RecordBatch is always the same it will pass. | ||
fsaintjacques marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. fsaintjacques marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| options_->use_threads = true; | ||
| ASSERT_OK(scanner->ToTable(&actual)); | ||
| AssertTablesEqual(*expected, *actual); | ||
| } | ||
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?