Skip to content

Commit ffe6e1c

Browse files
juwentus1234facebook-github-bot
authored andcommitted
feat: Implement IndexLookupJoinReplayer (facebookincubator#13560)
Summary: Pull Request resolved: facebookincubator#13560 Implement IndexLookupJoinReplayer, a tool to be used to replay indexlookupjoin. bypass-github-export-checks Reviewed By: xiaoxmeng Differential Revision: D75668860 fbshipit-source-id: fe7621fce442f2907e964d5406f36cb62dcd145a
1 parent 4c1892b commit ffe6e1c

File tree

7 files changed

+439
-1
lines changed

7 files changed

+439
-1
lines changed

velox/exec/tests/utils/TestIndexStorageConnector.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class TestIndexTableHandle : public connector::ConnectorTableHandle {
7474
obj["name"] = name();
7575
obj["connectorId"] = connectorId();
7676
obj["asyncLookup"] = asyncLookup_;
77+
// For testing purpose only, we serialize the index table pointer as an
78+
// long integer.
79+
obj["indexTable"] = reinterpret_cast<int64_t>(indexTable_.get());
7780
return obj;
7881
}
7982

@@ -82,8 +85,12 @@ class TestIndexTableHandle : public connector::ConnectorTableHandle {
8285
void* context) {
8386
// NOTE: this is only for testing purpose so we don't support to serialize
8487
// the table.
88+
auto ptr_value = obj["indexTable"].asInt();
89+
auto indexTablePtr = reinterpret_cast<TestIndexTable*>(ptr_value);
8590
return std::make_shared<TestIndexTableHandle>(
86-
obj["connectorId"].getString(), nullptr, obj["asyncLookup"].asBool());
91+
obj["connectorId"].getString(),
92+
std::shared_ptr<TestIndexTable>(indexTablePtr, [](TestIndexTable*) {}),
93+
obj["asyncLookup"].asBool());
8794
}
8895

8996
static void registerSerDe() {

velox/tool/trace/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_library(
1717
AggregationReplayer.cpp
1818
FilterProjectReplayer.cpp
1919
HashJoinReplayer.cpp
20+
IndexLookupJoinReplayer.cpp
2021
OperatorReplayerBase.cpp
2122
PartitionedOutputReplayer.cpp
2223
TableScanReplayer.cpp
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "velox/tool/trace/IndexLookupJoinReplayer.h"
18+
#include "velox/exec/TraceUtil.h"
19+
#include "velox/exec/tests/utils/PlanBuilder.h"
20+
21+
using namespace facebook::velox;
22+
using namespace facebook::velox::exec;
23+
using namespace facebook::velox::exec::test;
24+
25+
namespace facebook::velox::tool::trace {
26+
core::PlanNodePtr IndexLookupJoinReplayer::createPlanNode(
27+
const core::PlanNode* node,
28+
const core::PlanNodeId& nodeId,
29+
const core::PlanNodePtr& source) const {
30+
const auto* indexLookupJoinNode =
31+
dynamic_cast<const core::IndexLookupJoinNode*>(node);
32+
VELOX_CHECK_NOT_NULL(indexLookupJoinNode);
33+
return std::make_shared<core::IndexLookupJoinNode>(
34+
nodeId,
35+
indexLookupJoinNode->joinType(),
36+
indexLookupJoinNode->leftKeys(),
37+
indexLookupJoinNode->rightKeys(),
38+
indexLookupJoinNode->joinConditions(),
39+
source, // Probe side
40+
indexLookupJoinNode->lookupSource(), // Index side
41+
indexLookupJoinNode->outputType());
42+
}
43+
} // namespace facebook::velox::tool::trace
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include "velox/core/PlanNode.h"
20+
#include "velox/tool/trace/OperatorReplayerBase.h"
21+
22+
namespace facebook::velox::tool::trace {
23+
/// The replayer to replay the traced 'IndexLookupJoin' operator.
24+
class IndexLookupJoinReplayer : public OperatorReplayerBase {
25+
public:
26+
IndexLookupJoinReplayer(
27+
const std::string& traceDir,
28+
const std::string& queryId,
29+
const std::string& taskId,
30+
const std::string& nodeId,
31+
const std::string& operatorType,
32+
const std::string& driverIds,
33+
uint64_t queryCapacity,
34+
folly::Executor* executor)
35+
: OperatorReplayerBase(
36+
traceDir,
37+
queryId,
38+
taskId,
39+
nodeId,
40+
operatorType,
41+
driverIds,
42+
queryCapacity,
43+
executor) {}
44+
45+
private:
46+
core::PlanNodePtr createPlanNode(
47+
const core::PlanNode* node,
48+
const core::PlanNodeId& nodeId,
49+
const core::PlanNodePtr& source) const override;
50+
};
51+
} // namespace facebook::velox::tool::trace

velox/tool/trace/TraceReplayRunner.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "velox/tool/trace/AggregationReplayer.h"
4545
#include "velox/tool/trace/FilterProjectReplayer.h"
4646
#include "velox/tool/trace/HashJoinReplayer.h"
47+
#include "velox/tool/trace/IndexLookupJoinReplayer.h"
4748
#include "velox/tool/trace/OperatorReplayerBase.h"
4849
#include "velox/tool/trace/PartitionedOutputReplayer.h"
4950
#include "velox/tool/trace/TableScanReplayer.h"
@@ -396,6 +397,16 @@ TraceReplayRunner::createReplayer() const {
396397
FLAGS_driver_ids,
397398
queryCapacityBytes,
398399
cpuExecutor_.get());
400+
} else if (traceNodeName == "IndexLookupJoin") {
401+
replayer = std::make_unique<tool::trace::IndexLookupJoinReplayer>(
402+
FLAGS_root_dir,
403+
FLAGS_query_id,
404+
FLAGS_task_id,
405+
FLAGS_node_id,
406+
traceNodeName,
407+
FLAGS_driver_ids,
408+
queryCapacityBytes,
409+
cpuExecutor_.get());
399410
} else {
400411
VELOX_UNSUPPORTED("Unsupported operator type: {}", traceNodeName);
401412
}

velox/tool/trace/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_executable(
1717
AggregationReplayerTest.cpp
1818
FilterProjectReplayerTest.cpp
1919
HashJoinReplayerTest.cpp
20+
IndexLookupJoinReplayerTest.cpp
2021
PartitionedOutputReplayerTest.cpp
2122
TraceFileToolTest.cpp
2223
TableScanReplayerTest.cpp

0 commit comments

Comments
 (0)