Search in sources :

Example 11 with ParametricScalar

use of io.prestosql.operator.scalar.ParametricScalar in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testSingleImplementationScalarParse.

@Test
public void testSingleImplementationScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("single_implementation_parametric_scalar"), FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(SingleImplementationScalarFunction.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 class");
    assertImplementationCount(scalar, 1, 0, 0);
    BuiltInScalarFunctionImplementation specialized = scalar.specialize(BoundVariables.builder().build(), 1, METADATA.getFunctionAndTypeManager());
    assertFalse(specialized.getInstanceFactory().isPresent());
    assertEquals(specialized.getArgumentProperty(0).getNullConvention(), RETURN_NULL_ON_NULL);
}
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 12 with ParametricScalar

use of io.prestosql.operator.scalar.ParametricScalar 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 13 with ParametricScalar

use of io.prestosql.operator.scalar.ParametricScalar 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 14 with ParametricScalar

use of io.prestosql.operator.scalar.ParametricScalar 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

ParametricScalar (io.prestosql.operator.scalar.ParametricScalar)14 SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)13 Test (org.testng.annotations.Test)13 Signature (io.prestosql.spi.function.Signature)12 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)11 ImplementationDependency (io.prestosql.operator.annotations.ImplementationDependency)4 LiteralImplementationDependency (io.prestosql.operator.annotations.LiteralImplementationDependency)4 TypeImplementationDependency (io.prestosql.operator.annotations.TypeImplementationDependency)4 ParametricScalarImplementationChoice (io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice)4 BuiltInScalarFunctionImplementation (io.prestosql.spi.function.BuiltInScalarFunctionImplementation)4 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 Slice (io.airlift.slice.Slice)1 BoundVariables (io.prestosql.metadata.BoundVariables)1 Metadata (io.prestosql.metadata.Metadata)1 MetadataManager.createTestMetadataManager (io.prestosql.metadata.MetadataManager.createTestMetadataManager)1 ParametricImplementationsGroup (io.prestosql.operator.ParametricImplementationsGroup)1 SpecializedSignature (io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.SpecializedSignature)1