use of com.facebook.presto.spi.plan.Assignments in project presto by prestodb.
the class TestVerifyNoOriginalExpression method validateSpatialJoinWithFilter.
private void validateSpatialJoinWithFilter(RowExpression filter) {
ImmutableList<VariableReferenceExpression> outputVariables = ImmutableList.of(VARIABLE_REFERENCE_EXPRESSION);
Optional<VariableReferenceExpression> leftPartitionVariable = Optional.of(VARIABLE_REFERENCE_EXPRESSION);
Optional<VariableReferenceExpression> rightPartitionVariable = Optional.of(VARIABLE_REFERENCE_EXPRESSION);
Optional<String> kdbTree = Optional.of("");
ImmutableMap<VariableReferenceExpression, RowExpression> map = ImmutableMap.of(VARIABLE_REFERENCE_EXPRESSION, VARIABLE_REFERENCE_EXPRESSION);
ProjectNode projectNode = builder.project(new Assignments(map), valuesNode);
SpatialJoinNode spatialJoinNode = new SpatialJoinNode(Optional.empty(), new PlanNodeId("1"), SpatialJoinNode.Type.INNER, projectNode, projectNode, outputVariables, filter, leftPartitionVariable, rightPartitionVariable, kdbTree);
testValidation(spatialJoinNode);
}
use of com.facebook.presto.spi.plan.Assignments in project presto by prestodb.
the class TestVerifyNoOriginalExpression method testValidateFailedCompound.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testValidateFailedCompound() {
Expression predicate = COMPARISON_EXPRESSION;
RowExpression rowExpression = castToRowExpression(predicate);
FilterNode filterNode = builder.filter(rowExpression, valuesNode);
ImmutableMap<VariableReferenceExpression, RowExpression> map = ImmutableMap.of(VARIABLE_REFERENCE_EXPRESSION, castToRowExpression(new SymbolReference("count")));
ProjectNode projectNode = builder.project(new Assignments(map), filterNode);
testValidation(projectNode);
}
use of com.facebook.presto.spi.plan.Assignments in project presto by prestodb.
the class TestVerifyNoOriginalExpression method testValidateForApplyFailed.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testValidateForApplyFailed() {
ImmutableMap<VariableReferenceExpression, RowExpression> map = ImmutableMap.of(VARIABLE_REFERENCE_EXPRESSION, castToRowExpression(new SymbolReference("count")));
Assignments assignments = new Assignments(map);
ImmutableList<VariableReferenceExpression> variableReferenceExpressions = ImmutableList.of(VARIABLE_REFERENCE_EXPRESSION);
ApplyNode applyNode = builder.apply(assignments, variableReferenceExpressions, valuesNode, valuesNode);
testValidation(applyNode);
}
use of com.facebook.presto.spi.plan.Assignments in project presto by prestodb.
the class PushPartialAggregationThroughExchange method pushPartial.
private PlanNode pushPartial(AggregationNode aggregation, ExchangeNode exchange, Context context) {
List<PlanNode> partials = new ArrayList<>();
for (int i = 0; i < exchange.getSources().size(); i++) {
PlanNode source = exchange.getSources().get(i);
SymbolMapper.Builder mappingsBuilder = SymbolMapper.builder();
for (int outputIndex = 0; outputIndex < exchange.getOutputVariables().size(); outputIndex++) {
VariableReferenceExpression output = exchange.getOutputVariables().get(outputIndex);
VariableReferenceExpression input = exchange.getInputs().get(i).get(outputIndex);
if (!output.equals(input)) {
mappingsBuilder.put(output, input);
}
}
SymbolMapper symbolMapper = mappingsBuilder.build();
AggregationNode mappedPartial = symbolMapper.map(aggregation, source, context.getIdAllocator());
Assignments.Builder assignments = Assignments.builder();
for (VariableReferenceExpression output : aggregation.getOutputVariables()) {
VariableReferenceExpression input = symbolMapper.map(output);
assignments.put(output, input);
}
partials.add(new ProjectNode(exchange.getSourceLocation(), context.getIdAllocator().getNextId(), mappedPartial, assignments.build(), LOCAL));
}
for (PlanNode node : partials) {
verify(aggregation.getOutputVariables().equals(node.getOutputVariables()));
}
// Since this exchange source is now guaranteed to have the same symbols as the inputs to the the partial
// aggregation, we don't need to rewrite symbols in the partitioning function
List<VariableReferenceExpression> aggregationOutputs = aggregation.getOutputVariables();
PartitioningScheme partitioning = new PartitioningScheme(exchange.getPartitioningScheme().getPartitioning(), aggregationOutputs, exchange.getPartitioningScheme().getHashColumn(), exchange.getPartitioningScheme().isReplicateNullsAndAny(), exchange.getPartitioningScheme().getBucketToPartition());
return new ExchangeNode(aggregation.getSourceLocation(), context.getIdAllocator().getNextId(), exchange.getType(), exchange.getScope(), partitioning, partials, ImmutableList.copyOf(Collections.nCopies(partials.size(), aggregationOutputs)), exchange.isEnsureSourceOrdering(), Optional.empty());
}
use of com.facebook.presto.spi.plan.Assignments in project presto by prestodb.
the class TransformCorrelatedInPredicateToJoin method apply.
@Override
public Result apply(ApplyNode apply, Captures captures, Context context) {
Assignments subqueryAssignments = apply.getSubqueryAssignments();
if (subqueryAssignments.size() != 1) {
return Result.empty();
}
Expression assignmentExpression = castToExpression(getOnlyElement(subqueryAssignments.getExpressions()));
if (!(assignmentExpression instanceof InPredicate)) {
return Result.empty();
}
InPredicate inPredicate = (InPredicate) assignmentExpression;
VariableReferenceExpression inPredicateOutputVariable = getOnlyElement(subqueryAssignments.getVariables());
return apply(apply, inPredicate, inPredicateOutputVariable, context.getLookup(), context.getIdAllocator(), context.getVariableAllocator());
}
Aggregations