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())));
}
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()));
}
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)))));
}
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);
}
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));
}
Aggregations