Search in sources :

Example 11 with AggregationFunctionMetadata

use of io.trino.metadata.AggregationFunctionMetadata in project trino by trinodb.

the class TestAnnotationEngineForAggregates method testSimpleBlockInputAggregationParse.

@Test
public void testSimpleBlockInputAggregationParse() {
    Signature expectedSignature = new Signature("block_input_aggregate", DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(BlockInputAggregationFunction.class));
    assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple aggregate with @BlockPosition usage");
    assertTrue(aggregation.getFunctionMetadata().isDeterministic());
    assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 1, 0, 0);
    AggregationImplementation implementation = getOnlyElement(implementations.getExactImplementations().values());
    assertEquals(implementation.getDefinitionClass(), BlockInputAggregationFunction.class);
    assertDependencyCount(implementation, 0, 0, 0);
    assertFalse(implementation.hasSpecializedTypeParameters());
    assertEquals(implementation.getInputParameterKinds(), ImmutableList.of(STATE, BLOCK_INPUT_CHANNEL, BLOCK_INDEX));
    BoundSignature boundSignature = new BoundSignature(aggregation.getFunctionMetadata().getSignature().getName(), DoubleType.DOUBLE, ImmutableList.of(DoubleType.DOUBLE));
    AggregationFunctionMetadata aggregationMetadata = aggregation.getAggregationMetadata();
    assertFalse(aggregationMetadata.isOrderSensitive());
    assertFalse(aggregationMetadata.getIntermediateTypes().isEmpty());
    aggregation.specialize(boundSignature, NO_FUNCTION_DEPENDENCIES);
}
Also used : AggregationImplementation(io.trino.operator.aggregation.AggregationImplementation) TypeSignature(io.trino.spi.type.TypeSignature) Signature(io.trino.metadata.Signature) BoundSignature(io.trino.metadata.BoundSignature) BoundSignature(io.trino.metadata.BoundSignature) ParametricAggregation(io.trino.operator.aggregation.ParametricAggregation) AggregationFunctionMetadata(io.trino.metadata.AggregationFunctionMetadata) Test(org.testng.annotations.Test)

Example 12 with AggregationFunctionMetadata

use of io.trino.metadata.AggregationFunctionMetadata in project trino by trinodb.

the class TestAnnotationEngineForAggregates method specializeAggregationFunction.

private static void specializeAggregationFunction(BoundSignature boundSignature, SqlAggregationFunction aggregation) {
    FunctionMetadata functionMetadata = aggregation.getFunctionMetadata();
    FunctionBinding functionBinding = MetadataManager.toFunctionBinding(functionMetadata.getFunctionId(), boundSignature, functionMetadata.getSignature());
    AggregationFunctionMetadata aggregationMetadata = aggregation.getAggregationMetadata();
    assertFalse(aggregationMetadata.isOrderSensitive());
    assertFalse(aggregationMetadata.getIntermediateTypes().isEmpty());
    ResolvedFunction resolvedFunction = METADATA.resolve(TEST_SESSION, functionBinding, functionMetadata, aggregation.getFunctionDependencies(boundSignature));
    FunctionDependencies functionDependencies = new FunctionDependencies(FUNCTION_MANAGER::getScalarFunctionInvoker, resolvedFunction.getTypeDependencies(), resolvedFunction.getFunctionDependencies());
    aggregation.specialize(boundSignature, functionDependencies);
}
Also used : FunctionMetadata(io.trino.metadata.FunctionMetadata) AggregationFunctionMetadata(io.trino.metadata.AggregationFunctionMetadata) FunctionBinding(io.trino.metadata.FunctionBinding) ResolvedFunction(io.trino.metadata.ResolvedFunction) FunctionDependencies(io.trino.metadata.FunctionDependencies) AggregationFunctionMetadata(io.trino.metadata.AggregationFunctionMetadata)

Example 13 with AggregationFunctionMetadata

use of io.trino.metadata.AggregationFunctionMetadata in project trino by trinodb.

the class TestAnnotationEngineForAggregates method testSimpleExactAggregationParse.

@Test
public void testSimpleExactAggregationParse() {
    Signature expectedSignature = new Signature("simple_exact_aggregate", DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(ExactAggregationFunction.class));
    assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple exact aggregate description");
    assertTrue(aggregation.getFunctionMetadata().isDeterministic());
    assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 1, 0, 0);
    AggregationImplementation implementation = getOnlyElement(implementations.getExactImplementations().values());
    assertEquals(implementation.getDefinitionClass(), ExactAggregationFunction.class);
    assertDependencyCount(implementation, 0, 0, 0);
    assertFalse(implementation.hasSpecializedTypeParameters());
    assertEquals(implementation.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL));
    BoundSignature boundSignature = new BoundSignature(expectedSignature.getName(), DoubleType.DOUBLE, ImmutableList.of(DoubleType.DOUBLE));
    AggregationFunctionMetadata aggregationMetadata = aggregation.getAggregationMetadata();
    assertFalse(aggregationMetadata.isOrderSensitive());
    assertFalse(aggregationMetadata.getIntermediateTypes().isEmpty());
    aggregation.specialize(boundSignature, NO_FUNCTION_DEPENDENCIES);
}
Also used : AggregationImplementation(io.trino.operator.aggregation.AggregationImplementation) TypeSignature(io.trino.spi.type.TypeSignature) Signature(io.trino.metadata.Signature) BoundSignature(io.trino.metadata.BoundSignature) BoundSignature(io.trino.metadata.BoundSignature) ParametricAggregation(io.trino.operator.aggregation.ParametricAggregation) AggregationFunctionMetadata(io.trino.metadata.AggregationFunctionMetadata) Test(org.testng.annotations.Test)

Aggregations

AggregationFunctionMetadata (io.trino.metadata.AggregationFunctionMetadata)13 BoundSignature (io.trino.metadata.BoundSignature)10 ParametricAggregation (io.trino.operator.aggregation.ParametricAggregation)10 Test (org.testng.annotations.Test)10 Signature (io.trino.metadata.Signature)9 AggregationImplementation (io.trino.operator.aggregation.AggregationImplementation)9 TypeSignature (io.trino.spi.type.TypeSignature)9 ResolvedFunction (io.trino.metadata.ResolvedFunction)3 ArrayType (io.trino.spi.type.ArrayType)2 RowType (io.trino.spi.type.RowType)2 Type (io.trino.spi.type.Type)2 Symbol (io.trino.sql.planner.Symbol)2 Map (java.util.Map)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 SystemSessionProperties.preferPartialAggregation (io.trino.SystemSessionProperties.preferPartialAggregation)1 FunctionBinding (io.trino.metadata.FunctionBinding)1 FunctionDependencies (io.trino.metadata.FunctionDependencies)1 FunctionMetadata (io.trino.metadata.FunctionMetadata)1 LongVariableConstraint (io.trino.metadata.LongVariableConstraint)1 LiteralImplementationDependency (io.trino.operator.annotations.LiteralImplementationDependency)1