Skip to content

Commit

Permalink
Ignore tracing of subordinate operator of the traced opeator within t…
Browse files Browse the repository at this point in the history
…he same driver
  • Loading branch information
duanmeng committed Oct 11, 2024
1 parent 9cf4ee0 commit 725f6e7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions velox/exec/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ struct DriverCtx {
std::shared_ptr<Task> task;
Driver* driver{nullptr};
facebook::velox::process::ThreadDebugInfo threadDebugInfo;
std::unordered_set<int32_t> tracedOperatorIds;

DriverCtx(
std::shared_ptr<Task> _task,
Expand Down
10 changes: 9 additions & 1 deletion velox/exec/Operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,18 @@ void Operator::maybeSetTracer() {
return;
}

if (queryTraceConfig->queryNodes.count(planNodeId()) == 0) {
const auto nodeId = planNodeId();
if (queryTraceConfig->queryNodes.count(nodeId) == 0) {
return;
}

auto& tracedOpIds = operatorCtx_->driverCtx()->tracedOperatorIds;
if (const auto iter = tracedOpIds.find(operatorId());
iter != tracedOpIds.end()) {
return;
}
tracedOpIds.emplace(operatorId());

const auto pipelineId = operatorCtx_->driverCtx()->pipelineId;
const auto driverId = operatorCtx_->driverCtx()->driverId;
LOG(INFO) << "Trace data for operator type: " << operatorType()
Expand Down
39 changes: 36 additions & 3 deletions velox/tool/trace/tests/TableWriterReplayerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,24 @@ class TableWriterReplayerTest : public HiveConnectorTestBase {
connector::CommitStrategy::kNoCommit) {
return [=](core::PlanNodeId nodeId,
core::PlanNodePtr source) -> core::PlanNodePtr {
std::shared_ptr<core::AggregationNode> aggNode = nullptr;
if (aggregationNode == nullptr) {
aggNode = generateAggregationNode(
"c0", nodeId, {}, core::AggregationNode::Step::kPartial, source);
} else {
aggNode = aggregationNode;
}

return std::make_shared<core::TableWriteNode>(
nodeId,
inputColumns,
tableColumnNames,
aggregationNode,
aggNode,
insertHandle,
hasPartitioningScheme,
TableWriteTraits::outputType(aggregationNode),
TableWriteTraits::outputType(aggNode),
commitStrategy,
std::move(source));
source);
};
}

Expand Down Expand Up @@ -227,6 +235,31 @@ class TableWriterReplayerTest : public HiveConnectorTestBase {
}
}

static std::shared_ptr<core::AggregationNode> generateAggregationNode(
const std::string& name,
const core::PlanNodeId nodeId,
const std::vector<core::FieldAccessTypedExprPtr>& groupingKeys,
AggregationNode::Step step,
const PlanNodePtr& source) {
core::TypedExprPtr inputField =
std::make_shared<const core::FieldAccessTypedExpr>(BIGINT(), name);
auto callExpr = std::make_shared<const core::CallTypedExpr>(
BIGINT(), std::vector<core::TypedExprPtr>{inputField}, "min");
std::vector<std::string> aggregateNames = {"min"};
std::vector<core::AggregationNode::Aggregate> aggregates = {
core::AggregationNode::Aggregate{
callExpr, {{BIGINT()}}, nullptr, {}, {}}};
return std::make_shared<core::AggregationNode>(
nodeId,
step,
groupingKeys,
std::vector<core::FieldAccessTypedExprPtr>{},
aggregateNames,
aggregates,
false, // ignoreNullKeys
source);
}

std::string tableWriteNodeId_;
FileFormat fileFormat_{FileFormat::DWRF};
};
Expand Down

0 comments on commit 725f6e7

Please sign in to comment.