forked from facebookincubator/velox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add query trace TaskRunner (facebookincubator#11927)
Summary: Add a query trace TaskRunner to execute the replay task replacing `AssertQueryBuilder`. Use a flag named `copy_results` to control whether to copy the replay result (used in UT). Pull Request resolved: facebookincubator#11927 Reviewed By: tanjialiang Differential Revision: D67719866 Pulled By: xiaoxmeng fbshipit-source-id: 04735e9eb4da6516998e4f63f6d23d0605e681c8
- Loading branch information
1 parent
7cbfce0
commit 7fdb321
Showing
14 changed files
with
280 additions
and
42 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
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,84 @@ | ||
/* | ||
* 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/TraceReplayTaskRunner.h" | ||
|
||
namespace facebook::velox::tool::trace { | ||
|
||
std::pair<std::shared_ptr<exec::Task>, RowVectorPtr> TraceReplayTaskRunner::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(), copy(results)}; | ||
} | ||
|
||
return {cursor->task(), nullptr}; | ||
} | ||
|
||
std::shared_ptr<RowVector> TraceReplayTaskRunner::copy( | ||
const std::vector<RowVectorPtr>& results) { | ||
auto totalRows = 0; | ||
for (const auto& result : results) { | ||
totalRows += result->size(); | ||
} | ||
auto copyResult = BaseVector::create<RowVector>( | ||
results[0]->type(), totalRows, memory::traceMemoryPool()); | ||
auto resultRowOffset = 0; | ||
for (const auto& result : results) { | ||
copyResult->copy(result.get(), resultRowOffset, 0, result->size()); | ||
resultRowOffset += result->size(); | ||
} | ||
return copyResult; | ||
} | ||
|
||
TraceReplayTaskRunner& TraceReplayTaskRunner::maxDrivers(int32_t maxDrivers) { | ||
cursorParams_.maxDrivers = maxDrivers; | ||
return *this; | ||
} | ||
|
||
TraceReplayTaskRunner& TraceReplayTaskRunner::spillDirectory( | ||
const std::string& dir) { | ||
cursorParams_.spillDirectory = dir; | ||
return *this; | ||
} | ||
|
||
TraceReplayTaskRunner& TraceReplayTaskRunner::splits( | ||
const core::PlanNodeId& planNodeId, | ||
std::vector<exec::Split> splits) { | ||
splits_[planNodeId] = std::move(splits); | ||
return *this; | ||
} | ||
|
||
void TraceReplayTaskRunner::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,60 @@ | ||
/* | ||
* 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 TraceReplayTaskRunner { | ||
public: | ||
explicit TraceReplayTaskRunner( | ||
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. | ||
TraceReplayTaskRunner& maxDrivers(int32_t maxDrivers); | ||
|
||
/// Spilling directory, if not empty, then the task's spilling directory would | ||
/// be built from it. | ||
TraceReplayTaskRunner& spillDirectory(const std::string& dir); | ||
|
||
/// Splits of this task. | ||
TraceReplayTaskRunner& splits( | ||
const core::PlanNodeId& planNodeId, | ||
std::vector<exec::Split> splits); | ||
|
||
private: | ||
void addSplits(exec::Task* task); | ||
|
||
static std::shared_ptr<RowVector> copy( | ||
const std::vector<RowVectorPtr>& results); | ||
|
||
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.