Search in sources :

Example 11 with FunctionMetadata

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

the class TestAnnotationEngineForScalars method testStaticMethodScalarParse.

@Test
public void testStaticMethodScalarParse() {
    Signature expectedSignature = new Signature("static_method_scalar", DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinitions(StaticMethodScalarFunction.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 method");
}
Also used : 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 12 with FunctionMetadata

use of io.trino.metadata.FunctionMetadata 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 13 with FunctionMetadata

use of io.trino.metadata.FunctionMetadata 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 14 with FunctionMetadata

use of io.trino.metadata.FunctionMetadata 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 15 with FunctionMetadata

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

the class TestAnnotationEngineForScalars method testNonDeterministicScalarParse.

@Test
public void testNonDeterministicScalarParse() {
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(NonDeterministicScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertFalse(functionMetadata.isDeterministic());
    assertFalse(functionMetadata.isHidden());
}
Also used : FunctionMetadata(io.trino.metadata.FunctionMetadata) ParametricScalar(io.trino.operator.scalar.ParametricScalar) SqlScalarFunction(io.trino.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Aggregations

FunctionMetadata (io.trino.metadata.FunctionMetadata)16 SqlScalarFunction (io.trino.metadata.SqlScalarFunction)13 ParametricScalar (io.trino.operator.scalar.ParametricScalar)13 Test (org.testng.annotations.Test)13 BoundSignature (io.trino.metadata.BoundSignature)12 Signature (io.trino.metadata.Signature)12 TypeSignature (io.trino.spi.type.TypeSignature)11 FunctionDependencies (io.trino.metadata.FunctionDependencies)6 ImplementationDependency (io.trino.operator.annotations.ImplementationDependency)5 LiteralImplementationDependency (io.trino.operator.annotations.LiteralImplementationDependency)4 TypeImplementationDependency (io.trino.operator.annotations.TypeImplementationDependency)4 ChoicesScalarFunctionImplementation (io.trino.operator.scalar.ChoicesScalarFunctionImplementation)4 ParametricScalarImplementationChoice (io.trino.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice)4 FunctionBinding (io.trino.metadata.FunctionBinding)3 ImmutableList (com.google.common.collect.ImmutableList)2 AggregationFunctionMetadata (io.trino.metadata.AggregationFunctionMetadata)2 TrinoException (io.trino.spi.TrinoException)2 List (java.util.List)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1