Redesign function management abstraction#196
Conversation
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@prestosql.io. If you are contributing on behalf of someone else (e.g., your employer), the individual CLA may not be sufficient and your employer may need the Corporate CLA signed. |
…nd LiteralEncoder
Update all users of FunctionRegistry to use new FunctionManager wrapper instead. The new abstraction will simplify the changes necessary to introduce FunctionHandle API.
Remove unused return tye from
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@prestosql.io. If you are contributing on behalf of someone else (e.g., your employer), the individual CLA may not be sufficient and your employer may need the Corporate CLA signed. |
rongrong
left a comment
There was a problem hiding this comment.
Thanks for all the plumbing. 😛 Skimmed through commits up to Switch operators to FunctionHandle.
There was a problem hiding this comment.
It makes more sense to me to have
assertEquals(exactOperator.getSignature(), function.getSignature());
at this moment of the refactoring.
| List<TypeSignature> argumentTypes = Lists.transform(windowFunction.getArguments(), expression -> analysis.getType(expression).getTypeSignature()); | ||
|
|
||
| FunctionKind kind = metadata.getFunctionManager().resolveFunction(windowFunction.getName(), fromTypeSignatures(argumentTypes)).getKind(); | ||
| FunctionHandle functionHandle = metadata.getFunctionManager().resolveFunction(session, windowFunction.getName(), fromTypeSignatures(argumentTypes)); |
There was a problem hiding this comment.
I thought the guideline is "if a variable is only used once it should be inlined"? I agree in some cases break it up is easier to read, but "easy to read" is very subjective. And I find it more often than not that the reviewer disagrees with me on that. 😛
| public ScalarFunctionImplementation getScalarFunctionImplementation(Signature signature) | ||
| { | ||
| return functionRegistry.getScalarFunctionImplementation(signature); | ||
| return functionRegistry.getScalarFunctionImplementation(new FunctionHandle(signature)); |
There was a problem hiding this comment.
FunctionRegistry. getScalarFunctionImplementation(Signature) is not removed so this change is not necessary.
| } | ||
|
|
||
| public Signature getCoercion(Type fromType, Type toType) | ||
| public FunctionHandle lookupCast(TypeSignature fromType, TypeSignature toType) |
There was a problem hiding this comment.
What's the rational behind the name change?
| public class MapSubscriptOperator | ||
| extends SqlOperator | ||
| { | ||
| private static final MethodHandle METHOD_HANDLE_BOOLEAN = methodHandle(MapSubscriptOperator.class, "subscript", boolean.class, InterpretedFunctionInvoker.class, Type.class, Type.class, ConnectorSession.class, Block.class, boolean.class); |
There was a problem hiding this comment.
Change in this class should probably be a separate commit in itself.
| return invoke(implementation, session, arguments); | ||
| } | ||
|
|
||
| private Object invoke(ScalarFunctionImplementation function, ConnectorSession session, List<Object> arguments) |
There was a problem hiding this comment.
Seems that implementation is the right name.
| Signature functionSignature = metadata.getFunctionManager().resolveFunction(node.getName(), fromTypes(argumentTypes)); | ||
| ScalarFunctionImplementation function = metadata.getFunctionManager().getScalarFunctionImplementation(functionSignature); | ||
| FunctionHandle functionHandle = metadata.getFunctionManager().resolveFunction(session, node.getName(), fromTypes(argumentTypes)); | ||
| ScalarFunctionImplementation function = metadata.getFunctionManager().getScalarFunctionImplementation(functionHandle); |
There was a problem hiding this comment.
Most of this commit seems to be just rename session to connectorSession other than this two lines. Failed to understand the association between the code change and the commit title here. 🤣
There was a problem hiding this comment.
Resolving a function requires a full session, where as everything else in this code only needs a connector session. The renames are because connector session was called session, and I wanted to use that name for the full session.
| return new ConstantExpression(null, type); | ||
| } | ||
|
|
||
| public static CallExpression call(Signature signature, Type returnType, RowExpression... arguments) |
There was a problem hiding this comment.
What's the reasoning behind removing these helpers and prefer using new ... directly? Are other helpers in the class going to be removed as well?
| this.functionManager = requireNonNull(functionManager, "functionManager is null"); | ||
| } | ||
|
|
||
| public FunctionHandle notFunction() |
There was a problem hiding this comment.
This name is super confusing 🤣
| return functionManager.resolveFunction(session, QualifiedName.of("not"), fromTypes(BOOLEAN)); | ||
| } | ||
|
|
||
| public FunctionHandle likeVarcharSignature() |
There was a problem hiding this comment.
Why is this one called signature?
| return functionManager.resolveFunction(session, QualifiedName.of("LIKE_PATTERN"), fromTypes(VARCHAR, VARCHAR)); | ||
| } | ||
|
|
||
| // public FunctionHandle tryCastFunction(Type returnType, Type valueType) |
There was a problem hiding this comment.
Is this supposed to be here or not?
| return functionRegistry.lookupSaturatedFloorCast(fromType, toType); | ||
| } | ||
|
|
||
| public FunctionHandle lookupInternalCastFunction(String name, TypeSignature fromType, TypeSignature toType) |
There was a problem hiding this comment.
This doesn't seem to need to be a separate commit? Which commit calls this function?
|
|
||
| import static io.prestosql.spi.function.OperatorType.CAST; | ||
|
|
||
| public class CastCodeGenerator |
There was a problem hiding this comment.
I'd probably just call this commit Remove CastCodeGenerator to be more specific.
| return functionRegistry.list(); | ||
| } | ||
|
|
||
| public FunctionHandle lookupFunction(QualifiedName name, List<TypeSignatureProvider> parameterTypes) |
There was a problem hiding this comment.
Why is this one not called resolveFunction?
| toInvocationConvention(operatorDependency.convention())); | ||
| } | ||
| checkArgument(!operatorDependency.returnType().equals(""), operatorDependency.operator() + " operator dependency must not have a return type"); | ||
| checkArgument(operatorDependency.returnType().equals(""), operatorDependency.operator() + " operator dependency must not have a return type"); |
There was a problem hiding this comment.
Seems like this should be in the operator dependencies diff.
| @Override | ||
| protected RowExpression visitGenericLiteral(GenericLiteral node, Void context) | ||
| { | ||
| Type type; |
There was a problem hiding this comment.
Why is this no longer needed?
| Signature expectedSignature = functionSignature.name(TEST_FUNCTION_NAME).build(); | ||
| Signature actualSignature = resolveSignature(); | ||
| assertEquals(actualSignature, expectedSignature); | ||
| FunctionHandle expectedSignature = new FunctionHandle(functionSignature.name(TEST_FUNCTION_NAME).build()); |
| new Signature("min_by", AGGREGATE, parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(UnknownType.NAME))); | ||
| InternalAggregationFunction unknownValue = getInternalAggregationFunction("min_by", DOUBLE, UNKNOWN); | ||
| assertAggregation( | ||
| unknownKey, |
There was a problem hiding this comment.
I'm guessing this is meant to be unknownValue, otherwise unknownValue is an unused variable.
| { | ||
| R visitCall(CallExpression call, C context); | ||
|
|
||
| R visitSpecialForm(SpecialForm specialForm, C context); |
There was a problem hiding this comment.
Seems like it would be more consistent to call this new class SpecialFormExpression.
The redesigns the function APIs in preparation for extending runtime function resolution to connectors.
FuctionHandleabstraction which is similar toTableHandle.FunctionMetadataabstraction which describes a function represented by a FunctionHandle.