Search in sources :

Example 1 with PlanBuilder

use of io.prestosql.sql.planner.iterative.rule.test.PlanBuilder 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 PlanBuilder

use of io.prestosql.sql.planner.iterative.rule.test.PlanBuilder in project hetu-core by openlookeng.

the class TestPruneCrossJoinColumns method buildProjectedCrossJoin.

private static PlanNode buildProjectedCrossJoin(PlanBuilder p, Predicate<Symbol> projectionFilter) {
    Symbol leftValue = p.symbol("leftValue");
    Symbol rightValue = p.symbol("rightValue");
    List<Symbol> outputs = ImmutableList.of(leftValue, rightValue);
    return p.project(Assignments.copyOf(outputs.stream().filter(projectionFilter).collect(Collectors.toMap(v -> v, v -> p.variable(v.getName())))), p.join(JoinNode.Type.INNER, p.values(leftValue), p.values(rightValue), ImmutableList.of(), outputs, Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) PlanMatchPattern.join(io.prestosql.sql.planner.assertions.PlanMatchPattern.join) 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) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) PlanNode(io.prestosql.spi.plan.PlanNode) Collectors(java.util.stream.Collectors) List(java.util.List) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) ImmutableList(com.google.common.collect.ImmutableList) Predicates(com.google.common.base.Predicates) Optional(java.util.Optional) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol)

Example 3 with PlanBuilder

use of io.prestosql.sql.planner.iterative.rule.test.PlanBuilder in project hetu-core by openlookeng.

the class TestPruneIndexSourceColumns method buildProjectedIndexSource.

private static PlanNode buildProjectedIndexSource(PlanBuilder p, Predicate<Symbol> projectionFilter) {
    Symbol orderkey = p.symbol("orderkey", INTEGER);
    Symbol custkey = p.symbol("custkey", INTEGER);
    Symbol totalprice = p.symbol("totalprice", DOUBLE);
    ColumnHandle orderkeyHandle = new TpchColumnHandle(orderkey.getName(), INTEGER);
    ColumnHandle custkeyHandle = new TpchColumnHandle(custkey.getName(), INTEGER);
    ColumnHandle totalpriceHandle = new TpchColumnHandle(totalprice.getName(), DOUBLE);
    return p.project(Assignments.copyOf(ImmutableList.of(orderkey, custkey, totalprice).stream().filter(projectionFilter).collect(Collectors.toMap(v -> v, v -> p.variable(v.getName())))), p.indexSource(new TableHandle(new CatalogName("local"), new TpchTableHandle("orders", TINY_SCALE_FACTOR), TpchTransactionHandle.INSTANCE, Optional.empty()), ImmutableSet.of(orderkey, custkey), ImmutableList.of(orderkey, custkey, totalprice), ImmutableMap.of(orderkey, orderkeyHandle, custkey, custkeyHandle, totalprice, totalpriceHandle), TupleDomain.fromFixedValues(ImmutableMap.of(totalpriceHandle, asNull(DOUBLE)))));
}
Also used : BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) Test(org.testng.annotations.Test) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) TableHandle(io.prestosql.spi.metadata.TableHandle) ImmutableList(com.google.common.collect.ImmutableList) Predicates(com.google.common.base.Predicates) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) TpchTransactionHandle(io.prestosql.plugin.tpch.TpchTransactionHandle) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) Symbol(io.prestosql.spi.plan.Symbol) TINY_SCALE_FACTOR(io.prestosql.plugin.tpch.TpchMetadata.TINY_SCALE_FACTOR) PlanMatchPattern.constrainedIndexSource(io.prestosql.sql.planner.assertions.PlanMatchPattern.constrainedIndexSource) ImmutableSet(com.google.common.collect.ImmutableSet) 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) TupleDomain(io.prestosql.spi.predicate.TupleDomain) CatalogName(io.prestosql.spi.connector.CatalogName) PlanNode(io.prestosql.spi.plan.PlanNode) Collectors(java.util.stream.Collectors) NullableValue.asNull(io.prestosql.spi.predicate.NullableValue.asNull) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Domain(io.prestosql.spi.predicate.Domain) Optional(java.util.Optional) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) Symbol(io.prestosql.spi.plan.Symbol) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) CatalogName(io.prestosql.spi.connector.CatalogName) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle)

Example 4 with PlanBuilder

use of io.prestosql.sql.planner.iterative.rule.test.PlanBuilder in project hetu-core by openlookeng.

