use of com.facebook.presto.spi.plan.AggregationNode in project presto by prestodb.
the class TestUnion method assertAtMostOneAggregationBetweenRemoteExchanges.
private static void assertAtMostOneAggregationBetweenRemoteExchanges(Plan plan) {
List<PlanNode> fragments = searchFrom(plan.getRoot()).where(TestUnion::isRemoteExchange).findAll().stream().flatMap(exchangeNode -> exchangeNode.getSources().stream()).collect(toList());
for (PlanNode fragment : fragments) {
List<PlanNode> aggregations = searchFrom(fragment).where(AggregationNode.class::isInstance).recurseOnlyWhen(TestUnion::isNotRemoteExchange).findAll();
assertFalse(aggregations.size() > 1, "More than a single AggregationNode between remote exchanges");
}
}
use of com.facebook.presto.spi.plan.AggregationNode in project presto by prestodb.
the class PinotPushdownUtils method handlePushDownSingleDistinctCount.
/**
* Try to push down query like: `SELECT count(distinct $COLUMN) FROM myTable` to Pinot as `SELECT distinctCount($COLUMN) FROM myTable`.
* This function only handles the case of an AggregationNode (COUNT on $COLUMN) on top of an AggregationNode(of non-aggregate on $COLUMN).
*
* @param nodeBuilder
* @param aggregationNode
* @param outputColumn
* @param aggregation
* @return true if push down successfully otherwise false.
*/
private static boolean handlePushDownSingleDistinctCount(ImmutableList.Builder<AggregationColumnNode> nodeBuilder, AggregationNode aggregationNode, VariableReferenceExpression outputColumn, AggregationNode.Aggregation aggregation) {
if (!aggregation.getCall().getDisplayName().equalsIgnoreCase(COUNT_FUNCTION_NAME)) {
return false;
}
List<RowExpression> arguments = aggregation.getCall().getArguments();
if (arguments.size() != 1) {
return false;
}
RowExpression aggregationArgument = arguments.get(0);
// Handle the case of Count Aggregation on top of a Non-Agg GroupBy Aggregation.
if (!(aggregationNode.getSource() instanceof AggregationNode)) {
return false;
}
AggregationNode sourceAggregationNode = (AggregationNode) aggregationNode.getSource();
Set<String> sourceAggregationGroupSet = getGroupKeys(sourceAggregationNode.getGroupingKeys());
Set<String> aggregationGroupSet = getGroupKeys(aggregationNode.getGroupingKeys());
aggregationGroupSet.add(aggregationArgument.toString());
if (!sourceAggregationGroupSet.containsAll(aggregationGroupSet) && aggregationGroupSet.containsAll(sourceAggregationGroupSet)) {
return false;
}
nodeBuilder.add(new AggregationFunctionColumnNode(outputColumn, new CallExpression(aggregation.getCall().getSourceLocation(), PINOT_DISTINCT_COUNT_FUNCTION_NAME, aggregation.getFunctionHandle(), aggregation.getCall().getType(), ImmutableList.of(aggregationArgument))));
return true;
}
use of com.facebook.presto.spi.plan.AggregationNode in project presto by prestodb.
the class TestPinotSplitManager method testBrokerTopNLarge.
private void testBrokerTopNLarge(PinotTableHandle table, int sessionTopNLarge, int configTopNLarge, boolean useSql) {
String topNLimitKeyword = useSql ? "LIMIT " : "TOP ";
PinotConfig pinotConfig = new PinotConfig().setUsePinotSqlForBrokerQueries(useSql).setTopNLarge(configTopNLarge);
SessionHolder sessionHolder = new SessionHolder(pinotConfig);
ConnectorSession session = createSessionWithTopNLarge(sessionTopNLarge, pinotConfig);
PlanBuilder planBuilder = createPlanBuilder(sessionHolder);
PlanNode tableScanNode = tableScan(planBuilder, table, regionId, city, fare, secondsSinceEpoch);
AggregationNode aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city"), variable("regionid")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", sessionHolder)).addAggregation(planBuilder.variable("count_regionid"), getRowExpression("count(regionid)", sessionHolder)));
PinotQueryGenerator.PinotQueryGeneratorResult pinotQueryGeneratorResult = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(aggregationNode, session).get();
String[] limits = pinotQueryGeneratorResult.getGeneratedPinotQuery().getQuery().split(topNLimitKeyword);
assertEquals(Integer.parseInt(limits[1]), sessionTopNLarge);
aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city"), variable("regionid")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", sessionHolder)).addAggregation(planBuilder.variable("count_regionid"), getRowExpression("count(regionid)", sessionHolder)));
pinotQueryGeneratorResult = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(aggregationNode, sessionHolder.getConnectorSession()).get();
limits = pinotQueryGeneratorResult.getGeneratedPinotQuery().getQuery().split(topNLimitKeyword);
assertEquals(Integer.parseInt(limits[1]), configTopNLarge);
}
use of com.facebook.presto.spi.plan.AggregationNode in project presto by prestodb.
the class TestPinotQueryGenerator method testAggregationWithOrderByPushDownInTopN.
@Test(expectedExceptions = NoSuchElementException.class)
public void testAggregationWithOrderByPushDownInTopN() {
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, city, fare);
AggregationNode agg = planBuilder.aggregation(aggBuilder -> aggBuilder.source(tableScanNode).singleGroupingSet(variable("city")).addAggregation(planBuilder.variable("agg"), getRowExpression("sum(fare)", defaultSessionHolder)));
TopNNode topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), agg, 50L, new OrderingScheme(ImmutableList.of(new Ordering(variable("city"), SortOrder.DESC_NULLS_FIRST))), TopNNode.Step.FINAL);
testPinotQuery(pinotConfig, topN, "", defaultSessionHolder, ImmutableMap.of());
}
use of com.facebook.presto.spi.plan.AggregationNode in project presto by prestodb.
the class TestPinotQueryGeneratorSql method testAggregationWithGroupBy.
@Test
public void testAggregationWithGroupBy() {
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, regionId, city, fare);
AggregationNode aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city"), variable("regionid")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", defaultSessionHolder)).addAggregation(planBuilder.variable("count_regionid"), getRowExpression("count(regionid)", defaultSessionHolder)));
testPinotQuery(pinotConfig, aggregationNode, ImmutableList.of("SELECT city, regionId, sum(fare), count(regionId) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000", "SELECT city, regionId, count(regionId), sum(fare) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000"), defaultSessionHolder, ImmutableMap.of());
ProjectNode project = planBuilder.project(Assignments.builder().put(variable("count_regionid"), variable("count_regionid")).put(variable("city"), variable("city")).put(variable("regionid"), variable("regionid")).put(variable("sum_fare"), variable("sum_fare")).build(), aggregationNode);
testPinotQuery(pinotConfig, project, "SELECT city, regionId, count(regionId), sum(fare) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000", defaultSessionHolder, ImmutableMap.of());
project = planBuilder.project(Assignments.builder().put(variable("count_regionid"), variable("count_regionid")).put(variable("regionid"), variable("regionid")).put(variable("sum_fare"), variable("sum_fare")).build(), aggregationNode);
testPinotQuery(pinotConfig, project, "SELECT city, regionId, count(regionId), sum(fare) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000", defaultSessionHolder, ImmutableMap.of());
project = planBuilder.project(Assignments.builder().put(variable("count_regionid"), variable("count_regionid")).put(variable("city"), variable("city")).put(variable("sum_fare"), variable("sum_fare")).build(), aggregationNode);
testPinotQuery(pinotConfig, project, "SELECT city, regionId, count(regionId), sum(fare) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000", defaultSessionHolder, ImmutableMap.of());
project = planBuilder.project(Assignments.builder().put(variable("sum_fare"), variable("sum_fare")).put(variable("count_regionid"), variable("count_regionid")).build(), aggregationNode);
testPinotQuery(pinotConfig, project, "SELECT city, regionId, sum(fare), count(regionId) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000", defaultSessionHolder, ImmutableMap.of());
}
Aggregations