Skip to content

Commit

Permalink
feat(fuzzer): Update "makeDefaultPlan" function to generate multi-joi…
Browse files Browse the repository at this point in the history
…n plans (facebookincubator#11939)

Summary:

Generates a cascading multi-join from left to right.
```
[t1, t2, t3, t4]

t1  t2
 \  /
  a   t3
   \  /
     b   t4
      \  /
        c
```

Differential Revision: D67607316
  • Loading branch information
Daniel Hunte authored and facebook-github-bot committed Dec 23, 2024
1 parent f60ddf8 commit 57ae53c
Showing 1 changed file with 52 additions and 47 deletions.
99 changes: 52 additions & 47 deletions velox/exec/fuzzer/JoinFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,18 @@ class JoinFuzzer {
// Randomly pick a join type to test.
core::JoinType pickJoinType();

// Makes the query plan with default settings in JoinFuzzer and value inputs
// for both probe and build sides.
// Makes the query plan with default settings in JoinFuzzer using inputs
// joining each input from left to right.
//
// NOTE: 'probeInput' and 'buildInput' could either input rows with lazy
// vectors or flatten ones.
// NOTE: inputs can be rows with lazy vectors or flattened ones.
JoinFuzzer::PlanWithSplits makeDefaultPlan(
core::JoinType joinType,
bool nullAware,
const std::vector<std::string>& probeKeys,
const std::vector<std::string>& buildKeys,
const std::vector<RowVectorPtr>& probeInput,
const std::vector<RowVectorPtr>& buildInput,
const std::vector<std::string>& outputColumns,
const std::string& filter);
const std::vector<core::JoinType>& joinTypes,
const std::vector<bool>& nullAwareList,
const std::vector<std::vector<std::string>>& probeKeysList,
const std::vector<std::vector<std::string>>& buildKeysList,
const std::vector<std::vector<RowVectorPtr>>& inputs,
const std::vector<std::vector<std::string>>& outputColumnsList,
const std::vector<std::string>& filterList);

JoinFuzzer::PlanWithSplits makeMergeJoinPlan(
core::JoinType joinType,
Expand Down Expand Up @@ -735,28 +733,37 @@ std::vector<std::string> fieldNames(
}

JoinFuzzer::PlanWithSplits JoinFuzzer::makeDefaultPlan(
core::JoinType joinType,
bool nullAware,
const std::vector<std::string>& probeKeys,
const std::vector<std::string>& buildKeys,
const std::vector<RowVectorPtr>& probeInput,
const std::vector<RowVectorPtr>& buildInput,
const std::vector<std::string>& outputColumns,
const std::string& filter) {
const std::vector<core::JoinType>& joinTypes,
const std::vector<bool>& nullAwareList,
const std::vector<std::vector<std::string>>& probeKeysList,
const std::vector<std::vector<std::string>>& buildKeysList,
const std::vector<std::vector<RowVectorPtr>>& inputs,
const std::vector<std::vector<std::string>>& outputColumnsList,
const std::vector<std::string>& filterList) {
VELOX_CHECK(inputs.size() > 1);
auto planNodeIdGenerator = std::make_shared<core::PlanNodeIdGenerator>();
auto plan =
PlanBuilder plan =
PlanBuilder(planNodeIdGenerator)
.values(probeInput)
.values(inputs[0])
.hashJoin(
probeKeys,
buildKeys,
PlanBuilder(planNodeIdGenerator).values(buildInput).planNode(),
filter,
outputColumns,
joinType,
nullAware)
.planNode();
return PlanWithSplits{plan};
probeKeysList[0],
buildKeysList[0],
PlanBuilder(planNodeIdGenerator).values(inputs[1]).planNode(),
filterList[0],
outputColumnsList[0],
joinTypes[0],
nullAwareList[0]);
for (auto i = 1; i < inputs.size() - 1; i++) {
plan = plan.hashJoin(
probeKeysList[i],
buildKeysList[i],
PlanBuilder(planNodeIdGenerator).values(inputs[i + 1]).planNode(),
filterList[i],
outputColumnsList[i],
joinTypes[i],
nullAwareList[i]);
}
return PlanWithSplits{plan.planNode()};
}

JoinFuzzer::PlanWithSplits JoinFuzzer::makeDefaultPlanWithTableScan(
Expand Down Expand Up @@ -1176,14 +1183,13 @@ void JoinFuzzer::verify(core::JoinType joinType) {
shuffleJoinKeys(probeKeys, buildKeys);

const auto defaultPlan = makeDefaultPlan(
joinType,
nullAware,
probeKeys,
buildKeys,
probeInput,
buildInput,
outputColumns,
filter);
{joinType},
{nullAware},
{probeKeys},
{buildKeys},
{probeInput, buildInput},
{outputColumns},
{filter});

const auto expected = execute(defaultPlan, /*injectSpill=*/false);

Expand All @@ -1206,14 +1212,13 @@ void JoinFuzzer::verify(core::JoinType joinType) {

std::vector<PlanWithSplits> altPlans;
altPlans.push_back(makeDefaultPlan(
joinType,
nullAware,
probeKeys,
buildKeys,
flatProbeInput,
flatBuildInput,
outputColumns,
filter));
{joinType},
{nullAware},
{probeKeys},
{buildKeys},
{flatProbeInput, flatBuildInput},
{outputColumns},
{filter}));

makeAlternativePlans(
defaultPlan.plan, probeInput, buildInput, altPlans, filter);
Expand Down

0 comments on commit 57ae53c

Please sign in to comment.