Search in sources :

Example 1 with InvocationConvention

use of io.prestosql.spi.function.InvocationConvention in project hetu-core by openlookeng.

the class TestFunctionInvokerProvider method testFunctionInvokerProvider.

@Test
public void testFunctionInvokerProvider() {
    assertTrue(checkChoice(ImmutableList.of(new ArgumentProperty(VALUE_TYPE, Optional.of(USE_BOXED_TYPE), Optional.empty()), new ArgumentProperty(VALUE_TYPE, Optional.of(USE_BOXED_TYPE), Optional.empty())), true, false, Optional.of(new InvocationConvention(ImmutableList.of(BOXED_NULLABLE, BOXED_NULLABLE), InvocationReturnConvention.NULLABLE_RETURN, false))));
    assertTrue(checkChoice(ImmutableList.of(new ArgumentProperty(VALUE_TYPE, Optional.of(RETURN_NULL_ON_NULL), Optional.empty()), new ArgumentProperty(VALUE_TYPE, Optional.of(BLOCK_AND_POSITION), Optional.empty()), new ArgumentProperty(VALUE_TYPE, Optional.of(BLOCK_AND_POSITION), Optional.empty())), false, false, Optional.of(new InvocationConvention(ImmutableList.of(NEVER_NULL, BLOCK_POSITION, BLOCK_POSITION), InvocationReturnConvention.FAIL_ON_NULL, false))));
    assertTrue(checkChoice(ImmutableList.of(new ArgumentProperty(VALUE_TYPE, Optional.of(BLOCK_AND_POSITION), Optional.empty()), new ArgumentProperty(VALUE_TYPE, Optional.of(USE_NULL_FLAG), Optional.empty()), new ArgumentProperty(VALUE_TYPE, Optional.of(BLOCK_AND_POSITION), Optional.empty())), false, false, Optional.of(new InvocationConvention(ImmutableList.of(BLOCK_POSITION, NULL_FLAG, BLOCK_POSITION), InvocationReturnConvention.FAIL_ON_NULL, false))));
    assertFalse(checkChoice(ImmutableList.of(new ArgumentProperty(VALUE_TYPE, Optional.of(BLOCK_AND_POSITION), Optional.empty()), new ArgumentProperty(VALUE_TYPE, Optional.of(USE_BOXED_TYPE), Optional.empty())), false, false, Optional.of(new InvocationConvention(ImmutableList.of(BLOCK_POSITION, BOXED_NULLABLE), InvocationReturnConvention.NULLABLE_RETURN, false))));
    assertFalse(checkChoice(ImmutableList.of(new ArgumentProperty(VALUE_TYPE, Optional.of(BLOCK_AND_POSITION), Optional.empty()), new ArgumentProperty(VALUE_TYPE, Optional.of(BLOCK_AND_POSITION), Optional.empty())), false, false, Optional.of(new InvocationConvention(ImmutableList.of(BLOCK_POSITION, NULL_FLAG), InvocationReturnConvention.NULLABLE_RETURN, false))));
    assertFalse(checkChoice(ImmutableList.of(new ArgumentProperty(VALUE_TYPE, Optional.of(USE_NULL_FLAG), Optional.empty()), new ArgumentProperty(VALUE_TYPE, Optional.of(USE_BOXED_TYPE), Optional.empty())), true, false, Optional.of(new InvocationConvention(ImmutableList.of(BLOCK_POSITION, BOXED_NULLABLE), InvocationReturnConvention.FAIL_ON_NULL, false))));
}
Also used : ArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty) InvocationConvention(io.prestosql.spi.function.InvocationConvention) Test(org.testng.annotations.Test)

Example 2 with InvocationConvention

use of io.prestosql.spi.function.InvocationConvention in project hetu-core by openlookeng.

the class RowDistinctFromOperator method specialize.

@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
    ImmutableList.Builder<MethodHandle> argumentMethods = ImmutableList.builder();
    Type type = boundVariables.getTypeVariable("T");
    for (Type parameterType : type.getTypeParameters()) {
        FunctionHandle operatorHandle = functionAndTypeManager.resolveOperatorFunctionHandle(IS_DISTINCT_FROM, TypeSignatureProvider.fromTypes(parameterType, parameterType));
        FunctionInvoker functionInvoker = functionAndTypeManager.getFunctionInvokerProvider().createFunctionInvoker(operatorHandle, Optional.of(new InvocationConvention(ImmutableList.of(NULL_FLAG, NULL_FLAG), InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL, false)));
        argumentMethods.add(functionInvoker.methodHandle());
    }
    return new BuiltInScalarFunctionImplementation(ImmutableList.of(new ScalarImplementationChoice(false, ImmutableList.of(valueTypeArgumentProperty(USE_NULL_FLAG), valueTypeArgumentProperty(USE_NULL_FLAG)), BuiltInScalarFunctionImplementation.ReturnPlaceConvention.STACK, METHOD_HANDLE_NULL_FLAG.bindTo(type).bindTo(argumentMethods.build()), Optional.empty()), new ScalarImplementationChoice(false, ImmutableList.of(valueTypeArgumentProperty(BLOCK_AND_POSITION), valueTypeArgumentProperty(BLOCK_AND_POSITION)), BuiltInScalarFunctionImplementation.ReturnPlaceConvention.STACK, METHOD_HANDLE_BLOCK_POSITION.bindTo(type).bindTo(argumentMethods.build()), Optional.empty())));
}
Also used : Type(io.prestosql.spi.type.Type) ImmutableList(com.google.common.collect.ImmutableList) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) InvocationConvention(io.prestosql.spi.function.InvocationConvention) ScalarImplementationChoice(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ScalarImplementationChoice) FunctionInvoker(io.prestosql.metadata.FunctionInvoker) FunctionHandle(io.prestosql.spi.function.FunctionHandle) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

InvocationConvention (io.prestosql.spi.function.InvocationConvention)2 ImmutableList (com.google.common.collect.ImmutableList)1 FunctionInvoker (io.prestosql.metadata.FunctionInvoker)1 BuiltInScalarFunctionImplementation (io.prestosql.spi.function.BuiltInScalarFunctionImplementation)1 ArgumentProperty (io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty)1 ScalarImplementationChoice (io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ScalarImplementationChoice)1 FunctionHandle (io.prestosql.spi.function.FunctionHandle)1 Type (io.prestosql.spi.type.Type)1 MethodHandle (java.lang.invoke.MethodHandle)1 Test (org.testng.annotations.Test)1