Search in sources :

Example 76 with ProjectNode

use of io.prestosql.spi.plan.ProjectNode in project hetu-core by openlookeng.

the class TestPruneFilterColumns method buildProjectedFilter.

private ProjectNode buildProjectedFilter(PlanBuilder planBuilder, Predicate<Symbol> projectionFilter) {
    Symbol a = planBuilder.symbol("a");
    Symbol b = planBuilder.symbol("b");
    return planBuilder.project(Assignments.copyOf(Stream.of(a, b).filter(projectionFilter).collect(Collectors.toMap(v -> v, v -> planBuilder.variable(v.getName())))), planBuilder.filter(PlanBuilder.expression("b > 5"), planBuilder.values(a, b)));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.prestosql.spi.plan.Assignments) PlanMatchPattern.strictProject(io.prestosql.sql.planner.assertions.PlanMatchPattern.strictProject) Predicate(java.util.function.Predicate) Test(org.testng.annotations.Test) ProjectNode(io.prestosql.spi.plan.ProjectNode) Collectors(java.util.stream.Collectors) Predicates.alwaysTrue(com.google.common.base.Predicates.alwaysTrue) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) Stream(java.util.stream.Stream) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) PlanMatchPattern.filter(io.prestosql.sql.planner.assertions.PlanMatchPattern.filter) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) Symbol(io.prestosql.spi.plan.Symbol)

Example 77 with ProjectNode

use of io.prestosql.spi.plan.ProjectNode in project hetu-core by openlookeng.

the class TestTypeValidator method testValidTypeOnlyCoercion.

@Test
public void testValidTypeOnlyCoercion() {
    Expression expression = new Cast(toSymbolReference(columnB), StandardTypes.BIGINT);
    Assignments assignments = Assignments.builder().put(planSymbolAllocator.newSymbol(expression, BIGINT), castToRowExpression(expression)).put(planSymbolAllocator.newSymbol(toSymbolReference(columnE), VARCHAR), // implicit coercion from varchar(3) to varchar
    castToRowExpression(toSymbolReference(columnE))).build();
    PlanNode node = new ProjectNode(newId(), baseTableScan, assignments);
    assertTypesValid(node);
}
Also used : Cast(io.prestosql.sql.tree.Cast) PlanNode(io.prestosql.spi.plan.PlanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Expression(io.prestosql.sql.tree.Expression) Assignments(io.prestosql.spi.plan.Assignments) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 78 with ProjectNode

use of io.prestosql.spi.plan.ProjectNode in project hetu-core by openlookeng.

the class TestTypeValidator method testValidProject.

@Test
public void testValidProject() {
    Expression expression1 = new Cast(toSymbolReference(columnB), StandardTypes.BIGINT);
    Expression expression2 = new Cast(toSymbolReference(columnC), StandardTypes.BIGINT);
    Assignments assignments = Assignments.builder().put(planSymbolAllocator.newSymbol(expression1, BIGINT), castToRowExpression(expression1)).put(planSymbolAllocator.newSymbol(expression2, BIGINT), castToRowExpression(expression2)).build();
    PlanNode node = new ProjectNode(newId(), baseTableScan, assignments);
    assertTypesValid(node);
}
Also used : Cast(io.prestosql.sql.tree.Cast) PlanNode(io.prestosql.spi.plan.PlanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Expression(io.prestosql.sql.tree.Expression) Assignments(io.prestosql.spi.plan.Assignments) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 79 with ProjectNode

use of io.prestosql.spi.plan.ProjectNode in project hetu-core by openlookeng.

the class SimpleFilterProjectSemiJoinStatsRule method doCalculate.

@Override
protected Optional<PlanNodeStatsEstimate> doCalculate(FilterNode node, StatsProvider sourceStats, Lookup lookup, Session session, TypeProvider types) {
    PlanNode nodeSource = lookup.resolve(node.getSource());
    SemiJoinNode semiJoinNode;
    if (nodeSource instanceof ProjectNode) {
        ProjectNode projectNode = (ProjectNode) nodeSource;
        if (!isIdentity(projectNode)) {
            return Optional.empty();
        }
        PlanNode projectNodeSource = lookup.resolve(projectNode.getSource());
        if (!(projectNodeSource instanceof SemiJoinNode)) {
            return Optional.empty();
        }
        semiJoinNode = (SemiJoinNode) projectNodeSource;
    } else if (nodeSource instanceof SemiJoinNode) {
        semiJoinNode = (SemiJoinNode) nodeSource;
    } else {
        return Optional.empty();
    }
    return calculate(node, semiJoinNode, sourceStats, session, types);
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode)

Aggregations

ProjectNode (io.prestosql.spi.plan.ProjectNode)79 Symbol (io.prestosql.spi.plan.Symbol)56 Assignments (io.prestosql.spi.plan.Assignments)47 PlanNode (io.prestosql.spi.plan.PlanNode)40 RowExpression (io.prestosql.spi.relation.RowExpression)30 Expression (io.prestosql.sql.tree.Expression)30 ImmutableList (com.google.common.collect.ImmutableList)29 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)27 ImmutableMap (com.google.common.collect.ImmutableMap)25 AggregationNode (io.prestosql.spi.plan.AggregationNode)25 Map (java.util.Map)24 FilterNode (io.prestosql.spi.plan.FilterNode)22 TableScanNode (io.prestosql.spi.plan.TableScanNode)21 Cast (io.prestosql.sql.tree.Cast)20 List (java.util.List)19 CallExpression (io.prestosql.spi.relation.CallExpression)18 HashMap (java.util.HashMap)18 Type (io.prestosql.spi.type.Type)17 Test (org.testng.annotations.Test)17 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)16