Search in sources :

Example 21 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestAnnotationEngineForAggregates method testSimpleExactAggregationParse.

@Test
public void testSimpleExactAggregationParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("simple_exact_aggregate"), FunctionKind.AGGREGATE, DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    ParametricAggregation aggregation = parseFunctionDefinition(ExactAggregationFunction.class);
    assertEquals(aggregation.getDescription(), "Simple exact aggregate description");
    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(), ExactAggregationFunction.class);
    assertDependencyCount(implementation, 0, 0, 0);
    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, METADATA.getFunctionAndTypeManager());
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "simple_exact_aggregate");
}
Also used : AggregationImplementation(io.prestosql.operator.aggregation.AggregationImplementation) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) AggregationMetadata(io.prestosql.operator.aggregation.AggregationMetadata) ParametricAggregation(io.prestosql.operator.aggregation.ParametricAggregation) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 22 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testWithNullablePrimitiveArgScalarParse.

@Test
public void testWithNullablePrimitiveArgScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("scalar_with_nullable"), FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature(), DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(WithNullablePrimitiveArgScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Simple scalar with nullable primitive");
    BuiltInScalarFunctionImplementation specialized = scalar.specialize(BoundVariables.builder().build(), 2, METADATA.getFunctionAndTypeManager());
    assertFalse(specialized.getInstanceFactory().isPresent());
    assertEquals(specialized.getArgumentProperty(0), valueTypeArgumentProperty(RETURN_NULL_ON_NULL));
    assertEquals(specialized.getArgumentProperty(1), valueTypeArgumentProperty(USE_NULL_FLAG));
}
Also used : BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 23 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testParametricScalarParse.

@Test
public void testParametricScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("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());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Parametric scalar description");
}
Also used : TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 24 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testWithNullableComplexArgScalarParse.

@Test
public void testWithNullableComplexArgScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("scalar_with_nullable_complex"), FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature(), DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(WithNullableComplexArgScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Simple scalar with nullable complex type");
    BuiltInScalarFunctionImplementation specialized = scalar.specialize(BoundVariables.builder().build(), 2, METADATA.getFunctionAndTypeManager());
    assertFalse(specialized.getInstanceFactory().isPresent());
    assertEquals(specialized.getArgumentProperty(0), valueTypeArgumentProperty(RETURN_NULL_ON_NULL));
    assertEquals(specialized.getArgumentProperty(1), valueTypeArgumentProperty(USE_BOXED_TYPE));
}
Also used : BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 25 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testConstructorInjectionScalarParse.

@Test
public void testConstructorInjectionScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("parametric_scalar_inject_constructor"), FunctionKind.SCALAR, ImmutableList.of(typeVariable("T")), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(parseTypeSignature("array(T)")), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(ConstructorInjectionScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 2, 0, 1);
    List<ParametricScalarImplementationChoice> parametricScalarImplementationChoices = scalar.getImplementations().getGenericImplementations().get(0).getChoices();
    assertEquals(parametricScalarImplementationChoices.size(), 1);
    List<ImplementationDependency> dependencies = parametricScalarImplementationChoices.get(0).getDependencies();
    assertEquals(dependencies.size(), 0);
    List<ImplementationDependency> constructorDependencies = parametricScalarImplementationChoices.get(0).getConstructorDependencies();
    assertEquals(constructorDependencies.size(), 1);
    assertTrue(constructorDependencies.get(0) instanceof TypeImplementationDependency);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Parametric scalar with type injected though constructor");
}
Also used : TypeImplementationDependency(io.prestosql.operator.annotations.TypeImplementationDependency) ImplementationDependency(io.prestosql.operator.annotations.ImplementationDependency) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalarImplementationChoice(io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) TypeImplementationDependency(io.prestosql.operator.annotations.TypeImplementationDependency) Test(org.testng.annotations.Test)

Aggregations

Signature (io.prestosql.spi.function.Signature)230 Test (org.testng.annotations.Test)186 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)184 TypeSignature (io.prestosql.spi.type.TypeSignature)93 InternalAggregationFunction (io.prestosql.operator.aggregation.InternalAggregationFunction)69 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)41 CallExpression (io.prestosql.spi.relation.CallExpression)35 Type (io.prestosql.spi.type.Type)23 RowExpression (io.prestosql.spi.relation.RowExpression)20 Block (io.prestosql.spi.block.Block)18 ArrayList (java.util.ArrayList)17 ImmutableList (com.google.common.collect.ImmutableList)15 SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)15 MapType (io.prestosql.spi.type.MapType)14 ImmutableSet (com.google.common.collect.ImmutableSet)12 Slice (io.airlift.slice.Slice)12 ParametricAggregation (io.prestosql.operator.aggregation.ParametricAggregation)11 BuiltInScalarFunctionImplementation (io.prestosql.spi.function.BuiltInScalarFunctionImplementation)11 AggregationImplementation (io.prestosql.operator.aggregation.AggregationImplementation)10 AggregationMetadata (io.prestosql.operator.aggregation.AggregationMetadata)10