@VisibleForTesting public static InternalAggregationFunction generateInternalAggregationFunction(Class<?> clazz, TypeSignature outputType, List<TypeSignature> inputTypes, TypeManager typeManager) { return generateInternalAggregationFunction(clazz, outputType, inputTypes, typeManager, BoundVariables.builder().build(), inputTypes.size()); }
public BoundVariables build() { return new BoundVariables(typeVariables, longVariables); } }
@Override public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type inputType = boundVariables.getTypeVariable("T"); Type stateType = boundVariables.getTypeVariable("S"); return generateAggregation(inputType, stateType); }
public static TypeSignature applyBoundVariables(TypeSignature typeSignature, BoundVariables boundVariables) { String baseType = typeSignature.getBase(); if (boundVariables.containsTypeVariable(baseType)) { checkState(typeSignature.getParameters().isEmpty(), "Type parameters cannot have parameters"); return boundVariables.getTypeVariable(baseType).getTypeSignature(); } List<TypeSignatureParameter> parameters = typeSignature.getParameters().stream() .map(typeSignatureParameter -> applyBoundVariables(typeSignatureParameter, boundVariables)) .collect(toList()); return new TypeSignature(baseType, parameters); }
@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(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), identity, isDeterministic()); } }
@Override public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { return specializeArrayJoin(boundVariables.getTypeVariables(), functionRegistry, ImmutableList.of(false, false, false), METHOD_HANDLE); } }
private static TypeSignatureParameter applyBoundVariables(TypeSignatureParameter parameter, BoundVariables boundVariables) { ParameterKind parameterKind = parameter.getKind(); switch (parameterKind) { case TYPE: { TypeSignature typeSignature = parameter.getTypeSignature(); return TypeSignatureParameter.of(applyBoundVariables(typeSignature, boundVariables)); } case NAMED_TYPE: { NamedTypeSignature namedTypeSignature = parameter.getNamedTypeSignature(); TypeSignature typeSignature = namedTypeSignature.getTypeSignature(); return TypeSignatureParameter.of(new NamedTypeSignature( namedTypeSignature.getFieldName(), applyBoundVariables(typeSignature, boundVariables))); } case VARIABLE: { String variableName = parameter.getVariable(); checkState(boundVariables.containsLongVariable(variableName), "Variable is not bound: %s", variableName); Long variableValue = boundVariables.getLongVariable(variableName); return TypeSignatureParameter.of(variableValue); } case LONG: { return parameter; } default: throw new IllegalStateException("Unknown parameter kind: " + parameter.getKind()); } }
@Override public Long resolve(BoundVariables boundVariables, TypeManager typeManager, FunctionRegistry functionRegistry) { return boundVariables.getLongVariable(literalName); } }
public Long getLongVariable(String variableName) { return getValue(longVariables, variableName); }
public boolean containsTypeVariable(String variableName) { return containsValue(typeVariables, variableName); }
@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(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), identity, isDeterministic()); } }
public static TypeSignature applyBoundVariables(TypeSignature typeSignature, BoundVariables boundVariables) { String baseType = typeSignature.getBase(); if (boundVariables.containsTypeVariable(baseType)) { checkState(typeSignature.getParameters().isEmpty(), "Type parameters cannot have parameters"); return boundVariables.getTypeVariable(baseType).getTypeSignature(); } List<TypeSignatureParameter> parameters = typeSignature.getParameters().stream() .map(typeSignatureParameter -> applyBoundVariables(typeSignatureParameter, boundVariables)) .collect(toList()); return new TypeSignature(baseType, parameters); }
@Override public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { return specializeArrayJoin(boundVariables.getTypeVariables(), functionRegistry, ImmutableList.of(false, false, false), METHOD_HANDLE); } }
private static TypeSignatureParameter applyBoundVariables(TypeSignatureParameter parameter, BoundVariables boundVariables) { ParameterKind parameterKind = parameter.getKind(); switch (parameterKind) { case TYPE: { TypeSignature typeSignature = parameter.getTypeSignature(); return TypeSignatureParameter.of(applyBoundVariables(typeSignature, boundVariables)); } case NAMED_TYPE: { NamedTypeSignature namedTypeSignature = parameter.getNamedTypeSignature(); TypeSignature typeSignature = namedTypeSignature.getTypeSignature(); return TypeSignatureParameter.of(new NamedTypeSignature( namedTypeSignature.getFieldName(), applyBoundVariables(typeSignature, boundVariables))); } case VARIABLE: { String variableName = parameter.getVariable(); checkState(boundVariables.containsLongVariable(variableName), "Variable is not bound: %s", variableName); Long variableValue = boundVariables.getLongVariable(variableName); return TypeSignatureParameter.of(variableValue); } case LONG: { return parameter; } default: throw new IllegalStateException("Unknown parameter kind: " + parameter.getKind()); } }
@Override public Long resolve(BoundVariables boundVariables, TypeManager typeManager, FunctionRegistry functionRegistry) { return boundVariables.getLongVariable(literalName); } }
public Long getLongVariable(String variableName) { return getValue(longVariables, variableName); }
public boolean containsLongVariable(String variableName) { return containsValue(longVariables, variableName); }
@VisibleForTesting public static InternalAggregationFunction generateInternalAggregationFunction(Class<?> clazz, TypeSignature outputType, List<TypeSignature> inputTypes, TypeManager typeManager) { return generateInternalAggregationFunction(clazz, outputType, inputTypes, typeManager, BoundVariables.builder().build(), inputTypes.size()); }
public BoundVariables build() { return new BoundVariables(typeVariables, longVariables); } }
@Override public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type keyType = boundVariables.getTypeVariable("K"); Type valueType = boundVariables.getTypeVariable("V"); return generateAggregation(valueType, keyType); }