@VisibleForTesting static List<TypeVariableConstraint> getTypeVariableConstraintsForStdUdf(StdUDF stdUdf) { Set<GenericTypeSignatureElement> genericTypes = new HashSet<>(); for (String s : stdUdf.getInputParameterSignatures()) { genericTypes.addAll(com.linkedin.transport.typesystem.TypeSignature.parse(s).getGenericTypeSignatureElements()); } genericTypes.addAll(com.linkedin.transport.typesystem.TypeSignature.parse(stdUdf.getOutputParameterSignature()) .getGenericTypeSignatureElements()); return genericTypes.stream().map(t -> typeVariable(t.toString())).collect(Collectors.toList()); }
@VisibleForTesting static List<TypeVariableConstraint> getTypeVariableConstraintsForStdUdf(StdUDF stdUdf) { Set<GenericTypeSignatureElement> genericTypes = new HashSet<>(); for (String s : stdUdf.getInputParameterSignatures()) { genericTypes.addAll(com.linkedin.transport.typesystem.TypeSignature.parse(s).getGenericTypeSignatureElements()); } genericTypes.addAll(com.linkedin.transport.typesystem.TypeSignature.parse(stdUdf.getOutputParameterSignature()) .getGenericTypeSignatureElements()); return genericTypes.stream().map(t -> typeVariable(t.toString())).collect(Collectors.toList()); }
protected StdUdfWrapper(StdUDF stdUDF) { super(new Signature(((TopLevelStdUDF) stdUDF).getFunctionName(), FunctionKind.SCALAR, getTypeVariableConstraintsForStdUdf(stdUDF), ImmutableList.of(), parseTypeSignature(stdUDF.getOutputParameterSignature()), stdUDF.getInputParameterSignatures() .stream() .map(TypeSignature::parseTypeSignature) .collect(Collectors.toList()), false)); _functionDescription = ((TopLevelStdUDF) stdUDF).getFunctionDescription(); }
protected StdUdfWrapper(StdUDF stdUDF) { super(new Signature(((TopLevelStdUDF) stdUDF).getFunctionName(), FunctionKind.SCALAR, getTypeVariableConstraintsForStdUdf(stdUDF), ImmutableList.of(), parseTypeSignature(stdUDF.getOutputParameterSignature()), stdUDF.getInputParameterSignatures() .stream() .map(TypeSignature::parseTypeSignature) .collect(Collectors.toList()), false)); _functionDescription = ((TopLevelStdUDF) stdUDF).getFunctionDescription(); }
boolean atLeastOneInputParametersSignaturesBindingSuccess = false; for (StdUDF stdUdf: stdUdfImplementations) { List<String> inputParameterSignatures = stdUdf.getInputParameterSignatures(); if (inputParameterSignatures.size() != dataTypes.length) { continue;
boolean atLeastOneInputParametersSignaturesBindingSuccess = false; for (StdUDF stdUdf: stdUdfImplementations) { List<String> inputParameterSignatures = stdUdf.getInputParameterSignatures(); if (inputParameterSignatures.size() != dataTypes.length) { continue;
private MethodHandle getMethodHandle(StdUDF stdUDF, TypeManager typeManager, BoundVariables boundVariables, boolean[] nullableArguments) { Type[] inputTypes = getPrestoTypes(stdUDF.getInputParameterSignatures(), typeManager, boundVariables); Type outputType = getPrestoType(stdUDF.getOutputParameterSignature(), typeManager, boundVariables); // Generic MethodHandle for eval where all arguments are of type Object Class<?>[] genericMethodHandleArgumentTypes = getMethodHandleArgumentTypes(inputTypes, nullableArguments, true); MethodHandle genericMethodHandle = methodHandle(StdUdfWrapper.class, "evalInternal", genericMethodHandleArgumentTypes).bindTo(this); Class<?>[] specificMethodHandleArgumentTypes = getMethodHandleArgumentTypes(inputTypes, nullableArguments, false); Class<?> specificMethodHandleReturnType = getMethodHandleJavaType(outputType, true, 0); MethodType specificMethodType = MethodType.methodType(specificMethodHandleReturnType, specificMethodHandleArgumentTypes); // Specific MethodHandle required by presto where argument types map to the type signature MethodHandle specificMethodHandle = MethodHandles.explicitCastArguments(genericMethodHandle, specificMethodType); return MethodHandles.insertArguments(specificMethodHandle, 0, stdUDF, inputTypes, outputType instanceof IntegerType); }
private MethodHandle getMethodHandle(StdUDF stdUDF, TypeManager typeManager, BoundVariables boundVariables, boolean[] nullableArguments) { Type[] inputTypes = getPrestoTypes(stdUDF.getInputParameterSignatures(), typeManager, boundVariables); Type outputType = getPrestoType(stdUDF.getOutputParameterSignature(), typeManager, boundVariables); // Generic MethodHandle for eval where all arguments are of type Object Class<?>[] genericMethodHandleArgumentTypes = getMethodHandleArgumentTypes(inputTypes, nullableArguments, true); MethodHandle genericMethodHandle = methodHandle(StdUdfWrapper.class, "evalInternal", genericMethodHandleArgumentTypes).bindTo(this); Class<?>[] specificMethodHandleArgumentTypes = getMethodHandleArgumentTypes(inputTypes, nullableArguments, false); Class<?> specificMethodHandleReturnType = getMethodHandleJavaType(outputType, true, 0); MethodType specificMethodType = MethodType.methodType(specificMethodHandleReturnType, specificMethodHandleArgumentTypes); // Specific MethodHandle required by presto where argument types map to the type signature MethodHandle specificMethodHandle = MethodHandles.explicitCastArguments(genericMethodHandle, specificMethodType); return MethodHandles.insertArguments(specificMethodHandle, 0, stdUDF, inputTypes, outputType instanceof IntegerType); }