Search in sources :

Example 11 with AggregationImplementation

use of com.facebook.presto.operator.aggregation.AggregationImplementation in project presto by prestodb.

the class TestAnnotationEngineForAggregates method testSimpleBlockInputAggregationParse.

@Test
public void testSimpleBlockInputAggregationParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "block_input_aggregate"), FunctionKind.AGGREGATE, DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    ParametricAggregation aggregation = parseFunctionDefinition(BlockInputAggregationFunction.class);
    assertEquals(aggregation.getDescription(), "Simple aggregate with @BlockPosition usage");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 1, 0, 0);
    AggregationImplementation implementation = getOnlyElement(implementations.getExactImplementations().values());
    assertFalse(implementation.getStateSerializerFactory().isPresent());
    assertEquals(implementation.getDefinitionClass(), BlockInputAggregationFunction.class);
    assertDependencyCount(implementation, 0, 0, 0);
    assertFalse(implementation.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.BLOCK_INPUT_CHANNEL, AggregationMetadata.ParameterMetadata.ParameterType.BLOCK_INDEX);
    assertEquals(implementation.getInputParameterMetadataTypes(), expectedMetadataTypes);
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().build(), 1, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "block_input_aggregate");
}
Also used : AggregationImplementation(com.facebook.presto.operator.aggregation.AggregationImplementation) TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) AggregationMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata) ParametricAggregation(com.facebook.presto.operator.aggregation.ParametricAggregation) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 12 with AggregationImplementation

use of com.facebook.presto.operator.aggregation.AggregationImplementation in project presto by prestodb.

the class TestAnnotationEngineForAggregates method testMultiOutputAggregationParse.

@Test
public void testMultiOutputAggregationParse() {
    Signature expectedSignature1 = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "multi_output_aggregate_1"), FunctionKind.AGGREGATE, DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    Signature expectedSignature2 = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "multi_output_aggregate_2"), FunctionKind.AGGREGATE, DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    List<ParametricAggregation> aggregations = parseFunctionDefinitions(MultiOutputAggregationFunction.class);
    assertEquals(aggregations.size(), 2);
    ParametricAggregation aggregation1 = aggregations.stream().filter(aggregate -> aggregate.getSignature().getNameSuffix().equals("multi_output_aggregate_1")).collect(toImmutableList()).get(0);
    assertEquals(aggregation1.getSignature(), expectedSignature1);
    assertEquals(aggregation1.getDescription(), "Simple multi output function aggregate specialized description");
    ParametricAggregation aggregation2 = aggregations.stream().filter(aggregate -> aggregate.getSignature().getNameSuffix().equals("multi_output_aggregate_2")).collect(toImmutableList()).get(0);
    assertEquals(aggregation2.getSignature(), expectedSignature2);
    assertEquals(aggregation2.getDescription(), "Simple multi output function aggregate generic description");
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    ParametricImplementationsGroup<AggregationImplementation> implementations1 = aggregation1.getImplementations();
    assertImplementationCount(implementations1, 1, 0, 0);
    ParametricImplementationsGroup<AggregationImplementation> implementations2 = aggregation2.getImplementations();
    assertImplementationCount(implementations2, 1, 0, 0);
    AggregationImplementation implementation = getOnlyElement(implementations1.getExactImplementations().values());
    assertFalse(implementation.getStateSerializerFactory().isPresent());
    assertEquals(implementation.getDefinitionClass(), MultiOutputAggregationFunction.class);
    assertDependencyCount(implementation, 0, 0, 0);
    assertFalse(implementation.hasSpecializedTypeParameters());
    assertTrue(implementation.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    InternalAggregationFunction specialized = aggregation1.specialize(BoundVariables.builder().build(), 1, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "multi_output_aggregate_1");
}
Also used : AggregationImplementation(com.facebook.presto.operator.aggregation.AggregationImplementation) TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) AggregationMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata) ParametricAggregation(com.facebook.presto.operator.aggregation.ParametricAggregation) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 13 with AggregationImplementation

use of com.facebook.presto.operator.aggregation.AggregationImplementation in project presto by prestodb.

the class TestAnnotationEngineForAggregates method testInjectLiteralAggregateParse.

@Test
public void testInjectLiteralAggregateParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "inject_literal_aggregate"), FunctionKind.AGGREGATE, parseTypeSignature("varchar(x)", ImmutableSet.of("x")), ImmutableList.of(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))));
    ParametricAggregation aggregation = parseFunctionDefinition(InjectLiteralAggregateFunction.class);
    assertEquals(aggregation.getDescription(), "Simple aggregate with type literal");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertEquals(implementations.getGenericImplementations().size(), 1);
    AggregationImplementation implementation = implementations.getGenericImplementations().get(0);
    assertTrue(implementation.getStateSerializerFactory().isPresent());
    assertEquals(implementation.getDefinitionClass(), InjectLiteralAggregateFunction.class);
    assertDependencyCount(implementation, 1, 1, 1);
    assertEquals(implementation.getStateSerializerFactoryDependencies().size(), 1);
    assertTrue(implementation.getInputDependencies().get(0) instanceof LiteralImplementationDependency);
    assertTrue(implementation.getCombineDependencies().get(0) instanceof LiteralImplementationDependency);
    assertTrue(implementation.getOutputDependencies().get(0) instanceof LiteralImplementationDependency);
    assertTrue(implementation.getStateSerializerFactoryDependencies().get(0) instanceof LiteralImplementationDependency);
    assertFalse(implementation.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementation.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setLongVariable("x", 17L).build(), 1, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), VarcharType.createVarcharType(17));
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "inject_literal_aggregate");
}
Also used : AggregationImplementation(com.facebook.presto.operator.aggregation.AggregationImplementation) LiteralImplementationDependency(com.facebook.presto.operator.annotations.LiteralImplementationDependency) TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) AggregationMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata) ParametricAggregation(com.facebook.presto.operator.aggregation.ParametricAggregation) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 14 with AggregationImplementation

