Search in sources :

Example 46 with Signature

use of com.facebook.presto.spi.function.Signature in project presto by prestodb.

the class TestAnnotationEngineForAggregates method testSimpleImplicitSpecializedAggregationParse.

// @Test - this is not yet supported
public void testSimpleImplicitSpecializedAggregationParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "implicit_specialized_aggregate"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(new TypeSignature(ARRAY, TypeSignatureParameter.of(parseTypeSignature("T"))), parseTypeSignature("T")), false);
    ParametricAggregation aggregation = parseFunctionDefinition(ImplicitSpecializedAggregationFunction.class);
    assertEquals(aggregation.getDescription(), "Simple implicit specialized aggregate");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 0, 0, 2);
    AggregationImplementation implementation1 = implementations.getSpecializedImplementations().get(0);
    assertTrue(implementation1.hasSpecializedTypeParameters());
    assertFalse(implementation1.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementation1.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    AggregationImplementation implementation2 = implementations.getSpecializedImplementations().get(1);
    assertTrue(implementation2.hasSpecializedTypeParameters());
    assertFalse(implementation2.hasSpecializedTypeParameters());
    assertTrue(implementation2.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "implicit_specialized_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) 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)

Example 47 with Signature

use of com.facebook.presto.spi.function.Signature in project presto by prestodb.

the class TestAnnotationEngineForAggregates method testInjectOperatorAggregateParse.

@Test
public void testInjectOperatorAggregateParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "inject_operator_aggregate"), FunctionKind.AGGREGATE, DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    ParametricAggregation aggregation = parseFunctionDefinition(InjectOperatorAggregateFunction.class);
    assertEquals(aggregation.getDescription(), "Simple aggregate with operator injected");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    AggregationImplementation implementation = getOnlyElement(implementations.getExactImplementations().values());
    assertTrue(implementation.getStateSerializerFactory().isPresent());
    assertEquals(implementation.getDefinitionClass(), InjectOperatorAggregateFunction.class);
    assertDependencyCount(implementation, 1, 1, 1);
    assertEquals(implementation.getStateSerializerFactoryDependencies().size(), 1);
    assertTrue(implementation.getInputDependencies().get(0) instanceof OperatorImplementationDependency);
    assertTrue(implementation.getCombineDependencies().get(0) instanceof OperatorImplementationDependency);
    assertTrue(implementation.getOutputDependencies().get(0) instanceof OperatorImplementationDependency);
    assertTrue(implementation.getStateSerializerFactoryDependencies().get(0) instanceof OperatorImplementationDependency);
    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().build(), 1, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "inject_operator_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) OperatorImplementationDependency(com.facebook.presto.operator.annotations.OperatorImplementationDependency) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 48 with Signature

use of com.facebook.presto.spi.function.Signature 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 49 with Signature

use of com.facebook.presto.spi.function.Signature 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 50 with Signature

use of com.facebook.presto.spi.function.Signature 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)

Aggregations

Signature (com.facebook.presto.spi.function.Signature)90 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)79 TypeSignature (com.facebook.presto.common.type.TypeSignature)73 Test (org.testng.annotations.Test)64 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)16 ParametricAggregation (com.facebook.presto.operator.aggregation.ParametricAggregation)14 ImmutableList (com.google.common.collect.ImmutableList)14 AggregationImplementation (com.facebook.presto.operator.aggregation.AggregationImplementation)13 AggregationMetadata (com.facebook.presto.operator.aggregation.AggregationMetadata)13 StandardTypes (com.facebook.presto.common.type.StandardTypes)12 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)12 ParametricScalar (com.facebook.presto.operator.scalar.ParametricScalar)12 PrestoException (com.facebook.presto.spi.PrestoException)12 SCALAR (com.facebook.presto.spi.function.FunctionKind.SCALAR)12 ImmutableSet (com.google.common.collect.ImmutableSet)12 Slice (io.airlift.slice.Slice)12 BuiltInScalarFunctionImplementation (com.facebook.presto.operator.scalar.BuiltInScalarFunctionImplementation)11 ADD (com.facebook.presto.common.function.OperatorType.ADD)10 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)10 Math.toIntExact (java.lang.Math.toIntExact)10