use of io.trino.spi.type.TimestampType.TIMESTAMP_PICOS in project trino by trinodb.
the class TestAccumulatorCompiler method assertGenerateAccumulator.
private static <S extends AccumulatorState, A> void assertGenerateAccumulator(Class<A> aggregation, Class<S> stateInterface) {
AccumulatorStateSerializer<S> stateSerializer = StateCompiler.generateStateSerializer(stateInterface);
AccumulatorStateFactory<S> stateFactory = StateCompiler.generateStateFactory(stateInterface);
BoundSignature signature = new BoundSignature("longTimestampAggregation", RealType.REAL, ImmutableList.of(TIMESTAMP_PICOS));
MethodHandle inputFunction = methodHandle(aggregation, "input", stateInterface, LongTimestamp.class);
inputFunction = normalizeInputMethod(inputFunction, signature, STATE, INPUT_CHANNEL);
MethodHandle combineFunction = methodHandle(aggregation, "combine", stateInterface, stateInterface);
MethodHandle outputFunction = methodHandle(aggregation, "output", stateInterface, BlockBuilder.class);
AggregationMetadata metadata = new AggregationMetadata(inputFunction, Optional.empty(), Optional.of(combineFunction), outputFunction, ImmutableList.of(new AggregationMetadata.AccumulatorStateDescriptor<>(stateInterface, stateSerializer, stateFactory)));
FunctionNullability functionNullability = new FunctionNullability(false, ImmutableList.of(false));
// test if we can compile aggregation
AccumulatorFactory accumulatorFactory = AccumulatorCompiler.generateAccumulatorFactory(signature, metadata, functionNullability);
assertThat(accumulatorFactory).isNotNull();
assertThat(AccumulatorCompiler.generateWindowAccumulatorClass(signature, metadata, functionNullability)).isNotNull();
TestingAggregationFunction aggregationFunction = new TestingAggregationFunction(ImmutableList.of(TIMESTAMP_PICOS), ImmutableList.of(BIGINT), BIGINT, accumulatorFactory);
assertThat(AggregationTestUtils.aggregation(aggregationFunction, createPage(1234))).isEqualTo(1234L);
}
Aggregations