Search in sources :

Example 31 with Signature

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

the class TestAnnotationEngineForScalars method testMultiScalarParse.

@Test
public void testMultiScalarParse() {
    Signature expectedSignature1 = new Signature("static_method_scalar_1", DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
    Signature expectedSignature2 = new Signature("static_method_scalar_2", BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinitions(MultiScalarFunction.class);
    assertEquals(functions.size(), 2);
    ParametricScalar scalar1 = (ParametricScalar) functions.stream().filter(function -> function.getFunctionMetadata().getSignature().equals(expectedSignature1)).collect(toImmutableList()).get(0);
    ParametricScalar scalar2 = (ParametricScalar) functions.stream().filter(function -> function.getFunctionMetadata().getSignature().equals(expectedSignature2)).collect(toImmutableList()).get(0);
    assertImplementationCount(scalar1, 1, 0, 0);
    assertImplementationCount(scalar2, 1, 0, 0);
    FunctionMetadata functionMetadata1 = scalar1.getFunctionMetadata();
    assertEquals(functionMetadata1.getSignature(), expectedSignature1);
    assertTrue(functionMetadata1.isDeterministic());
    assertFalse(functionMetadata1.isHidden());
    assertEquals(functionMetadata1.getDescription(), "Simple scalar with single implementation based on method 1");
    FunctionMetadata functionMetadata2 = scalar2.getFunctionMetadata();
    assertEquals(functionMetadata2.getSignature(), expectedSignature2);
    assertFalse(functionMetadata2.isDeterministic());
    assertTrue(functionMetadata2.isHidden());
    assertEquals(functionMetadata2.getDescription(), "Simple scalar with single implementation based on method 2");
}
Also used : SqlNullable(io.trino.spi.function.SqlNullable) Slice(io.airlift.slice.Slice) Description(io.trino.spi.function.Description) FunctionDependencies(io.trino.metadata.FunctionDependencies) ImplementationDependency(io.trino.operator.annotations.ImplementationDependency) ParametricScalar(io.trino.operator.scalar.ParametricScalar) Type(io.trino.spi.type.Type) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) Assert.assertEquals(org.testng.Assert.assertEquals) ChoicesScalarFunctionImplementation(io.trino.operator.scalar.ChoicesScalarFunctionImplementation) ParametricScalarImplementationChoice(io.trino.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) Test(org.testng.annotations.Test) LiteralParameters(io.trino.spi.function.LiteralParameters) FunctionManager.createTestingFunctionManager(io.trino.metadata.FunctionManager.createTestingFunctionManager) ImmutableList(com.google.common.collect.ImmutableList) Block(io.trino.spi.block.Block) SqlType(io.trino.spi.function.SqlType) ScalarFromAnnotationsParser(io.trino.operator.scalar.annotations.ScalarFromAnnotationsParser) Signature(io.trino.metadata.Signature) Assert.assertFalse(org.testng.Assert.assertFalse) FunctionMetadata(io.trino.metadata.FunctionMetadata) TypeImplementationDependency(io.trino.operator.annotations.TypeImplementationDependency) TypeSignature(io.trino.spi.type.TypeSignature) TypeSignature.arrayType(io.trino.spi.type.TypeSignature.arrayType) ImmutableSet(com.google.common.collect.ImmutableSet) IsNull(io.trino.spi.function.IsNull) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StandardTypes(io.trino.spi.type.StandardTypes) ScalarFunction(io.trino.spi.function.ScalarFunction) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) LiteralImplementationDependency(io.trino.operator.annotations.LiteralImplementationDependency) SqlScalarFunction(io.trino.metadata.SqlScalarFunction) FunctionManager(io.trino.metadata.FunctionManager) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) List(java.util.List) BIGINT(io.trino.spi.type.BigintType.BIGINT) TypeParameter(io.trino.spi.function.TypeParameter) BoundSignature(io.trino.metadata.BoundSignature) Signature.typeVariable(io.trino.metadata.Signature.typeVariable) Assert.assertTrue(org.testng.Assert.assertTrue) LiteralParameter(io.trino.spi.function.LiteralParameter) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) TypeSignatureParameter(io.trino.spi.type.TypeSignatureParameter) FunctionMetadata(io.trino.metadata.FunctionMetadata) Signature(io.trino.metadata.Signature) TypeSignature(io.trino.spi.type.TypeSignature) BoundSignature(io.trino.metadata.BoundSignature) ParametricScalar(io.trino.operator.scalar.ParametricScalar) SqlScalarFunction(io.trino.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 32 with Signature

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

the class TestAnnotationEngineForScalars method testSingleImplementationScalarParse.

@Test
public void testSingleImplementationScalarParse() {
    Signature expectedSignature = new Signature("single_implementation_parametric_scalar", DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(SingleImplementationScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertEquals(functionMetadata.getSignature(), expectedSignature);
    assertTrue(functionMetadata.isDeterministic());
    assertFalse(functionMetadata.isHidden());
    assertEquals(functionMetadata.getDescription(), "Simple scalar with single implementation based on class");
    assertFalse(functionMetadata.getFunctionNullability().isArgumentNullable(0));
    assertImplementationCount(scalar, 1, 0, 0);
    BoundSignature boundSignature = new BoundSignature(expectedSignature.getName(), DOUBLE, ImmutableList.of(DOUBLE));
    ChoicesScalarFunctionImplementation specialized = (ChoicesScalarFunctionImplementation) scalar.specialize(boundSignature, new FunctionDependencies(FUNCTION_MANAGER::getScalarFunctionInvoker, ImmutableMap.of(), ImmutableSet.of()));
    assertFalse(specialized.getChoices().get(0).getInstanceFactory().isPresent());
}
Also used : FunctionMetadata(io.trino.metadata.FunctionMetadata) Signature(io.trino.metadata.Signature) TypeSignature(io.trino.spi.type.TypeSignature) BoundSignature(io.trino.metadata.BoundSignature) BoundSignature(io.trino.metadata.BoundSignature) ParametricScalar(io.trino.operator.scalar.ParametricScalar) ChoicesScalarFunctionImplementation(io.trino.operator.scalar.ChoicesScalarFunctionImplementation) SqlScalarFunction(io.trino.metadata.SqlScalarFunction) FunctionDependencies(io.trino.metadata.FunctionDependencies) Test(org.testng.annotations.Test)

Example 33 with Signature

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

the class TestAnnotationEngineForScalars method testPartiallyFixedTypeParameterParse.

@Test
public void testPartiallyFixedTypeParameterParse() {
    Signature expectedSignature = new Signature("partially_fixed_type_parameter_scalar_function", ImmutableList.of(typeVariable("T1"), typeVariable("T2")), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(PartiallyFixedTypeParameterScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 0, 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(), 1);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertEquals(functionMetadata.getSignature(), expectedSignature);
    assertTrue(functionMetadata.isDeterministic());
    assertFalse(functionMetadata.isHidden());
    assertEquals(functionMetadata.getDescription(), "Parametric scalar that uses TypeParameter with partially fixed type");
}
Also used : FunctionMetadata(io.trino.metadata.FunctionMetadata) ImplementationDependency(io.trino.operator.annotations.ImplementationDependency) TypeImplementationDependency(io.trino.operator.annotations.TypeImplementationDependency) LiteralImplementationDependency(io.trino.operator.annotations.LiteralImplementationDependency) Signature(io.trino.metadata.Signature) TypeSignature(io.trino.spi.type.TypeSignature) BoundSignature(io.trino.metadata.BoundSignature) ParametricScalarImplementationChoice(io.trino.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) ParametricScalar(io.trino.operator.scalar.ParametricScalar) SqlScalarFunction(io.trino.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 34 with Signature

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

the class TestAnnotationEngineForScalars method testParametricScalarParse.

@Test
public void testParametricScalarParse() {
    Signature expectedSignature = new Signature("parametric_scalar", ImmutableList.of(typeVariable("T")), ImmutableList.of(), new TypeSignature("T"), ImmutableList.of(new TypeSignature("T")), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(ParametricScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 0, 2, 0);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertEquals(functionMetadata.getSignature(), expectedSignature);
    assertTrue(functionMetadata.isDeterministic());
    assertFalse(functionMetadata.isHidden());
    assertEquals(functionMetadata.getDescription(), "Parametric scalar description");
}
Also used : FunctionMetadata(io.trino.metadata.FunctionMetadata) TypeSignature(io.trino.spi.type.TypeSignature) Signature(io.trino.metadata.Signature) TypeSignature(io.trino.spi.type.TypeSignature) BoundSignature(io.trino.metadata.BoundSignature) ParametricScalar(io.trino.operator.scalar.ParametricScalar) SqlScalarFunction(io.trino.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Aggregations

Signature (io.trino.metadata.Signature)34 TypeSignature (io.trino.spi.type.TypeSignature)32 BoundSignature (io.trino.metadata.BoundSignature)27 Test (org.testng.annotations.Test)25 SqlScalarFunction (io.trino.metadata.SqlScalarFunction)16 ParametricAggregation (io.trino.operator.aggregation.ParametricAggregation)14 AggregationImplementation (io.trino.operator.aggregation.AggregationImplementation)13 FunctionMetadata (io.trino.metadata.FunctionMetadata)12 ParametricScalar (io.trino.operator.scalar.ParametricScalar)12 AggregationFunctionMetadata (io.trino.metadata.AggregationFunctionMetadata)9 ImmutableList (com.google.common.collect.ImmutableList)8 List (java.util.List)8 TrinoException (io.trino.spi.TrinoException)5 LiteralParameters (io.trino.spi.function.LiteralParameters)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 UsedByGeneratedCode (io.trino.annotation.UsedByGeneratedCode)4 PolymorphicScalarFunctionBuilder (io.trino.metadata.PolymorphicScalarFunctionBuilder)4 SpecializeContext (io.trino.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext)4 Signature.longVariableExpression (io.trino.metadata.Signature.longVariableExpression)4 SignatureBuilder (io.trino.metadata.SignatureBuilder)4