-
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.
Summary: Add FilterProjectReplayer. For the plan fragment involving FilterNode->ProjectNode, users should use the ProjectNode ID for tracing. This is because the planner will combine these two operators into a single FilterProject operator. During replay, the ProjectNode ID will locate the trace data directory. Part of #9668 Pull Request resolved: #11351 Reviewed By: tanjialiang Differential Revision: D65320080 Pulled By: xiaoxmeng fbshipit-source-id: eefa5541f892f08b587c83f78110898e3f041d66
- Loading branch information
1 parent
2090d78
commit ad27145
Showing
10 changed files
with
527 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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/FilterProjectReplayer.h" | ||
#include "velox/exec/TraceUtil.h" | ||
#include "velox/exec/tests/utils/PlanBuilder.h" | ||
|
||
using namespace facebook::velox; | ||
using namespace facebook::velox::exec; | ||
using namespace facebook::velox::exec::test; | ||
|
||
namespace facebook::velox::tool::trace { | ||
core::PlanNodePtr FilterProjectReplayer::createPlanNode( | ||
const core::PlanNode* node, | ||
const core::PlanNodeId& nodeId, | ||
const core::PlanNodePtr& source) const { | ||
if (node->name() == "Filter") { | ||
const auto* filterNode = dynamic_cast<const core::FilterNode*>(node); | ||
VELOX_CHECK( | ||
!isFilterProject(dynamic_cast<const core::FilterNode*>(node)), | ||
"If the target node is a FilterNode, it must be a standalone FilterNode"); | ||
|
||
// A standalone FilterNode. | ||
return std::make_shared<core::FilterNode>( | ||
nodeId, filterNode->filter(), source); | ||
} | ||
|
||
const auto* projectNode = dynamic_cast<const core::ProjectNode*>(node); | ||
|
||
// A standalone ProjectNode. | ||
if (node->sources().empty() || node->sources().front()->name() != "Filter") { | ||
return std::make_shared<core::ProjectNode>( | ||
nodeId, projectNode->names(), projectNode->projections(), source); | ||
} | ||
|
||
// A ProjectNode with a FilterNode as its source. | ||
// -- ProjectNode [nodeId] | ||
// -- FilterNode [nodeId - 1] | ||
const auto originalFilterNode = | ||
std::dynamic_pointer_cast<const core::FilterNode>( | ||
node->sources().front()); | ||
const auto filterNode = std::make_shared<core::FilterNode>( | ||
nodeId, originalFilterNode->filter(), source); | ||
const auto projectNodeId = planNodeIdGenerator_->next(); | ||
return std::make_shared<core::ProjectNode>( | ||
projectNodeId, | ||
projectNode->names(), | ||
projectNode->projections(), | ||
filterNode); | ||
} | ||
|
||
bool FilterProjectReplayer::isFilterProject( | ||
const core::PlanNode* filterNode) const { | ||
const auto* projectNode = | ||
dynamic_cast<const core::ProjectNode*>(core::PlanNode::findFirstNode( | ||
planFragment_.get(), [this](const core::PlanNode* node) { | ||
return node->id() == std::to_string(std::stoull(nodeId_) + 1); | ||
})); | ||
return projectNode != nullptr && projectNode->name() == "Project" && | ||
projectNode->sources().size() == 1 && | ||
projectNode->sources().front()->id() == 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 "velox/core/PlanNode.h" | ||
#include "velox/tool/trace/OperatorReplayerBase.h" | ||
|
||
namespace facebook::velox::tool::trace { | ||
/// The replayer to replay the traced 'FilterProject' operator. | ||
/// | ||
/// NOTE: For the plan fragment involving FilterNode->ProjectNode, users must | ||
/// use the ProjectNode ID for tracing. This is because the planner will combine | ||
/// these two operators into a single FilterProject operator. During replay, | ||
/// the ProjectNode ID will be used to locate the trace data directory. | ||
class FilterProjectReplayer : public OperatorReplayerBase { | ||
public: | ||
FilterProjectReplayer( | ||
const std::string& rootDir, | ||
const std::string& queryId, | ||
const std::string& taskId, | ||
const std::string& nodeId, | ||
const int32_t pipelineId, | ||
const std::string& operatorType) | ||
: OperatorReplayerBase( | ||
rootDir, | ||
queryId, | ||
taskId, | ||
nodeId, | ||
pipelineId, | ||
operatorType) {} | ||
|
||
private: | ||
// Create either a standalone FilterNode, a standalone ProjectNode, or a | ||
// ProjectNode with a FilterNode as its source. | ||
// | ||
// NOTE: If the target node is a FilterNode, it must be a standalone | ||
// FilterNode, without a ProjectNode as its parent. | ||
core::PlanNodePtr createPlanNode( | ||
const core::PlanNode* node, | ||
const core::PlanNodeId& nodeId, | ||
const core::PlanNodePtr& source) const override; | ||
|
||
// Checks whether the FilterNode is a source node of a ProjectNode. | ||
bool isFilterProject(const core::PlanNode* filterNode) const; | ||
}; | ||
} // 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
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
Oops, something went wrong.