protected List<MethodHandle> getMethodHandles(RowType type, FunctionRegistry functionRegistry, OperatorType operatorType) { ImmutableList.Builder<MethodHandle> argumentMethods = ImmutableList.builder(); for (Type parameterType : type.getTypeParameters()) { Signature signature = functionRegistry.resolveOperator(operatorType, ImmutableList.of(parameterType, parameterType)); argumentMethods.add(functionRegistry.getScalarFunctionImplementation(signature).getMethodHandle()); } return argumentMethods.build(); }
@Override public MethodHandle resolveOperator(OperatorType operatorType, List<? extends Type> argumentTypes) { requireNonNull(functionRegistry, "functionRegistry is null"); return functionRegistry.getScalarFunctionImplementation(functionRegistry.resolveOperator(operatorType, argumentTypes)).getMethodHandle(); }
private LongStrategy(FunctionRegistry registry, Type type) { hashCodeHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(HASH_CODE, ImmutableList.of(type))).getMethodHandle(); equalsHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(EQUAL, ImmutableList.of(type, type))).getMethodHandle(); }
private static MethodHandle resolveEqualOperator(Type type, FunctionRegistry functionRegistry) { Signature operator = functionRegistry.resolveOperator(EQUAL, ImmutableList.of(type, type)); ScalarFunctionImplementation implementation = functionRegistry.getScalarFunctionImplementation(operator); return implementation.getMethodHandle(); }
private DoubleStrategy(FunctionRegistry registry, Type type) { hashCodeHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(HASH_CODE, ImmutableList.of(type))).getMethodHandle(); equalsHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(EQUAL, ImmutableList.of(type, type))).getMethodHandle(); }
private static MethodHandle resolveEqualOperator(Type type, FunctionRegistry functionRegistry) { Signature operator = functionRegistry.resolveOperator(EQUAL, ImmutableList.of(type, type)); ScalarFunctionImplementation implementation = functionRegistry.getScalarFunctionImplementation(operator); return implementation.getMethodHandle(); }
private LongStrategy(FunctionRegistry registry, Type type) { hashCodeHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(HASH_CODE, ImmutableList.of(type))).getMethodHandle(); equalsHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(EQUAL, ImmutableList.of(type, type))).getMethodHandle(); }
protected List<MethodHandle> getMethodHandles(RowType type, FunctionRegistry functionRegistry, OperatorType operatorType) { ImmutableList.Builder<MethodHandle> argumentMethods = ImmutableList.builder(); for (Type parameterType : type.getTypeParameters()) { Signature signature = functionRegistry.resolveOperator(operatorType, ImmutableList.of(parameterType, parameterType)); argumentMethods.add(functionRegistry.getScalarFunctionImplementation(signature).getMethodHandle()); } return argumentMethods.build(); }
private DoubleStrategy(FunctionRegistry registry, Type type) { hashCodeHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(HASH_CODE, ImmutableList.of(type))).getMethodHandle(); equalsHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(EQUAL, ImmutableList.of(type, type))).getMethodHandle(); }
@Override public MethodHandle resolveOperator(OperatorType operatorType, List<? extends Type> argumentTypes) { requireNonNull(functionRegistry, "functionRegistry is null"); return functionRegistry.getScalarFunctionImplementation(functionRegistry.resolveOperator(operatorType, argumentTypes)).getMethodHandle(); }
private Object invokeOperator(OperatorType operatorType, List<? extends Type> argumentTypes, List<Object> argumentValues) { Signature operatorSignature = metadata.getFunctionRegistry().resolveOperator(operatorType, argumentTypes); return functionInvoker.invoke(operatorSignature, session, argumentValues); }
private Object invokeOperator(OperatorType operatorType, List<? extends Type> argumentTypes, List<Object> argumentValues) { Signature operatorSignature = metadata.getFunctionRegistry().resolveOperator(operatorType, argumentTypes); return functionInvoker.invoke(operatorSignature, session, argumentValues); }
private ObjectStrategy(FunctionRegistry registry, Type type) { hashCodeHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(HASH_CODE, ImmutableList.of(type))) .getMethodHandle() .asType(MethodType.methodType(long.class, Object.class)); equalsHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(EQUAL, ImmutableList.of(type, type))) .getMethodHandle() .asType(MethodType.methodType(Boolean.class, Object.class, Object.class)); }
private ObjectStrategy(FunctionRegistry registry, Type type) { hashCodeHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(HASH_CODE, ImmutableList.of(type))) .getMethodHandle() .asType(MethodType.methodType(long.class, Object.class)); equalsHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(EQUAL, ImmutableList.of(type, type))) .getMethodHandle() .asType(MethodType.methodType(Boolean.class, Object.class, Object.class)); }
@Test public void testOperatorsImplemented() { for (Type type : typeRegistry.getTypes()) { if (type.isComparable()) { functionRegistry.resolveOperator(EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(NOT_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(IS_DISTINCT_FROM, ImmutableList.of(type, type)); functionRegistry.resolveOperator(HASH_CODE, ImmutableList.of(type)); } if (type.isOrderable()) { functionRegistry.resolveOperator(LESS_THAN, ImmutableList.of(type, type)); functionRegistry.resolveOperator(LESS_THAN_OR_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(GREATER_THAN_OR_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(GREATER_THAN, ImmutableList.of(type, type)); } } }
@Test public void testOperatorsImplemented() { for (Type type : typeRegistry.getTypes()) { if (type.isComparable()) { functionRegistry.resolveOperator(EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(NOT_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(IS_DISTINCT_FROM, ImmutableList.of(type, type)); functionRegistry.resolveOperator(HASH_CODE, ImmutableList.of(type)); } if (type.isOrderable()) { functionRegistry.resolveOperator(LESS_THAN, ImmutableList.of(type, type)); functionRegistry.resolveOperator(LESS_THAN_OR_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(GREATER_THAN_OR_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(GREATER_THAN, ImmutableList.of(type, type)); } } }
public static MethodHandle distinctFromOperator(Type type) { Signature signature = FUNCTION_REGISTRY.resolveOperator(IS_DISTINCT_FROM, ImmutableList.of(type, type)); return FUNCTION_REGISTRY.getScalarFunctionImplementation(signature).getMethodHandle(); }
public static MethodHandle distinctFromOperator(Type type) { Signature signature = FUNCTION_REGISTRY.resolveOperator(IS_DISTINCT_FROM, ImmutableList.of(type, type)); return FUNCTION_REGISTRY.getScalarFunctionImplementation(signature).getMethodHandle(); }
@Override public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type keyType = boundVariables.getTypeVariable("K"); Type valueType = boundVariables.getTypeVariable("V"); Type mapType = typeManager.getParameterizedType(MAP, ImmutableList.of(TypeSignatureParameter.of(keyType.getTypeSignature()), TypeSignatureParameter.of(valueType.getTypeSignature()))); MethodHandle keyHashCode = functionRegistry.getScalarFunctionImplementation(functionRegistry.resolveOperator(OperatorType.HASH_CODE, ImmutableList.of(keyType))).getMethodHandle(); MethodHandle keyEqual = functionRegistry.getScalarFunctionImplementation(functionRegistry.resolveOperator(OperatorType.EQUAL, ImmutableList.of(keyType, keyType))).getMethodHandle(); MethodHandle keyIndeterminate = functionRegistry.getScalarFunctionImplementation(internalOperator(INDETERMINATE.name(), BOOLEAN.getTypeSignature(), ImmutableList.of(keyType.getTypeSignature()))).getMethodHandle(); MethodHandle instanceFactory = constructorMethodHandle(State.class, MapType.class).bindTo(mapType); return new ScalarFunctionImplementation( false, ImmutableList.of( valueTypeArgumentProperty(RETURN_NULL_ON_NULL), valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), METHOD_HANDLE.bindTo(mapType).bindTo(keyEqual).bindTo(keyHashCode).bindTo(keyIndeterminate), Optional.of(instanceFactory), isDeterministic()); }
@Override public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type keyType = boundVariables.getTypeVariable("K"); Type valueType = boundVariables.getTypeVariable("V"); Type mapType = typeManager.getParameterizedType(MAP, ImmutableList.of(TypeSignatureParameter.of(keyType.getTypeSignature()), TypeSignatureParameter.of(valueType.getTypeSignature()))); MethodHandle keyHashCode = functionRegistry.getScalarFunctionImplementation(functionRegistry.resolveOperator(OperatorType.HASH_CODE, ImmutableList.of(keyType))).getMethodHandle(); MethodHandle keyEqual = functionRegistry.getScalarFunctionImplementation(functionRegistry.resolveOperator(OperatorType.EQUAL, ImmutableList.of(keyType, keyType))).getMethodHandle(); MethodHandle keyIndeterminate = functionRegistry.getScalarFunctionImplementation(internalOperator(INDETERMINATE.name(), BOOLEAN.getTypeSignature(), ImmutableList.of(keyType.getTypeSignature()))).getMethodHandle(); MethodHandle instanceFactory = constructorMethodHandle(State.class, MapType.class).bindTo(mapType); return new ScalarFunctionImplementation( false, ImmutableList.of( valueTypeArgumentProperty(RETURN_NULL_ON_NULL), valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), METHOD_HANDLE.bindTo(mapType).bindTo(keyEqual).bindTo(keyHashCode).bindTo(keyIndeterminate), Optional.of(instanceFactory), isDeterministic()); }