Ejemplo n.º 1
0
  @Override
  public ScalarFunctionImplementation specialize(
      BoundVariables boundVariables,
      int arity,
      TypeManager typeManager,
      FunctionRegistry functionRegistry) {
    Type fromType = boundVariables.getTypeVariable("F");
    Type toType = boundVariables.getTypeVariable("T");

    Class<?> returnType = Primitives.wrap(toType.getJavaType());
    MethodHandle tryCastHandle;

    if (fromType.equals(UNKNOWN)) {
      tryCastHandle = dropArguments(constant(returnType, null), 0, Void.class);
    } else {
      // the resulting method needs to return a boxed type
      Signature signature = functionRegistry.getCoercion(fromType, toType);
      MethodHandle coercion =
          functionRegistry.getScalarFunctionImplementation(signature).getMethodHandle();
      coercion = coercion.asType(methodType(returnType, coercion.type()));

      MethodHandle exceptionHandler =
          dropArguments(constant(returnType, null), 0, RuntimeException.class);
      tryCastHandle = catchException(coercion, RuntimeException.class, exceptionHandler);
    }

    return new ScalarFunctionImplementation(
        true, ImmutableList.of(true), tryCastHandle, isDeterministic());
  }
Ejemplo n.º 2
0
 @Override
 public ScalarFunctionImplementation specialize(
     BoundVariables boundVariables,
     int arity,
     TypeManager typeManager,
     FunctionRegistry functionRegistry) {
   checkArgument(boundVariables.getTypeVariables().size() == 1, "Expected only one type");
   Type type = boundVariables.getTypeVariable("T");
   MethodHandle identity = MethodHandles.identity(type.getJavaType());
   return new ScalarFunctionImplementation(
       false, ImmutableList.of(false), identity, isDeterministic());
 }
Ejemplo n.º 3
0
 @Override
 public ScalarFunctionImplementation specialize(
     BoundVariables boundVariables,
     int arity,
     TypeManager typeManager,
     FunctionRegistry functionRegistry) {
   Type argumentType = boundVariables.getTypeVariable("T");
   Type returnType = boundVariables.getTypeVariable("U");
   return new ScalarFunctionImplementation(
       true,
       ImmutableList.of(true, false),
       METHOD_HANDLE.asType(
           METHOD_HANDLE
               .type()
               .changeReturnType(wrap(returnType.getJavaType()))
               .changeParameterType(0, wrap(argumentType.getJavaType()))),
       isDeterministic());
 }
Ejemplo n.º 4
0
 @Override
 public ScalarFunctionImplementation specialize(
     BoundVariables boundVariables,
     int arity,
     TypeManager typeManager,
     FunctionRegistry functionRegistry) {
   Type type = boundVariables.getTypeVariable("T");
   return new ScalarFunctionImplementation(
       false, ImmutableList.of(false, false), METHOD_HANDLE.bindTo(type), isDeterministic());
 }
 @Override
 public ScalarFunctionImplementation specialize(
     BoundVariables boundVariables,
     int arity,
     TypeManager typeManager,
     FunctionRegistry functionRegistry) {
   Type elementType = boundVariables.getTypeVariable("T");
   MethodHandle greaterThanFunction =
       functionRegistry
           .getScalarFunctionImplementation(
               internalOperator(GREATER_THAN, BOOLEAN, ImmutableList.of(elementType, elementType)))
           .getMethodHandle();
   MethodHandle method = METHOD_HANDLE.bindTo(greaterThanFunction).bindTo(elementType);
   return new ScalarFunctionImplementation(
       false, ImmutableList.of(false, false), method, isDeterministic());
 }