the class TestExternalFunctionPushDownChecker method setup.

@BeforeClass
public void setup() {
    planSymbolAllocator = new PlanSymbolAllocator();
    columnA = planSymbolAllocator.newSymbol("a", DOUBLE);
    columnB = planSymbolAllocator.newSymbol("b", DOUBLE);
    sumCall = call("sum", SUM, DOUBLE, ImmutableList.of(VariableReferenceSymbolConverter.toVariableReference(columnA, DOUBLE)));
    externalFooCall1 = new CallExpression("jdbc.v1.foo", EXTERNAL_FOO, DOUBLE, ImmutableList.of());
    externalFooCall2 = new CallExpression("jdbc.v1.foo2", EXTERNAL_FOO, DOUBLE, ImmutableList.of());
    metadata = getQueryRunner().getMetadata();
    builder = new PlanBuilder(new PlanNodeIdAllocator(), metadata);
}
Also used : PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator) CallExpression(io.prestosql.spi.relation.CallExpression) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with PlanBuilder

use of io.prestosql.sql.planner.iterative.rule.test.PlanBuilder in project hetu-core by openlookeng.

the class TestCardinalityExtractorPlanVisitor method testAggregation.

@Test
public void testAggregation() {
    PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata());
    Symbol symbol = planBuilder.symbol("symbol");
    ColumnHandle columnHandle = new TestingColumnHandle("column");
    // single default aggregation
    assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.singleGroupingSet().source(planBuilder.values(10)))), Range.singleton(1L));
    // multiple grouping sets with default aggregation with source that produces arbitrary number of rows
    assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.groupingSets(AggregationNode.groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))).source(planBuilder.tableScan(ImmutableList.of(symbol), ImmutableMap.of(symbol, columnHandle))))), Range.atLeast(1L));
    // multiple grouping sets with default aggregation with source that produces exact number of rows
    assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.groupingSets(AggregationNode.groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))).source(planBuilder.values(10, symbol)))), Range.closed(1L, 10L));
    // multiple grouping sets with default aggregation with source that produces no rows
    assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.groupingSets(AggregationNode.groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))).source(planBuilder.values(0, symbol)))), Range.singleton(1L));
    // single non-default aggregation with source that produces arbitrary number of rows
    assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.singleGroupingSet(symbol).source(planBuilder.tableScan(ImmutableList.of(symbol), ImmutableMap.of(symbol, columnHandle))))), Range.atLeast(0L));
    // single non-default aggregation with source that produces at least single row
    assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.singleGroupingSet(symbol).source(planBuilder.values(10, symbol)))), Range.closed(1L, 10L));
    // single non-default aggregation with source that produces no rows
    assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.singleGroupingSet(symbol).source(planBuilder.values(0, symbol)))), Range.singleton(0L));
}
Also used : TestingColumnHandle(io.prestosql.spi.connector.TestingColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) TestingColumnHandle(io.prestosql.spi.connector.TestingColumnHandle) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) Symbol(io.prestosql.spi.plan.Symbol) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Aggregations

PlanBuilder (io.prestosql.sql.planner.iterative.rule.test.PlanBuilder)34 Symbol (io.prestosql.spi.plan.Symbol)27 Test (org.testng.annotations.Test)27 ImmutableMap (com.google.common.collect.ImmutableMap)14 PlanNode (io.prestosql.spi.plan.PlanNode)14 ImmutableList (com.google.common.collect.ImmutableList)13 Assignments (io.prestosql.spi.plan.Assignments)13 PlanNodeIdAllocator (io.prestosql.spi.plan.PlanNodeIdAllocator)12 BaseRuleTest (io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest)12 PlanMatchPattern.values (io.prestosql.sql.planner.assertions.PlanMatchPattern.values)11 Optional (java.util.Optional)11 JoinNode (io.prestosql.spi.plan.JoinNode)10 PlanMatchPattern.strictProject (io.prestosql.sql.planner.assertions.PlanMatchPattern.strictProject)10 Predicate (java.util.function.Predicate)10 Collectors (java.util.stream.Collectors)10 BIGINT (io.prestosql.spi.type.BigintType.BIGINT)9 PlanMatchPattern.expression (io.prestosql.sql.planner.assertions.PlanMatchPattern.expression)8 MultiJoinNode (io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode)7 ProjectNode (io.prestosql.spi.plan.ProjectNode)6 TableScanNode (io.prestosql.spi.plan.TableScanNode)6