use of com.facebook.presto.operator.aggregation.AggregationImplementation in project presto by prestodb.

the class TestAnnotationEngineForAggregates method testLongConstraintAggregateFunctionParse.

@Test
public void testLongConstraintAggregateFunctionParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "parametric_aggregate_long_constraint"), FunctionKind.AGGREGATE, ImmutableList.of(), ImmutableList.of(new LongVariableConstraint("z", "x + y")), parseTypeSignature("varchar(z)", ImmutableSet.of("z")), ImmutableList.of(parseTypeSignature("varchar(x)", ImmutableSet.of("x")), parseTypeSignature("varchar(y)", ImmutableSet.of("y"))), false);
    ParametricAggregation aggregation = parseFunctionDefinition(LongConstraintAggregateFunction.class);
    assertEquals(aggregation.getDescription(), "Parametric aggregate with parametric type returned");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertEquals(implementations.getGenericImplementations().size(), 1);
    AggregationImplementation implementation = implementations.getGenericImplementations().get(0);
    assertTrue(!implementation.getStateSerializerFactory().isPresent());
    assertEquals(implementation.getDefinitionClass(), LongConstraintAggregateFunction.class);
    assertDependencyCount(implementation, 0, 0, 0);
    assertEquals(implementation.getStateSerializerFactoryDependencies().size(), 0);
    assertFalse(implementation.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementation.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setLongVariable("x", 17L).setLongVariable("y", 13L).setLongVariable("z", 30L).build(), 2, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), VarcharType.createVarcharType(30));
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "parametric_aggregate_long_constraint");
}
Also used : AggregationImplementation(com.facebook.presto.operator.aggregation.AggregationImplementation) LongVariableConstraint(com.facebook.presto.spi.function.LongVariableConstraint) TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) AggregationMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata) ParametricAggregation(com.facebook.presto.operator.aggregation.ParametricAggregation) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 15 with AggregationImplementation

use of com.facebook.presto.operator.aggregation.AggregationImplementation in project presto by prestodb.

the class TestAnnotationEngineForAggregates method testSimpleGenericAggregationFunctionParse.

@Test
public void testSimpleGenericAggregationFunctionParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "simple_generic_implementations"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(parseTypeSignature("T")), false);
    ParametricAggregation aggregation = parseFunctionDefinition(GenericAggregationFunction.class);
    assertEquals(aggregation.getDescription(), "Simple aggregate with two generic implementations");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 0, 0, 2);
    AggregationImplementation implementationDouble = implementations.getGenericImplementations().stream().filter(impl -> impl.getStateClass() == NullableDoubleState.class).collect(toImmutableList()).get(0);
    assertFalse(implementationDouble.getStateSerializerFactory().isPresent());
    assertEquals(implementationDouble.getDefinitionClass(), GenericAggregationFunction.class);
    assertDependencyCount(implementationDouble, 0, 0, 0);
    assertFalse(implementationDouble.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementationDouble.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    assertEquals(implementationDouble.getStateClass(), NullableDoubleState.class);
    AggregationImplementation implementationLong = implementations.getGenericImplementations().stream().filter(impl -> impl.getStateClass() == NullableLongState.class).collect(toImmutableList()).get(0);
    assertFalse(implementationLong.getStateSerializerFactory().isPresent());
    assertEquals(implementationLong.getDefinitionClass(), GenericAggregationFunction.class);
    assertDependencyCount(implementationLong, 0, 0, 0);
    assertFalse(implementationLong.hasSpecializedTypeParameters());
    assertTrue(implementationLong.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    assertEquals(implementationLong.getStateClass(), NullableLongState.class);
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.getParameterTypes().equals(ImmutableList.of(DoubleType.DOUBLE)));
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "simple_generic_implementations");
}
Also used : AggregationImplementation(com.facebook.presto.operator.aggregation.AggregationImplementation) NullableLongState(com.facebook.presto.operator.aggregation.state.NullableLongState) TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) AggregationMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata) ParametricAggregation(com.facebook.presto.operator.aggregation.ParametricAggregation) NullableDoubleState(com.facebook.presto.operator.aggregation.state.NullableDoubleState) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Aggregations

AggregationImplementation (com.facebook.presto.operator.aggregation.AggregationImplementation)15 ParametricAggregation (com.facebook.presto.operator.aggregation.ParametricAggregation)15 AggregationMetadata (com.facebook.presto.operator.aggregation.AggregationMetadata)14 TypeSignature (com.facebook.presto.common.type.TypeSignature)13 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)13 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)13 Signature (com.facebook.presto.spi.function.Signature)13 Test (org.testng.annotations.Test)13 NullableDoubleState (com.facebook.presto.operator.aggregation.state.NullableDoubleState)2 NullableLongState (com.facebook.presto.operator.aggregation.state.NullableLongState)1 LiteralImplementationDependency (com.facebook.presto.operator.annotations.LiteralImplementationDependency)1 OperatorImplementationDependency (com.facebook.presto.operator.annotations.OperatorImplementationDependency)1 TypeImplementationDependency (com.facebook.presto.operator.annotations.TypeImplementationDependency)1 LongVariableConstraint (com.facebook.presto.spi.function.LongVariableConstraint)1