use of com.facebook.presto.spi.plan.AggregationNode.Aggregation in project presto by prestodb.
the class AggregatedOrcPageSource method getNextPage.
@Override
public Page getNextPage() {
if (completed) {
return null;
}
long start = System.nanoTime();
Block[] blocks = new Block[columnHandles.size()];
for (int fieldId = 0; fieldId < blocks.length; fieldId++) {
HiveColumnHandle columnHandle = columnHandles.get(fieldId);
Aggregation aggregation = columnHandle.getPartialAggregation().get();
int columnIndex = columnHandle.getHiveColumnIndex();
Type type = typeManager.getType(columnHandle.getTypeSignature());
BlockBuilder blockBuilder = type.createBlockBuilder(null, batchSize, 0);
FunctionHandle functionHandle = aggregation.getFunctionHandle();
if (functionResolution.isCountFunction(functionHandle)) {
if (aggregation.getArguments().isEmpty()) {
blockBuilder = blockBuilder.writeLong(footer.getNumberOfRows());
} else {
writeNonNullCount(columnIndex, blockBuilder);
}
completedBytes += INTEGER.getFixedSize();
} else if (functionResolution.isMaxFunction(functionHandle)) {
writeMinMax(columnIndex, type, columnHandle.getHiveType(), blockBuilder, false);
} else if (functionResolution.isMinFunction(functionHandle)) {
writeMinMax(columnIndex, type, columnHandle.getHiveType(), blockBuilder, true);
} else {
throw new UnsupportedOperationException(aggregation.getFunctionHandle().toString() + " is not supported");
}
blocks[fieldId] = blockBuilder.build();
}
completed = true;
readTimeNanos += System.nanoTime() - start;
return new Page(batchSize, blocks);
}
use of com.facebook.presto.spi.plan.AggregationNode.Aggregation in project presto by prestodb.
the class SingleDistinctAggregationToGroupBy method apply.
@Override
public Result apply(AggregationNode aggregation, Captures captures, Context context) {
List<Set<RowExpression>> argumentSets = extractArgumentSets(aggregation).collect(Collectors.toList());
Set<VariableReferenceExpression> variables = Iterables.getOnlyElement(argumentSets).stream().map(OriginalExpressionUtils::castToExpression).map(context.getVariableAllocator()::toVariableReference).collect(Collectors.toSet());
return Result.ofPlanNode(new AggregationNode(aggregation.getSourceLocation(), aggregation.getId(), new AggregationNode(aggregation.getSourceLocation(), context.getIdAllocator().getNextId(), aggregation.getSource(), ImmutableMap.of(), singleGroupingSet(ImmutableList.<VariableReferenceExpression>builder().addAll(aggregation.getGroupingKeys()).addAll(variables).build()), ImmutableList.of(), SINGLE, Optional.empty(), Optional.empty()), // remove DISTINCT flag from function calls
aggregation.getAggregations().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> removeDistinct(e.getValue()))), aggregation.getGroupingSets(), emptyList(), aggregation.getStep(), aggregation.getHashVariable(), aggregation.getGroupIdVariable()));
}
use of com.facebook.presto.spi.plan.AggregationNode.Aggregation in project presto by prestodb.
the class TransformExistsApplyToLateralNode method rewriteToDefaultAggregation.
private PlanNode rewriteToDefaultAggregation(ApplyNode parent, Context context) {
VariableReferenceExpression count = context.getVariableAllocator().newVariable("count", BIGINT);
VariableReferenceExpression exists = getOnlyElement(parent.getSubqueryAssignments().getVariables());
return new LateralJoinNode(parent.getSourceLocation(), parent.getId(), parent.getInput(), new ProjectNode(context.getIdAllocator().getNextId(), new AggregationNode(parent.getSourceLocation(), context.getIdAllocator().getNextId(), parent.getSubquery(), ImmutableMap.of(count, new Aggregation(new CallExpression(exists.getSourceLocation(), "count", functionResolution.countFunction(), BIGINT, ImmutableList.of()), Optional.empty(), Optional.empty(), false, Optional.empty())), globalAggregation(), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty()), Assignments.of(exists, castToRowExpression(new ComparisonExpression(GREATER_THAN, asSymbolReference(count), new Cast(new LongLiteral("0"), BIGINT.toString()))))), parent.getCorrelation(), INNER, parent.getOriginSubqueryError());
}
use of com.facebook.presto.spi.plan.AggregationNode.Aggregation in project presto by prestodb.
the class TestTypeValidator method testInvalidAggregationFunctionCall.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Expected input types are \\[double\\] but getting \\[bigint\\]")
public void testInvalidAggregationFunctionCall() {
VariableReferenceExpression aggregationVariable = variableAllocator.newVariable("sum", DOUBLE);
PlanNode node = new AggregationNode(Optional.empty(), newId(), baseTableScan, ImmutableMap.of(aggregationVariable, new Aggregation(new CallExpression("sum", SUM, DOUBLE, ImmutableList.of(variableA)), Optional.empty(), Optional.empty(), false, Optional.empty())), singleGroupingSet(ImmutableList.of(variableA, variableB)), ImmutableList.of(), SINGLE, Optional.empty(), Optional.empty());
assertTypesValid(node);
}
use of com.facebook.presto.spi.plan.AggregationNode.Aggregation in project presto by prestodb.
the class TestTypeValidator method testValidAggregation.
@Test
public void testValidAggregation() {
VariableReferenceExpression aggregationVariable = variableAllocator.newVariable("sum", DOUBLE);
PlanNode node = new AggregationNode(Optional.empty(), newId(), baseTableScan, ImmutableMap.of(aggregationVariable, new Aggregation(new CallExpression("sum", SUM, DOUBLE, ImmutableList.of(variableC)), Optional.empty(), Optional.empty(), false, Optional.empty())), singleGroupingSet(ImmutableList.of(variableA, variableB)), ImmutableList.of(), SINGLE, Optional.empty(), Optional.empty());
assertTypesValid(node);
}
Aggregations