Search in sources :

Example 1 with Assignments

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);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Assignments(com.facebook.presto.spi.plan.Assignments) RowExpression(com.facebook.presto.spi.relation.RowExpression) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) SpatialJoinNode(com.facebook.presto.sql.planner.plan.SpatialJoinNode)

Example 2 with Assignments

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);
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) CallExpression(com.facebook.presto.spi.relation.CallExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) FilterNode(com.facebook.presto.spi.plan.FilterNode) Assignments(com.facebook.presto.spi.plan.Assignments) RowExpression(com.facebook.presto.spi.relation.RowExpression) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 3 with Assignments

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);
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) ApplyNode(com.facebook.presto.sql.planner.plan.ApplyNode) Assignments(com.facebook.presto.spi.plan.Assignments) RowExpression(com.facebook.presto.spi.relation.RowExpression) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 4 with Assignments

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());
}
Also used : SymbolMapper(com.facebook.presto.sql.planner.optimizations.SymbolMapper) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) ArrayList(java.util.ArrayList) Assignments(com.facebook.presto.spi.plan.Assignments) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) PlanNode(com.facebook.presto.spi.plan.PlanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) ProjectNode(com.facebook.presto.spi.plan.ProjectNode)

Example 5 with Assignments

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());
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) OriginalExpressionUtils.castToExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToExpression) CallExpression(com.facebook.presto.spi.relation.CallExpression) NotExpression(com.facebook.presto.sql.tree.NotExpression) SearchedCaseExpression(com.facebook.presto.sql.tree.SearchedCaseExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Assignments(com.facebook.presto.spi.plan.Assignments) InPredicate(com.facebook.presto.sql.tree.InPredicate)

Aggregations

Assignments (com.facebook.presto.spi.plan.Assignments)25 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)23 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)22 OriginalExpressionUtils.castToRowExpression (com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression)12 PlanNode (com.facebook.presto.spi.plan.PlanNode)11 RowExpression (com.facebook.presto.spi.relation.RowExpression)11 Expression (com.facebook.presto.sql.tree.Expression)10 CallExpression (com.facebook.presto.spi.relation.CallExpression)8 ImmutableList (com.google.common.collect.ImmutableList)8 Cast (com.facebook.presto.sql.tree.Cast)7 SymbolReference (com.facebook.presto.sql.tree.SymbolReference)7 Map (java.util.Map)6 Type (com.facebook.presto.common.type.Type)5 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)5 FilterNode (com.facebook.presto.spi.plan.FilterNode)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Session (com.facebook.presto.Session)4 Field (com.facebook.presto.sql.analyzer.Field)4 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)3