use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.
the class TestPinotSplitManager method testSegmentSplitsHelperNoFilter.
private void testSegmentSplitsHelperNoFilter(PinotTableHandle table, int segmentsPerSplit, int expectedNumSplits, boolean expectFilter) {
PinotConfig pinotConfig = new PinotConfig().setForbidBrokerQueries(false);
SessionHolder sessionHolder = new SessionHolder(pinotConfig);
PlanBuilder planBuilder = createPlanBuilder(sessionHolder);
PlanNode plan = tableScan(planBuilder, table, regionId, city, fare, secondsSinceEpoch);
PinotQueryGenerator.PinotQueryGeneratorResult pinotQueryGeneratorResult = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(plan, sessionHolder.getConnectorSession()).get();
List<PinotColumnHandle> expectedHandles = ImmutableList.copyOf(pinotQueryGeneratorResult.getContext().getAssignments(pinotQueryGeneratorResult.getGeneratedPinotQuery().getFormat() == PinotQueryGenerator.PinotQueryFormat.SQL).values());
PinotQueryGenerator.GeneratedPinotQuery generatedPql = pinotQueryGeneratorResult.getGeneratedPinotQuery();
PinotTableHandle pinotTableHandle = new PinotTableHandle(table.getConnectorId(), table.getSchemaName(), table.getTableName(), Optional.of(false), Optional.of(expectedHandles), Optional.of(generatedPql));
List<PinotSplit> splits = getSplitsHelper(pinotTableHandle, segmentsPerSplit, false);
assertSplits(splits, expectedNumSplits, SEGMENT);
splits.forEach(s -> assertSegmentSplitWellFormed(s, expectFilter));
}
use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.
the class TestPinotPlanOptimizerSql method testDistinctLimitPushdown.
@Test
public void testDistinctLimitPushdown() {
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
PlanNode originalPlan = distinctLimit(planBuilder, ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "regionid", BIGINT)), 50L, tableScan(planBuilder, pinotTable, regionId));
PlanNode optimized = getOptimizedPlan(planBuilder, originalPlan);
assertPlanMatch(optimized, PinotTableScanMatcher.match(pinotTable, Optional.of("SELECT regionId FROM hybrid GROUP BY regionId LIMIT 50"), Optional.of(false), originalPlan.getOutputVariables(), useSqlSyntax()), typeProvider);
planBuilder = createPlanBuilder(defaultSessionHolder);
originalPlan = distinctLimit(planBuilder, ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "regionid", BIGINT), new VariableReferenceExpression(Optional.empty(), "city", VARCHAR)), 50L, tableScan(planBuilder, pinotTable, regionId, city));
optimized = getOptimizedPlan(planBuilder, originalPlan);
assertPlanMatch(optimized, PinotTableScanMatcher.match(pinotTable, Optional.of("SELECT regionId, city FROM hybrid GROUP BY regionId, city LIMIT 50"), Optional.of(false), originalPlan.getOutputVariables(), useSqlSyntax()), typeProvider);
}
use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.
the class TestPinotQueryGenerator method helperTestMultipleAggregatesWithGroupBy.
protected void helperTestMultipleAggregatesWithGroupBy(PinotConfig givenPinotConfig) {
Map<String, String> outputVariables = ImmutableMap.of("agg", "count(*)", "min", "min(fare)");
PlanNode justScan = buildPlan(planBuilder -> tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare));
testPinotQuery(givenPinotConfig, planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(justScan).singleGroupingSet(variable("city")).addAggregation(planBuilder.variable("agg"), getRowExpression("count(*)", defaultSessionHolder)).addAggregation(planBuilder.variable("min"), getRowExpression("min(fare)", defaultSessionHolder))), String.format("SELECT %s FROM realtimeOnly GROUP BY city %s 10000", getExpectedAggOutput("__expressions__", "city"), getGroupByLimitKey()), defaultSessionHolder, outputVariables);
}
use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.
the class TestPinotQueryGenerator method testUnaryAggregationHelper.
private void testUnaryAggregationHelper(BiConsumer<PlanBuilder, PlanBuilder.AggregationBuilder> aggregationFunctionBuilder, String expectedAggOutput) {
PlanNode justScan = buildPlan(planBuilder -> tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare));
PlanNode filter = buildPlan(planBuilder -> filter(planBuilder, tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare), getRowExpression("fare > 3", defaultSessionHolder)));
PlanNode anotherFilter = buildPlan(planBuilder -> filter(planBuilder, tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare), getRowExpression("secondssinceepoch between 200 and 300 and regionid >= 40", defaultSessionHolder)));
PlanNode filterWithMultiValue = buildPlan(planBuilder -> filter(planBuilder, tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare, scores), getRowExpression("contains(scores, 100) OR contains(scores, 200)", defaultSessionHolder)));
testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(justScan).globalGrouping())), format("SELECT %s FROM realtimeOnly", getExpectedAggOutput(expectedAggOutput, "")));
testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(filter).globalGrouping())), format("SELECT %s FROM realtimeOnly WHERE (fare > 3)", getExpectedAggOutput(expectedAggOutput, "")));
testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(filter).singleGroupingSet(variable("regionid")))), format("SELECT %s FROM realtimeOnly WHERE (fare > 3) GROUP BY regionId %s 10000", getExpectedAggOutput(expectedAggOutput, "regionId"), getGroupByLimitKey()));
testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(justScan).singleGroupingSet(variable("regionid")))), format("SELECT %s FROM realtimeOnly GROUP BY regionId %s 10000", getExpectedAggOutput(expectedAggOutput, "regionId"), getGroupByLimitKey()));
testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(anotherFilter).singleGroupingSet(variable("regionid"), variable("city")))), format("SELECT %s FROM realtimeOnly WHERE ((secondsSinceEpoch BETWEEN 200 AND 300) AND (regionId >= 40)) GROUP BY regionId, city %s 10000", getExpectedAggOutput(expectedAggOutput, "regionId, city"), getGroupByLimitKey()));
testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(filterWithMultiValue).singleGroupingSet(variable("regionid"), variable("city")))), format("SELECT %s FROM realtimeOnly WHERE ((scores = 100) OR (scores = 200)) GROUP BY regionId, city %s 10000", getExpectedAggOutput(expectedAggOutput, "regionId, city"), getGroupByLimitKey()));
}
use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.
the class TestPinotQueryGenerator method testDistinctCountPushdown.
@Test
public void testDistinctCountPushdown() {
PlanNode justScan = buildPlan(planBuilder -> tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare));
PlanNode distinctAggregation = buildPlan(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(justScan).singleGroupingSet(variable("regionid"))));
testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(distinctAggregation).globalGrouping().addAggregation(variable("count_regionid"), getRowExpression("count(regionid)", defaultSessionHolder))), "SELECT DISTINCTCOUNT(regionId) FROM realtimeOnly");
}
Aggregations