Search in sources :

Example 1 with ParametricScalar

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

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);
    assertFalse(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
}
Also used : ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 2 with ParametricScalar

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

the class TestAnnotationEngineForScalars method testWithNullablePrimitiveArgScalarParse.

@Test
public void testWithNullablePrimitiveArgScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("scalar_with_nullable"), FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature(), DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(WithNullablePrimitiveArgScalarFunction.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 nullable primitive");
    BuiltInScalarFunctionImplementation specialized = scalar.specialize(BoundVariables.builder().build(), 2, METADATA.getFunctionAndTypeManager());
    assertFalse(specialized.getInstanceFactory().isPresent());
    assertEquals(specialized.getArgumentProperty(0), valueTypeArgumentProperty(RETURN_NULL_ON_NULL));
    assertEquals(specialized.getArgumentProperty(1), valueTypeArgumentProperty(USE_NULL_FLAG));
}
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 3 with ParametricScalar

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

the class TestAnnotationEngineForScalars method testParametricScalarParse.

@Test
public void testParametricScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("parametric_scalar"), FunctionKind.SCALAR, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(parseTypeSignature("T")), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(ParametricScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 0, 2, 0);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Parametric scalar description");
}
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 4 with ParametricScalar

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

the class TestAnnotationEngineForScalars method testWithNullableComplexArgScalarParse.

@Test
public void testWithNullableComplexArgScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("scalar_with_nullable_complex"), FunctionKind.SCALAR, 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);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Simple scalar with nullable complex type");
    BuiltInScalarFunctionImplementation specialized = scalar.specialize(BoundVariables.builder().build(), 2, METADATA.getFunctionAndTypeManager());
    assertFalse(specialized.getInstanceFactory().isPresent());
    assertEquals(specialized.getArgumentProperty(0), valueTypeArgumentProperty(RETURN_NULL_ON_NULL));
    assertEquals(specialized.getArgumentProperty(1), valueTypeArgumentProperty(USE_BOXED_TYPE));
}
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 5 with ParametricScalar

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

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