Skip to content

Commit

Permalink
Improve printing of join criteria in PlanPrinter
Browse files Browse the repository at this point in the history
Print join criteria and filter separately for clarity
  • Loading branch information
raunaqmorarka committed Sep 15, 2023
1 parent 0b8f09f commit 0c6fac4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -678,23 +678,21 @@ public Void visitExplainAnalyze(ExplainAnalyzeNode node, Context context)
@Override
public Void visitJoin(JoinNode node, Context context)
{
List<Expression> joinExpressions = new ArrayList<>();
for (JoinNode.EquiJoinClause clause : node.getCriteria()) {
joinExpressions.add(unresolveFunctions(clause.toExpression()));
}
node.getFilter()
.map(PlanPrinter::unresolveFunctions)
.ifPresent(joinExpressions::add);
List<Expression> criteriaExpressions = node.getCriteria().stream()
.map(clause -> unresolveFunctions(clause.toExpression()))
.collect(toImmutableList());

NodeRepresentation nodeOutput;
if (node.isCrossJoin()) {
checkState(joinExpressions.isEmpty());
checkState(criteriaExpressions.isEmpty());
checkState(node.getFilter().isEmpty());
nodeOutput = addNode(node, "CrossJoin", context.tag());
}
else {
ImmutableMap.Builder<String, String> descriptor = ImmutableMap.<String, String>builder()
.put("criteria", Joiner.on(" AND ").join(anonymizeExpressions(joinExpressions)))
.put("hash", formatHash(node.getLeftHashSymbol(), node.getRightHashSymbol()));
.put("criteria", Joiner.on(" AND ").join(anonymizeExpressions(criteriaExpressions)));
node.getFilter().ifPresent(filter -> descriptor.put("filter", formatFilter(unresolveFunctions(filter))));
descriptor.put("hash", formatHash(node.getLeftHashSymbol(), node.getRightHashSymbol()));
node.getDistributionType().ifPresent(distribution -> descriptor.put("distribution", distribution.name()));
nodeOutput = addNode(node, node.getType().getJoinLabel(), descriptor.buildOrThrow(), node.getReorderJoinStatsAndCost(), context.tag());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ public void testJoinPlan()
ImmutableList.of(new JoinNode.EquiJoinClause(pb.symbol("a", BIGINT), pb.symbol("d", BIGINT))),
ImmutableList.of(pb.symbol("b", BIGINT)),
ImmutableList.of(),
Optional.empty(),
Optional.of(expression("a < c")),
Optional.empty(),
Optional.empty(),
ImmutableMap.of(new DynamicFilterId("DF"), pb.symbol("d", BIGINT))),
new JsonRenderedNode(
"2",
"InnerJoin",
ImmutableMap.of("criteria", "(\"a\" = \"d\")", "hash", "[]"),
ImmutableMap.of("criteria", "(\"a\" = \"d\")", "filter", "(\"a\" < \"c\")", "hash", "[]"),
ImmutableList.of(typedSymbol("b", "bigint")),
ImmutableList.of("dynamicFilterAssignments = {d -> #DF}"),
ImmutableList.of(),
Expand Down

0 comments on commit 0c6fac4

Please sign in to comment.