Search in sources :

Example 1 with ProjectNode

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

the class TestPruneAggregationColumns method buildProjectedAggregation.

private ProjectNode buildProjectedAggregation(PlanBuilder planBuilder, Predicate<Symbol> projectionFilter) {
    Symbol a = planBuilder.symbol("a");
    Symbol b = planBuilder.symbol("b");
    Symbol key = planBuilder.symbol("key");
    return planBuilder.project(Assignments.copyOf(ImmutableList.of(a, b).stream().filter(projectionFilter).collect(Collectors.toMap(v -> v, v -> planBuilder.variable(v.getName())))), planBuilder.aggregation(aggregationBuilder -> aggregationBuilder.source(planBuilder.values(key)).singleGroupingSet(key).addAggregation(a, PlanBuilder.expression("count()"), ImmutableList.of()).addAggregation(b, PlanBuilder.expression("count()"), ImmutableList.of())));
}
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) PlanMatchPattern.singleGroupingSet(io.prestosql.sql.planner.assertions.PlanMatchPattern.singleGroupingSet) Predicates.alwaysTrue(com.google.common.base.Predicates.alwaysTrue) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) ImmutableList(com.google.common.collect.ImmutableList) SINGLE(io.prestosql.spi.plan.AggregationNode.Step.SINGLE) PlanMatchPattern.functionCall(io.prestosql.sql.planner.assertions.PlanMatchPattern.functionCall) Optional(java.util.Optional) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) PlanMatchPattern.aggregation(io.prestosql.sql.planner.assertions.PlanMatchPattern.aggregation) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) Symbol(io.prestosql.spi.plan.Symbol)

Example 2 with ProjectNode

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

the class TestVerifyOnlyOneOutputNode method testValidateSuccessful.

@Test
public void testValidateSuccessful() {
    // random seemingly valid plan
    PlanNode root = new OutputNode(idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of()), ImmutableList.of(), ImmutableList.of());
    new VerifyOnlyOneOutputNode().validate(root, null, null, null, null, WarningCollector.NOOP);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) OutputNode(io.prestosql.sql.planner.plan.OutputNode) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 3 with ProjectNode

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

the class TestVerifyOnlyOneOutputNode method testValidateFailed.

@Test(expectedExceptions = IllegalStateException.class)
public void testValidateFailed() {
    // random plan with 2 output nodes
    PlanNode root = new OutputNode(idAllocator.getNextId(), new ExplainAnalyzeNode(idAllocator.getNextId(), new OutputNode(idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of()), ImmutableList.of(), ImmutableList.of()), new Symbol("a"), false), ImmutableList.of(), ImmutableList.of());
    new VerifyOnlyOneOutputNode().validate(root, null, null, null, null, WarningCollector.NOOP);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) OutputNode(io.prestosql.sql.planner.plan.OutputNode) PlanNode(io.prestosql.spi.plan.PlanNode) ExplainAnalyzeNode(io.prestosql.sql.planner.plan.ExplainAnalyzeNode) Symbol(io.prestosql.spi.plan.Symbol) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 4 with ProjectNode

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

the class TestRuleIndex method testWithPlanNodeHierarchy.

@Test
public void testWithPlanNodeHierarchy() {
    Rule<?> projectRule1 = new NoOpRule<>(Pattern.typeOf(ProjectNode.class));
    Rule<?> projectRule2 = new NoOpRule<>(Pattern.typeOf(ProjectNode.class));
    Rule<?> filterRule = new NoOpRule<>(Pattern.typeOf(FilterNode.class));
    Rule<?> anyRule = new NoOpRule<>(Pattern.any());
    RuleIndex ruleIndex = RuleIndex.builder().register(projectRule1).register(projectRule2).register(filterRule).register(anyRule).build();
    ProjectNode projectNode = planBuilder.project(Assignments.of(), planBuilder.values());
    FilterNode filterNode = planBuilder.filter(BooleanLiteral.TRUE_LITERAL, planBuilder.values());
    ValuesNode valuesNode = planBuilder.values();
    assertEquals(ruleIndex.getCandidates(projectNode).collect(toSet()), ImmutableSet.of(projectRule1, projectRule2, anyRule));
    assertEquals(ruleIndex.getCandidates(filterNode).collect(toSet()), ImmutableSet.of(filterRule, anyRule));
    assertEquals(ruleIndex.getCandidates(valuesNode).collect(toSet()), ImmutableSet.of(anyRule));
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) FilterNode(io.prestosql.spi.plan.FilterNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 5 with ProjectNode

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

the class TestPruneLimitColumns method buildProjectedLimit.

private ProjectNode buildProjectedLimit(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(), BIGINT)))), planBuilder.limit(1, 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) PlanMatchPattern.limit(io.prestosql.sql.planner.assertions.PlanMatchPattern.limit) Predicates.alwaysTrue(com.google.common.base.Predicates.alwaysTrue) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) Symbol(io.prestosql.spi.plan.Symbol)

Aggregations

ProjectNode (io.prestosql.spi.plan.ProjectNode)76 Symbol (io.prestosql.spi.plan.Symbol)54 Assignments (io.prestosql.spi.plan.Assignments)46 PlanNode (io.prestosql.spi.plan.PlanNode)39 Expression (io.prestosql.sql.tree.Expression)30 RowExpression (io.prestosql.spi.relation.RowExpression)28 ImmutableList (com.google.common.collect.ImmutableList)27 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)27 AggregationNode (io.prestosql.spi.plan.AggregationNode)24 ImmutableMap (com.google.common.collect.ImmutableMap)23 Map (java.util.Map)22 FilterNode (io.prestosql.spi.plan.FilterNode)21 Cast (io.prestosql.sql.tree.Cast)20 TableScanNode (io.prestosql.spi.plan.TableScanNode)18 List (java.util.List)18 CallExpression (io.prestosql.spi.relation.CallExpression)17 HashMap (java.util.HashMap)17 Type (io.prestosql.spi.type.Type)16 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)16 Collectors (java.util.stream.Collectors)16