Search in sources :

Example 16 with SqlScalarFunction

use of io.prestosql.metadata.SqlScalarFunction in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testStaticMethodScalarParse.

@Test
public void testStaticMethodScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("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());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Simple scalar with single implementation based on method");
}
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 17 with SqlScalarFunction

use of io.prestosql.metadata.SqlScalarFunction in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testFixedTypeParameterParse.

@Test
public void testFixedTypeParameterParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("fixed_type_parameter_scalar_function"), FunctionKind.SCALAR, 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);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Parametric scalar that uses TypeParameter with fixed type");
}
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 18 with SqlScalarFunction

use of io.prestosql.metadata.SqlScalarFunction in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testComplexParametricScalarParse.

@Test
public void testComplexParametricScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("with_exact_scalar"), FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), BOOLEAN.getTypeSignature(), ImmutableList.of(parseTypeSignature("array(varchar(x))", ImmutableSet.of("x"))), false);
    Signature exactSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("with_exact_scalar"), FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), BOOLEAN.getTypeSignature(), ImmutableList.of(parseTypeSignature("array(varchar(17))")), 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);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Parametric scalar with exact and generic implementations");
}
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)

Aggregations

SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)18 Signature (io.prestosql.spi.function.Signature)16 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)15 Test (org.testng.annotations.Test)14 ParametricScalar (io.prestosql.operator.scalar.ParametricScalar)13 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 Slice (io.airlift.slice.Slice)5 IsNull (io.prestosql.spi.function.IsNull)5 LiteralParameters (io.prestosql.spi.function.LiteralParameters)5 SqlType (io.prestosql.spi.function.SqlType)5 StandardTypes (io.prestosql.spi.type.StandardTypes)5 XxHash64 (io.airlift.slice.XxHash64)4 PolymorphicScalarFunctionBuilder (io.prestosql.metadata.PolymorphicScalarFunctionBuilder)4 SpecializeContext (io.prestosql.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext)3 ImplementationDependency (io.prestosql.operator.annotations.ImplementationDependency)3 LiteralImplementationDependency (io.prestosql.operator.annotations.LiteralImplementationDependency)3 TypeImplementationDependency (io.prestosql.operator.annotations.TypeImplementationDependency)3 ParametricScalarImplementationChoice (io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice)3 PrestoException (io.prestosql.spi.PrestoException)3