Search in sources :

Example 1 with ParametricScalar

use of io.trino.operator.scalar.ParametricScalar in project trino by trinodb.

the class TestAnnotationEngineForScalars method testWithNullableComplexArgScalarParse.

@Test
public void testWithNullableComplexArgScalarParse() {
    Signature expectedSignature = new Signature("scalar_with_nullable_complex", 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);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertEquals(functionMetadata.getSignature(), expectedSignature);
    assertTrue(functionMetadata.isDeterministic());
    assertFalse(functionMetadata.isHidden());
    assertEquals(functionMetadata.getDescription(), "Simple scalar with nullable complex type");
    assertFalse(functionMetadata.getFunctionNullability().isArgumentNullable(0));
    assertTrue(functionMetadata.getFunctionNullability().isArgumentNullable(1));
    BoundSignature boundSignature = new BoundSignature(expectedSignature.getName(), DOUBLE, ImmutableList.of(DOUBLE, 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 2 with ParametricScalar

use of io.trino.operator.scalar.ParametricScalar in project trino by trinodb.

the class TestAnnotationEngineForScalars method testComplexParametricScalarParse.

@Test
public void testComplexParametricScalarParse() {
    Signature expectedSignature = new Signature("with_exact_scalar", ImmutableList.of(), ImmutableList.of(), BOOLEAN.getTypeSignature(), ImmutableList.of(arrayType(new TypeSignature("varchar", TypeSignatureParameter.typeVariable("x")))), false);
    Signature exactSignature = new Signature("with_exact_scalar", ImmutableList.of(), ImmutableList.of(), BOOLEAN.getTypeSignature(), ImmutableList.of(arrayType(createVarcharType(17).getTypeSignature())), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(ComplexParametricScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar.getImplementations(), 1, 0, 1);
    assertEquals(getOnlyElement(scalar.getImplementations().getExactImplementations().keySet()), exactSignature);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertEquals(functionMetadata.getSignature(), expectedSignature);
    assertTrue(functionMetadata.isDeterministic());
    assertFalse(functionMetadata.isHidden());
    assertEquals(functionMetadata.getDescription(), "Parametric scalar with exact and generic implementations");
}
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)

Example 3 with ParametricScalar

use of io.trino.operator.scalar.ParametricScalar in project trino by trinodb.

the class TestAnnotationEngineForScalars method testSimpleInjectionScalarParse.

@Test
public void testSimpleInjectionScalarParse() {
    Signature expectedSignature = new Signature("parametric_scalar_inject", ImmutableList.of(), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(new TypeSignature("varchar", TypeSignatureParameter.typeVariable("x"))), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(SimpleInjectionScalarFunction.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);
    assertTrue(dependencies.get(0) instanceof LiteralImplementationDependency);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertEquals(functionMetadata.getSignature(), expectedSignature);
    assertTrue(functionMetadata.isDeterministic());
    assertFalse(functionMetadata.isHidden());
    assertEquals(functionMetadata.getDescription(), "Parametric scalar with literal injected");
}
Also used : FunctionMetadata(io.trino.metadata.FunctionMetadata) TypeSignature(io.trino.spi.type.TypeSignature) ImplementationDependency(io.trino.operator.annotations.ImplementationDependency) TypeImplementationDependency(io.trino.operator.annotations.TypeImplementationDependency) LiteralImplementationDependency(io.trino.operator.annotations.LiteralImplementationDependency) 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 4 with ParametricScalar

use of io.trino.operator.scalar.ParametricScalar in project trino by trinodb.

the class TestAnnotationEngineForScalars method testFixedTypeParameterParse.

@Test
public void testFixedTypeParameterParse() {
    Signature expectedSignature = new Signature("fixed_type_parameter_scalar_function", ImmutableList.of(), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(FixedTypeParameterScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 1, 0, 0);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertEquals(functionMetadata.getSignature(), expectedSignature);
    assertTrue(functionMetadata.isDeterministic());
    assertFalse(functionMetadata.isHidden());
    assertEquals(functionMetadata.getDescription(), "Parametric scalar that uses TypeParameter with fixed type");
}
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 5 with ParametricScalar

use of io.trino.operator.scalar.ParametricScalar in project trino by trinodb.

the class TestAnnotationEngineForScalars method testHiddenScalarParse.

@Test
public void testHiddenScalarParse() {
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(HiddenScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertTrue(functionMetadata.isDeterministic());
    assertTrue(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

ParametricScalar (io.trino.operator.scalar.ParametricScalar)14 FunctionMetadata (io.trino.metadata.FunctionMetadata)13 SqlScalarFunction (io.trino.metadata.SqlScalarFunction)13 Test (org.testng.annotations.Test)13 Signature (io.trino.metadata.Signature)12 BoundSignature (io.trino.metadata.BoundSignature)11 TypeSignature (io.trino.spi.type.TypeSignature)11 FunctionDependencies (io.trino.metadata.FunctionDependencies)4 ImplementationDependency (io.trino.operator.annotations.ImplementationDependency)4 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 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 Slice (io.airlift.slice.Slice)1 FunctionManager (io.trino.metadata.FunctionManager)1