This repository has been archived by the owner on Dec 9, 2022. It is now read-only.
forked from prestodb/presto
-
Notifications
You must be signed in to change notification settings - Fork 2
Tests for TPCDS queries join ordering #21
Closed
kokosing
wants to merge
6
commits into
starburstdata:epic/cbo/16
from
kokosing:sd/epic/cbo/16/tpcds_plan_utility
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37c5bbb
Add TPCDS queries to tpcds connector module
kokosing c4a4ef2
Support TPCDS stats file to store DATE as String
kokosing a089a70
Add statistics for tpcds.sf3000
kokosing a20d9e8
Extract BaseJoinReorderingTest
kokosing 6cc67e9
Add TPCDS expected join ordering files
kokosing a1f880e
Tests for TPCDS queries join ordering
kokosing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
251 changes: 251 additions & 0 deletions
251
...n/src/test/java/com/facebook/presto/sql/planner/optimizations/BaseJoinReorderingTest.java
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,251 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.facebook.presto.sql.planner.optimizations; | ||
|
||
import com.facebook.presto.sql.planner.LogicalPlanner; | ||
import com.facebook.presto.sql.planner.Plan; | ||
import com.facebook.presto.sql.planner.SimplePlanVisitor; | ||
import com.facebook.presto.sql.planner.assertions.BasePlanTest; | ||
import com.facebook.presto.sql.planner.plan.JoinNode; | ||
import com.facebook.presto.sql.planner.plan.SemiJoinNode; | ||
import com.facebook.presto.sql.planner.plan.TableScanNode; | ||
import com.facebook.presto.sql.planner.plan.ValuesNode; | ||
import com.google.common.base.Strings; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
import static com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.REPLICATED; | ||
import static com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER; | ||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkState; | ||
import static java.lang.String.format; | ||
import static java.util.Objects.requireNonNull; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
public class BaseJoinReorderingTest | ||
extends BasePlanTest | ||
{ | ||
|
||
public BaseJoinReorderingTest(String schema, ImmutableMap<String, String> sessionProperties) | ||
{ | ||
super(schema, sessionProperties); | ||
} | ||
|
||
protected void assertJoinOrder(String sql, Node expected) | ||
{ | ||
assertEquals(joinOrderString(sql), expected.print()); | ||
} | ||
|
||
protected String joinOrderString(String sql) | ||
{ | ||
Plan plan = plan(sql, LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, false); | ||
|
||
JoinOrderPrinter joinOrderPrinter = new JoinOrderPrinter(); | ||
plan.getRoot().accept(joinOrderPrinter, 0); | ||
return joinOrderPrinter.result(); | ||
} | ||
|
||
private static class JoinOrderPrinter | ||
extends SimplePlanVisitor<Integer> | ||
{ | ||
private final StringBuilder stringBuilder = new StringBuilder(); | ||
|
||
public String result() | ||
{ | ||
return stringBuilder.toString(); | ||
} | ||
|
||
@Override | ||
public Void visitJoin(JoinNode node, Integer indent) | ||
{ | ||
JoinNode.DistributionType distributionType = node.getDistributionType() | ||
.orElseThrow(() -> new IllegalStateException("Expected distribution type to be present")); | ||
if (node.isCrossJoin()) { | ||
checkState(node.getType() == INNER && distributionType == REPLICATED, "Expected CROSS join to be INNER REPLICATED"); | ||
stringBuilder.append(indentString(indent)) | ||
.append("cross join:\n"); | ||
} | ||
else { | ||
stringBuilder.append(indentString(indent)) | ||
.append("join (") | ||
.append(node.getType()) | ||
.append(", ") | ||
.append(distributionType) | ||
.append("):\n"); | ||
} | ||
|
||
return visitPlan(node, indent + 1); | ||
} | ||
|
||
@Override | ||
public Void visitTableScan(TableScanNode node, Integer indent) | ||
{ | ||
stringBuilder.append(indentString(indent)) | ||
.append(node.getTable().getConnectorHandle().toString()) | ||
.append("\n"); | ||
return visitPlan(node, indent + 1); | ||
} | ||
|
||
@Override | ||
public Void visitSemiJoin(final SemiJoinNode node, Integer indent) | ||
{ | ||
stringBuilder.append(indentString(indent)) | ||
.append("semijoin (") | ||
.append(node.getDistributionType().map(SemiJoinNode.DistributionType::toString).orElse("unknown")) | ||
.append("):\n"); | ||
|
||
return visitPlan(node, indent + 1); | ||
} | ||
|
||
@Override | ||
public Void visitValues(ValuesNode node, Integer indent) | ||
{ | ||
stringBuilder.append(indentString(indent)) | ||
.append("values\n"); | ||
|
||
return null; | ||
} | ||
} | ||
|
||
private static String indentString(int indent) | ||
{ | ||
return Strings.repeat(" ", indent); | ||
} | ||
|
||
private interface Node | ||
{ | ||
void print(StringBuilder stringBuilder, int indent); | ||
|
||
default String print() | ||
{ | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
print(stringBuilder, 0); | ||
return stringBuilder.toString(); | ||
} | ||
} | ||
|
||
protected Join crossJoin(Node left, Node right) | ||
{ | ||
return new Join(INNER, REPLICATED, true, left, right); | ||
} | ||
|
||
protected static class Join | ||
implements Node | ||
{ | ||
private final JoinNode.Type type; | ||
private final JoinNode.DistributionType distributionType; | ||
private final boolean isCrossJoin; | ||
private final Node left; | ||
private final Node right; | ||
|
||
protected Join(JoinNode.Type type, JoinNode.DistributionType distributionType, Node left, Node right) | ||
{ | ||
this(type, distributionType, false, left, right); | ||
} | ||
|
||
private Join(JoinNode.Type type, JoinNode.DistributionType distributionType, boolean isCrossJoin, Node left, Node right) | ||
{ | ||
if (isCrossJoin) { | ||
checkArgument(distributionType == REPLICATED && type == INNER, "Cross join can only accept INNER REPLICATED join"); | ||
} | ||
this.type = requireNonNull(type, "type is null"); | ||
this.distributionType = requireNonNull(distributionType, "distributionType is null"); | ||
this.isCrossJoin = isCrossJoin; | ||
this.left = requireNonNull(left, "left is null"); | ||
this.right = requireNonNull(right, "right is null"); | ||
} | ||
|
||
@Override | ||
public void print(StringBuilder stringBuilder, int indent) | ||
{ | ||
if (isCrossJoin) { | ||
stringBuilder.append(indentString(indent)) | ||
.append("cross join:\n"); | ||
} | ||
else { | ||
stringBuilder.append(indentString(indent)) | ||
.append("join (") | ||
.append(type) | ||
.append(", ") | ||
.append(distributionType) | ||
.append("):\n"); | ||
} | ||
|
||
left.print(stringBuilder, indent + 1); | ||
right.print(stringBuilder, indent + 1); | ||
} | ||
} | ||
|
||
protected static class SemiJoin | ||
implements Node | ||
{ | ||
private final JoinNode.DistributionType distributionType; | ||
private final Node left; | ||
private final Node right; | ||
|
||
protected SemiJoin(JoinNode.DistributionType distributionType, final Node left, final Node right) | ||
{ | ||
this.distributionType = requireNonNull(distributionType); | ||
this.left = requireNonNull(left); | ||
this.right = requireNonNull(right); | ||
} | ||
|
||
@Override | ||
public void print(StringBuilder stringBuilder, int indent) | ||
{ | ||
stringBuilder.append(indentString(indent)) | ||
.append("semijoin (") | ||
.append(distributionType.toString()) | ||
.append("):\n"); | ||
|
||
left.print(stringBuilder, indent + 1); | ||
right.print(stringBuilder, indent + 1); | ||
} | ||
} | ||
|
||
protected TableScan tableScan(String tableName) | ||
{ | ||
return new TableScan(format("tpch:%s:%s", tableName, getQueryRunner().getDefaultSession().getSchema().get())); | ||
} | ||
|
||
protected static class TableScan | ||
implements Node | ||
{ | ||
private final String tableName; | ||
|
||
private TableScan(String tableName) | ||
{ | ||
this.tableName = tableName; | ||
} | ||
|
||
@Override | ||
public void print(StringBuilder stringBuilder, int indent) | ||
{ | ||
stringBuilder.append(indentString(indent)) | ||
.append(tableName) | ||
.append("\n"); | ||
} | ||
} | ||
|
||
protected static class Values | ||
implements Node | ||
{ | ||
@Override | ||
public void print(StringBuilder stringBuilder, int indent) | ||
{ | ||
stringBuilder.append(indentString(indent)) | ||
.append("values\n"); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure. Is
an extract only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure it is. :)