Search in sources :

Example 1 with TIMESTAMP_PICOS

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);
}
Also used : TIMESTAMP_PICOS(io.trino.spi.type.TimestampType.TIMESTAMP_PICOS) BoundSignature(io.trino.metadata.BoundSignature) FunctionNullability(io.trino.metadata.FunctionNullability) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

BoundSignature (io.trino.metadata.BoundSignature)1 FunctionNullability (io.trino.metadata.FunctionNullability)1 TIMESTAMP_PICOS (io.trino.spi.type.TimestampType.TIMESTAMP_PICOS)1 MethodHandle (java.lang.invoke.MethodHandle)1