Search in sources :

Example 51 with Signature

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

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

Example 53 with Signature

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

the class TestAnnotationEngineForScalars method testSingleImplementationScalarParse.

@Test
public void testSingleImplementationScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "single_implementation_parametric_scalar"), FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(SingleImplementationScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertEquals(scalar.getVisibility(), PUBLIC);
    assertEquals(scalar.getDescription(), "Simple scalar with single implementation based on class");
    assertImplementationCount(scalar, 1, 0, 0);
    BuiltInScalarFunctionImplementation specialized = scalar.specialize(BoundVariables.builder().build(), 1, FUNCTION_AND_TYPE_MANAGER);
    assertFalse(specialized.getInstanceFactory().isPresent());
    assertEquals(specialized.getArgumentProperty(0).getNullConvention(), RETURN_NULL_ON_NULL);
}
Also used : BuiltInScalarFunctionImplementation(com.facebook.presto.operator.scalar.BuiltInScalarFunctionImplementation) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) ParametricScalar(com.facebook.presto.operator.scalar.ParametricScalar) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 54 with Signature

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

the class TestAnnotationEngineForScalars method testStaticMethodScalarParse.

@Test
public void testStaticMethodScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "static_method_scalar"), FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinitions(StaticMethodScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertEquals(scalar.getVisibility(), PUBLIC);
    assertEquals(scalar.getDescription(), "Simple scalar with single implementation based on method");
}
Also used : TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) ParametricScalar(com.facebook.presto.operator.scalar.ParametricScalar) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 55 with Signature

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

the class TestAnnotationEngineForScalars method testParametricScalarParse.

@Test
public void testParametricScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "parametric_scalar"), FunctionKind.SCALAR, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(parseTypeSignature("T")), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(ParametricScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 0, 2, 0);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertEquals(scalar.getVisibility(), PUBLIC);
    assertEquals(scalar.getDescription(), "Parametric scalar description");
}
Also used : TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) ParametricScalar(com.facebook.presto.operator.scalar.ParametricScalar) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) 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