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());
}
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));
}
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");
}
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));
}
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");
}
Aggregations