-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize distinct from semi join #8092
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
import com.facebook.presto.Session; | ||
import com.facebook.presto.connector.ConnectorId; | ||
import com.facebook.presto.metadata.Metadata; | ||
import com.facebook.presto.metadata.QualifiedObjectName; | ||
import com.facebook.presto.metadata.Signature; | ||
import com.facebook.presto.metadata.TableHandle; | ||
import com.facebook.presto.spi.ColumnHandle; | ||
|
@@ -66,13 +65,11 @@ | |
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static com.facebook.presto.sql.planner.SystemPartitioningHandle.FIXED_HASH_DISTRIBUTION; | ||
import static com.facebook.presto.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION; | ||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Verify.verify; | ||
import static com.google.common.collect.ImmutableList.toImmutableList; | ||
import static java.lang.String.format; | ||
|
||
|
@@ -222,35 +219,22 @@ public SemiJoinNode semiJoin(PlanNode source, PlanNode filteringSource, Symbol s | |
|
||
public TableScanNode tableScan(List<Symbol> symbols, Map<Symbol, ColumnHandle> assignments) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this method become deprecated? |
||
{ | ||
Expression originalConstraint = null; | ||
return new TableScanNode(idAllocator.getNextId(), | ||
new TableHandle( | ||
new ConnectorId("testConnector"), | ||
new TestingTableHandle()), | ||
symbols, | ||
assignments, | ||
Optional.empty(), | ||
TupleDomain.all(), | ||
originalConstraint); | ||
TableHandle tableHandle = new TableHandle(new ConnectorId("testConnector"), new TestingTableHandle()); | ||
return tableScan(tableHandle, symbols, assignments); | ||
} | ||
|
||
public TableScanNode tableScan(String tableName, Map<String, String> symbolMap) | ||
public TableScanNode tableScan(TableHandle tableHandle, List<Symbol> symbols, Map<Symbol, ColumnHandle> assignments) | ||
{ | ||
QualifiedObjectName name = new QualifiedObjectName(session.getCatalog().get(), session.getSchema().get(), tableName); | ||
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, name); | ||
verify(tableHandle.isPresent(), "Unknown table %s", name); | ||
Map<String, ColumnHandle> columns = metadata.getColumnHandles(session, tableHandle.get()); | ||
Map<Symbol, ColumnHandle> assignments = symbolMap.entrySet().stream() | ||
.filter(entry -> columns.containsKey(entry.getValue())) | ||
.collect(Collectors.toMap(entry -> new Symbol(entry.getKey()), entry -> columns.get(entry.getValue()))); | ||
List<Symbol> symbols = ImmutableList.copyOf(assignments.keySet()); | ||
return new TableScanNode(idAllocator.getNextId(), | ||
tableHandle.get(), | ||
Expression originalConstraint = null; | ||
return new TableScanNode( | ||
idAllocator.getNextId(), | ||
tableHandle, | ||
symbols, | ||
assignments, | ||
Optional.empty(), | ||
TupleDomain.all(), | ||
null); | ||
originalConstraint | ||
); | ||
} | ||
|
||
public TableFinishNode tableDelete(SchemaTableName schemaTableName, PlanNode deleteSource, Symbol deleteRowId) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,11 +13,15 @@ | |
*/ | ||
package com.facebook.presto.sql.planner.iterative.rule.test; | ||
|
||
import com.facebook.presto.connector.ConnectorId; | ||
import com.facebook.presto.metadata.TableHandle; | ||
import com.facebook.presto.spi.type.BigintType; | ||
import com.facebook.presto.sql.planner.Symbol; | ||
import com.facebook.presto.sql.planner.iterative.rule.RemoveDistinctFromSemiJoin; | ||
import com.facebook.presto.sql.planner.plan.AggregationNode; | ||
import com.facebook.presto.sql.planner.plan.Assignments; | ||
import com.facebook.presto.tpch.TpchColumnHandle; | ||
import com.facebook.presto.tpch.TpchTableHandle; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.testng.annotations.Test; | ||
|
@@ -27,6 +31,7 @@ | |
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.semiJoin; | ||
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.tableScan; | ||
import static com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.expression; | ||
import static com.facebook.presto.tpch.TpchMetadata.TINY_SCALE_FACTOR; | ||
|
||
public class TestRemoveDistinctFromSemiJoin | ||
{ | ||
|
@@ -42,11 +47,23 @@ public void test() | |
Symbol filteringSourceKey = p.symbol("custkey_1", BigintType.BIGINT); | ||
Symbol outputKey = p.symbol("orderkey", BigintType.BIGINT); | ||
return p.semiJoin( | ||
p.tableScan("orders", ImmutableMap.of("custkey", "custkey")), | ||
p.tableScan( | ||
new TableHandle( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe plan builder could have a method, |
||
new ConnectorId("local"), | ||
new TpchTableHandle("local", "orders", TINY_SCALE_FACTOR)), | ||
ImmutableList.of(sourceKey), | ||
ImmutableMap.of(sourceKey, new TpchColumnHandle("custkey", BIGINT))), | ||
p.project(Assignments.of(filteringSourceKey, expression("x")), | ||
p.aggregation(ab -> ab.step(AggregationNode.Step.SINGLE) | ||
.groupingSets(ImmutableList.of(ImmutableList.of(filteringSourceKey))) | ||
.source(p.tableScan("customer", ImmutableMap.of("custkey_1", "custkey"))) | ||
.source( | ||
p.tableScan( | ||
new TableHandle( | ||
new ConnectorId("local"), | ||
new TpchTableHandle("local", "customer", TINY_SCALE_FACTOR)), | ||
ImmutableList.of(filteringSourceKey), | ||
ImmutableMap.of(filteringSourceKey, new TpchColumnHandle("custkey", BIGINT))) | ||
) | ||
.build()) | ||
), | ||
sourceKey, filteringSourceKey, outputKey | ||
|
@@ -69,12 +86,23 @@ public void testDoesNotFire() | |
Symbol filteringSourceKey = p.symbol("custkey_1", BigintType.BIGINT); | ||
Symbol outputKey = p.symbol("orderkey", BigintType.BIGINT); | ||
return p.semiJoin( | ||
p.tableScan("orders", ImmutableMap.of("custkey", "custkey")), | ||
p.tableScan( | ||
new TableHandle( | ||
new ConnectorId("local"), | ||
new TpchTableHandle("local", "orders", TINY_SCALE_FACTOR)), | ||
ImmutableList.of(sourceKey), | ||
ImmutableMap.of(sourceKey, new TpchColumnHandle("custkey", BIGINT))), | ||
p.project(Assignments.of(filteringSourceKey, expression("x")), | ||
p.aggregation(ab -> ab.step(AggregationNode.Step.SINGLE) | ||
.groupingSets(ImmutableList.of(ImmutableList.of(filteringSourceKey))) | ||
.addAggregation(p.symbol("max", BigintType.BIGINT), expression("max(custkey_1)"), ImmutableList.of(BIGINT)) | ||
.source(p.tableScan("customer", ImmutableMap.of("custkey_1", "custkey"))) | ||
.source(p.tableScan( | ||
new TableHandle( | ||
new ConnectorId("local"), | ||
new TpchTableHandle("local", "customer", TINY_SCALE_FACTOR)), | ||
ImmutableList.of(filteringSourceKey), | ||
ImmutableMap.of(filteringSourceKey, new TpchColumnHandle("custkey", BIGINT))) | ||
) | ||
.build()) | ||
), | ||
sourceKey, filteringSourceKey, outputKey | ||
|
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.
I am not sure if need to change the product because the testing infrastructure code. Maybe we should testing code instead to not have this issue?