Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import static com.facebook.presto.sql.planner.iterative.Lookup.noLookup;
import static com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher.searchFrom;
import static com.facebook.presto.sql.relational.Expressions.call;
import static com.facebook.presto.sql.relational.Expressions.callOperator;
import static com.facebook.presto.sql.relational.Expressions.constant;
import static com.facebook.presto.sql.relational.Expressions.variable;
import static com.facebook.presto.type.TypeUtils.NULL_HASH_CODE;
Expand Down Expand Up @@ -577,4 +578,19 @@ public static RowExpression randomizeJoinKey(Session session, FunctionAndTypeMan
}
return new SpecialFormExpression(COALESCE, VARCHAR, ImmutableList.of(castToVarchar, concatExpression));
}

public static RowExpression getVariableHash(List<VariableReferenceExpression> inputVariables, FunctionAndTypeManager functionAndTypeManager)
{
checkArgument(!inputVariables.isEmpty());
List<CallExpression> hashExpressionList = inputVariables.stream().map(keyVariable ->
callOperator(functionAndTypeManager.getFunctionAndTypeResolver(), OperatorType.XX_HASH_64, BIGINT, keyVariable)).collect(toImmutableList());
RowExpression hashExpression = hashExpressionList.get(0);
if (hashExpressionList.size() > 1) {
hashExpression = orNullHashCode(hashExpression);
for (int i = 1; i < hashExpressionList.size(); ++i) {
hashExpression = call(functionAndTypeManager, "combine_hash", BIGINT, hashExpression, orNullHashCode(hashExpressionList.get(i)));
}
}
return hashExpression;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.facebook.presto.sql.planner.optimizations;

import com.facebook.presto.Session;
import com.facebook.presto.common.function.OperatorType;
import com.facebook.presto.common.type.VarcharType;
import com.facebook.presto.metadata.FunctionAndTypeManager;
import com.facebook.presto.metadata.Metadata;
Expand All @@ -27,7 +26,6 @@
import com.facebook.presto.spi.plan.PlanNode;
import com.facebook.presto.spi.plan.PlanNodeIdAllocator;
import com.facebook.presto.spi.plan.SemiJoinNode;
import com.facebook.presto.spi.relation.CallExpression;
import com.facebook.presto.spi.relation.RowExpression;
import com.facebook.presto.spi.relation.VariableReferenceExpression;
import com.facebook.presto.sql.planner.TypeProvider;
Expand All @@ -42,21 +40,18 @@
import java.util.stream.IntStream;

import static com.facebook.presto.SystemSessionProperties.isJoinPrefilterEnabled;
import static com.facebook.presto.common.type.BigintType.BIGINT;
import static com.facebook.presto.common.type.BooleanType.BOOLEAN;
import static com.facebook.presto.common.type.VarcharType.VARCHAR;
import static com.facebook.presto.spi.plan.AggregationNode.singleGroupingSet;
import static com.facebook.presto.spi.plan.JoinType.INNER;
import static com.facebook.presto.spi.plan.JoinType.LEFT;
import static com.facebook.presto.sql.planner.PlannerUtils.addProjections;
import static com.facebook.presto.sql.planner.PlannerUtils.clonePlanNode;
import static com.facebook.presto.sql.planner.PlannerUtils.getVariableHash;
import static com.facebook.presto.sql.planner.PlannerUtils.isScanFilterProject;
import static com.facebook.presto.sql.planner.PlannerUtils.orNullHashCode;
import static com.facebook.presto.sql.planner.PlannerUtils.projectExpressions;
import static com.facebook.presto.sql.planner.PlannerUtils.restrictOutput;
import static com.facebook.presto.sql.planner.plan.ChildReplacer.replaceChildren;
import static com.facebook.presto.sql.relational.Expressions.call;
import static com.facebook.presto.sql.relational.Expressions.callOperator;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -208,7 +203,7 @@ public PlanNode visitJoin(JoinNode node, RewriteContext<Void> context)
PlanNode leftKeys = clonePlanNode(rewrittenLeft, session, metadata, idAllocator, leftKeyList, leftVarMap);
ImmutableList.Builder<RowExpression> expressionsToProject = ImmutableList.builder();
if (hashJoinKey) {
RowExpression hashExpression = getVariableHash(leftKeyList);
RowExpression hashExpression = getVariableHash(leftKeyList, functionAndTypeManager);
expressionsToProject.add(hashExpression);
}
else {
Expand All @@ -218,7 +213,7 @@ public PlanNode visitJoin(JoinNode node, RewriteContext<Void> context)

VariableReferenceExpression rightKeyToFilter = rightKeyList.get(0);
if (hashJoinKey) {
RowExpression hashExpression = getVariableHash(rightKeyList);
RowExpression hashExpression = getVariableHash(rightKeyList, functionAndTypeManager);
rightKeyToFilter = variableAllocator.newVariable(hashExpression);
rewrittenRight = addProjections(rewrittenRight, idAllocator, ImmutableMap.of(rightKeyToFilter, hashExpression));
}
Expand Down Expand Up @@ -273,19 +268,5 @@ public boolean isPlanChanged()
{
return planChanged;
}

private RowExpression getVariableHash(List<VariableReferenceExpression> inputVariables)
{
List<CallExpression> hashExpressionList = inputVariables.stream().map(keyVariable ->
callOperator(functionAndTypeManager.getFunctionAndTypeResolver(), OperatorType.XX_HASH_64, BIGINT, keyVariable)).collect(toImmutableList());
RowExpression hashExpression = hashExpressionList.get(0);
if (hashExpressionList.size() > 1) {
hashExpression = orNullHashCode(hashExpression);
for (int i = 1; i < hashExpressionList.size(); ++i) {
hashExpression = call(functionAndTypeManager, "combine_hash", BIGINT, hashExpression, orNullHashCode(hashExpressionList.get(i)));
}
}
return hashExpression;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
import static com.facebook.presto.sql.planner.PlannerUtils.addProjections;
import static com.facebook.presto.sql.planner.PlannerUtils.clonePlanNode;
import static com.facebook.presto.sql.planner.PlannerUtils.createMapType;
import static com.facebook.presto.sql.planner.PlannerUtils.getHashExpression;
import static com.facebook.presto.sql.planner.PlannerUtils.getTableScanNodeWithOnlyFilterAndProject;
import static com.facebook.presto.sql.planner.PlannerUtils.getVariableHash;
import static com.facebook.presto.sql.planner.PlannerUtils.projectExpressions;
import static com.facebook.presto.sql.planner.optimizations.JoinNodeUtils.typeConvert;
import static com.facebook.presto.sql.planner.plan.ChildReplacer.replaceChildren;
Expand Down Expand Up @@ -223,8 +223,8 @@ private PlanNode addPrefilter(AggregationNode aggregationNode, long count)
SystemSessionProperties.getPrefilterForGroupbyLimitTimeoutMS(session));

FunctionAndTypeManager functionAndTypeManager = metadata.getFunctionAndTypeManager();
RowExpression leftHashExpression = getHashExpression(functionAndTypeManager, keys).get();
RowExpression rightHashExpression = getHashExpression(functionAndTypeManager, timedDistinctLimitNode.getOutputVariables()).get();
RowExpression leftHashExpression = getVariableHash(keys, functionAndTypeManager);
RowExpression rightHashExpression = getVariableHash(timedDistinctLimitNode.getOutputVariables(), functionAndTypeManager);

Type mapType = createMapType(functionAndTypeManager, BIGINT, BOOLEAN);
PlanNode rightProjectNode = projectExpressions(timedDistinctLimitNode, idAllocator, variableAllocator, ImmutableList.of(rightHashExpression, constant(TRUE, BOOLEAN)), ImmutableList.of());
Expand Down
Loading