-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
266 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "velox/tool/trace/TraceTaskRunner.h" | ||
|
||
namespace facebook::velox::tool::trace { | ||
|
||
std::pair<std::shared_ptr<exec::Task>, RowVectorPtr> TraceTaskRunner::run( | ||
bool copyResults) { | ||
auto cursor = exec::test::TaskCursor::create(cursorParams_); | ||
std::vector<RowVectorPtr> results; | ||
auto* task = cursor->task().get(); | ||
addSplits(task); | ||
|
||
while (cursor->moveNext()) { | ||
results.push_back(cursor->current()); | ||
} | ||
|
||
task->taskCompletionFuture().wait(); | ||
|
||
if (!copyResults) { | ||
return {cursor->task(), nullptr}; | ||
} | ||
|
||
auto totalCount = 0; | ||
for (const auto& result : results) { | ||
totalCount += result->size(); | ||
} | ||
auto copy = BaseVector::create<RowVector>( | ||
results[0]->type(), totalCount, memory::traceMemoryPool()); | ||
auto copyCount = 0; | ||
for (const auto& result : results) { | ||
copy->copy(result.get(), copyCount, 0, result->size()); | ||
copyCount += result->size(); | ||
} | ||
return {cursor->task(), copy}; | ||
} | ||
|
||
TraceTaskRunner& TraceTaskRunner::maxDrivers(int32_t maxDrivers) { | ||
cursorParams_.maxDrivers = maxDrivers; | ||
return *this; | ||
} | ||
|
||
TraceTaskRunner& TraceTaskRunner::spillDirectory(const std::string& dir) { | ||
cursorParams_.spillDirectory = dir; | ||
return *this; | ||
} | ||
|
||
TraceTaskRunner& TraceTaskRunner::splits( | ||
const core::PlanNodeId& planNodeId, | ||
std::vector<exec::Split> splits) { | ||
splits_[planNodeId] = std::move(splits); | ||
return *this; | ||
} | ||
|
||
void TraceTaskRunner::addSplits(exec::Task* task) { | ||
for (auto& [nodeId, nodeSplits] : splits_) { | ||
for (auto& split : nodeSplits) { | ||
task->addSplit(nodeId, std::move(split)); | ||
} | ||
task->noMoreSplits(nodeId); | ||
} | ||
} | ||
|
||
} // namespace facebook::velox::tool::trace |
This file contains 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <folly/executors/IOThreadPoolExecutor.h> | ||
#include "velox/exec/Cursor.h" | ||
|
||
namespace facebook::velox::tool::trace { | ||
|
||
class TraceTaskRunner { | ||
public: | ||
explicit TraceTaskRunner( | ||
core::PlanNodePtr plan, | ||
std::shared_ptr<core::QueryCtx> queryCtx) { | ||
cursorParams_.planNode = std::move(plan); | ||
cursorParams_.queryCtx = std::move(queryCtx); | ||
} | ||
|
||
/// Run the replaying task. Return the copied results if 'copyResults' is | ||
/// true or return null. | ||
std::pair<std::shared_ptr<exec::Task>, RowVectorPtr> run( | ||
bool copyResults = false); | ||
|
||
/// Max number of drivers. Default is 1. | ||
TraceTaskRunner& maxDrivers(int32_t maxDrivers); | ||
|
||
/// Spilling directory, if not empty, then the task's spilling directory would | ||
/// be built from it. | ||
TraceTaskRunner& spillDirectory(const std::string& dir); | ||
|
||
/// Splits of this task. | ||
TraceTaskRunner& splits( | ||
const core::PlanNodeId& planNodeId, | ||
std::vector<exec::Split> splits); | ||
|
||
private: | ||
void addSplits(exec::Task* task); | ||
|
||
inline static std::atomic<uint64_t> cursorQueryId_ = 0; | ||
|
||
exec::test::CursorParameters cursorParams_; | ||
std::unordered_map<core::PlanNodeId, std::vector<exec::Split>> splits_; | ||
bool noMoreSplits_ = false; | ||
}; | ||
} // namespace facebook::velox::tool::trace |
Oops, something went wrong.