use of io.prestosql.metadata.SqlScalarFunction in project hetu-core by openlookeng.
the class TestAnnotationEngineForScalars method testMultiScalarParse.
@Test
public void testMultiScalarParse() {
Signature expectedSignature1 = new Signature(QualifiedObjectName.valueOfDefaultFunction("static_method_scalar_1"), FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
Signature expectedSignature2 = new Signature(QualifiedObjectName.valueOfDefaultFunction("static_method_scalar_2"), FunctionKind.SCALAR, BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()));
List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinitions(MultiScalarFunction.class);
assertEquals(functions.size(), 2);
ParametricScalar scalar1 = (ParametricScalar) functions.stream().filter(signature -> signature.getSignature().equals(expectedSignature1)).collect(toImmutableList()).get(0);
ParametricScalar scalar2 = (ParametricScalar) functions.stream().filter(signature -> signature.getSignature().equals(expectedSignature2)).collect(toImmutableList()).get(0);
assertImplementationCount(scalar1, 1, 0, 0);
assertImplementationCount(scalar2, 1, 0, 0);
assertEquals(scalar1.getSignature(), expectedSignature1);
assertTrue(scalar1.isDeterministic());
assertFalse(scalar1.isHidden());
assertEquals(scalar1.getDescription(), "Simple scalar with single implementation based on method 1");
assertEquals(scalar2.getSignature(), expectedSignature2);
assertFalse(scalar2.isDeterministic());
assertTrue(scalar2.isHidden());
assertEquals(scalar2.getDescription(), "Simple scalar with single implementation based on method 2");
}
use of io.prestosql.metadata.SqlScalarFunction 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");
}
use of io.prestosql.metadata.SqlScalarFunction 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");
}
use of io.prestosql.metadata.SqlScalarFunction in project hetu-core by openlookeng.
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);
assertTrue(scalar.isDeterministic());
assertTrue(scalar.isHidden());
}
use of io.prestosql.metadata.SqlScalarFunction 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);
}
Aggregations