use of io.trino.operator.aggregation.AggregatorFactory in project trino by trinodb.
the class InMemoryHashAggregationBuilder method toTypes.
public static List<Type> toTypes(List<? extends Type> groupByType, List<AggregatorFactory> factories, Optional<Integer> hashChannel) {
ImmutableList.Builder<Type> types = ImmutableList.builder();
types.addAll(groupByType);
if (hashChannel.isPresent()) {
types.add(BIGINT);
}
for (AggregatorFactory factory : factories) {
types.add(factory.createAggregator().getType());
}
return types.build();
}
use of io.trino.operator.aggregation.AggregatorFactory in project trino by trinodb.
the class HashAggregationOperator method getGlobalAggregationOutput.
private Page getGlobalAggregationOutput() {
// global aggregation output page will only be constructed once,
// so a new PageBuilder is constructed (instead of using PageBuilder.reset)
PageBuilder output = new PageBuilder(globalAggregationGroupIds.size(), types);
for (int groupId : globalAggregationGroupIds) {
output.declarePosition();
int channel = 0;
while (channel < groupByTypes.size()) {
if (channel == groupIdChannel.orElseThrow()) {
output.getBlockBuilder(channel).writeLong(groupId);
} else {
output.getBlockBuilder(channel).appendNull();
}
channel++;
}
if (hashChannel.isPresent()) {
long hashValue = calculateDefaultOutputHash(groupByTypes, groupIdChannel.orElseThrow(), groupId);
output.getBlockBuilder(channel).writeLong(hashValue);
channel++;
}
for (AggregatorFactory aggregatorFactory : aggregatorFactories) {
aggregatorFactory.createAggregator().evaluate(output.getBlockBuilder(channel));
channel++;
}
}
if (output.isEmpty()) {
return null;
}
return output.build();
}
use of io.trino.operator.aggregation.AggregatorFactory in project trino by trinodb.
the class TestSpatialPartitioningInternalAggregation method test.
@Test(dataProvider = "partitionCount")
public void test(int partitionCount) {
TestingAggregationFunction function = getFunction();
List<OGCGeometry> geometries = makeGeometries();
Block geometryBlock = makeGeometryBlock(geometries);
Block partitionCountBlock = BlockAssertions.createRLEBlock(partitionCount, geometries.size());
Rectangle expectedExtent = new Rectangle(-10, -10, Math.nextUp(10.0), Math.nextUp(10.0));
String expectedValue = getSpatialPartitioning(expectedExtent, geometries, partitionCount);
AggregatorFactory aggregatorFactory = function.createAggregatorFactory(SINGLE, Ints.asList(0, 1), OptionalInt.empty());
Page page = new Page(geometryBlock, partitionCountBlock);
Aggregator aggregator = aggregatorFactory.createAggregator();
aggregator.processPage(page);
String aggregation = (String) BlockAssertions.getOnlyValue(function.getFinalType(), getFinalBlock(function.getFinalType(), aggregator));
assertEquals(aggregation, expectedValue);
GroupedAggregator groupedAggregator = aggregatorFactory.createGroupedAggregator();
groupedAggregator.processPage(createGroupByIdBlock(0, page.getPositionCount()), page);
String groupValue = (String) getGroupValue(function.getFinalType(), groupedAggregator, 0);
assertEquals(groupValue, expectedValue);
}
use of io.trino.operator.aggregation.AggregatorFactory in project trino by trinodb.
the class TestAggregationOperator method testDistinctMaskWithNulls.
@Test
public void testDistinctMaskWithNulls() {
AggregatorFactory distinctFactory = LONG_SUM.createDistinctAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.of(1));
DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(distinctFactory));
ByteArrayBlock trueMaskAllNull = new ByteArrayBlock(4, Optional.of(new boolean[] { true, true, true, true }), /* all positions are null */
new byte[] { 1, 1, 1, 1 });
/* non-zero value is true, all masks are true */
Block trueNullRleMask = new RunLengthEncodedBlock(trueMaskAllNull.getSingleValueBlock(0), 4);
List<Page> nullTrueMaskInput = ImmutableList.of(new Page(4, createLongsBlock(1, 2, 3, 4), trueMaskAllNull), new Page(4, createLongsBlock(10, 11, 10, 11), createBooleansBlock(true, true, true, true)), new Page(4, createLongsBlock(5, 6, 7, 8), trueNullRleMask));
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).row(21L).build();
assertOperatorEquals(operatorFactory, driverContext, nullTrueMaskInput, expected);
}
Aggregations