Search in sources :

Example 1 with ParametricScalarImplementationChoice

use of io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testConstructorInjectionScalarParse.

@Test
public void testConstructorInjectionScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("parametric_scalar_inject_constructor"), FunctionKind.SCALAR, ImmutableList.of(typeVariable("T")), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(parseTypeSignature("array(T)")), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(ConstructorInjectionScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 2, 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(), 0);
    List<ImplementationDependency> constructorDependencies = parametricScalarImplementationChoices.get(0).getConstructorDependencies();
    assertEquals(constructorDependencies.size(), 1);
    assertTrue(constructorDependencies.get(0) instanceof TypeImplementationDependency);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Parametric scalar with type injected though constructor");
}
Also used : TypeImplementationDependency(io.prestosql.operator.annotations.TypeImplementationDependency) ImplementationDependency(io.prestosql.operator.annotations.ImplementationDependency) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalarImplementationChoice(io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) TypeImplementationDependency(io.prestosql.operator.annotations.TypeImplementationDependency) Test(org.testng.annotations.Test)

Example 2 with ParametricScalarImplementationChoice

use of io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testSimpleInjectionScalarParse.

@Test
public void testSimpleInjectionScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("parametric_scalar_inject"), FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(parseTypeSignature("varchar(x)", ImmutableSet.of("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);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Parametric scalar with literal injected");
}
Also used : TypeImplementationDependency(io.prestosql.operator.annotations.TypeImplementationDependency) ImplementationDependency(io.prestosql.operator.annotations.ImplementationDependency) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalarImplementationChoice(io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 3 with ParametricScalarImplementationChoice

use of io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testPartiallyFixedTypeParameterParse.

@Test
public void testPartiallyFixedTypeParameterParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("partially_fixed_type_parameter_scalar_function"), FunctionKind.SCALAR, 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);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Parametric scalar that uses TypeParameter with partially fixed type");
}
Also used : TypeImplementationDependency(io.prestosql.operator.annotations.TypeImplementationDependency) ImplementationDependency(io.prestosql.operator.annotations.ImplementationDependency) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalarImplementationChoice(io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Aggregations

SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)3 ImplementationDependency (io.prestosql.operator.annotations.ImplementationDependency)3 LiteralImplementationDependency (io.prestosql.operator.annotations.LiteralImplementationDependency)3 TypeImplementationDependency (io.prestosql.operator.annotations.TypeImplementationDependency)3 ParametricScalar (io.prestosql.operator.scalar.ParametricScalar)3 ParametricScalarImplementationChoice (io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice)3 Signature (io.prestosql.spi.function.Signature)3 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)3 Test (org.testng.annotations.Test)3