Skip to content

Redesign function management abstraction#196

Closed
dain wants to merge 28 commits intotrinodb:masterfrom
dain:function-handle
Closed

Redesign function management abstraction#196
dain wants to merge 28 commits intotrinodb:masterfrom
dain:function-handle

Conversation

@dain
Copy link
Member

@dain dain commented Feb 8, 2019

The redesigns the function APIs in preparation for extending runtime function resolution to connectors.

  • Add FuctionHandle abstraction which is similar to TableHandle.
  • Add FunctionMetadata abstraction which describes a function represented by a FunctionHandle.

@cla-bot
Copy link

cla-bot bot commented Feb 8, 2019

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.

@dain dain requested a review from martint February 8, 2019 22:53
rongrong and others added 27 commits February 9, 2019 10:10
Update all users of FunctionRegistry to use new FunctionManager wrapper instead.
The new abstraction will simplify the changes necessary to introduce FunctionHandle API.
@cla-bot
Copy link

cla-bot bot commented Feb 9, 2019

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.

Copy link
Contributor

@rongrong rongrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the plumbing. 😛 Skimmed through commits up to Switch operators to FunctionHandle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 🤣

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is super confusing 🤣

return functionManager.resolveFunction(session, QualifiedName.of("not"), fromTypes(BOOLEAN));
}

public FunctionHandle likeVarcharSignature()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this one called signature?

return functionManager.resolveFunction(session, QualifiedName.of("LIKE_PATTERN"), fromTypes(VARCHAR, VARCHAR));
}

// public FunctionHandle tryCastFunction(Type returnType, Type valueType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be here or not?

return functionRegistry.lookupSaturatedFloorCast(fromType, toType);
}

public FunctionHandle lookupInternalCastFunction(String name, TypeSignature fromType, TypeSignature toType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably just call this commit Remove CastCodeGenerator to be more specific.

return functionRegistry.list();
}

public FunctionHandle lookupFunction(QualifiedName name, List<TypeSignatureProvider> parameterTypes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this should be in the operator dependencies diff.

@Override
protected RowExpression visitGenericLiteral(GenericLiteral node, Void context)
{
Type type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expectedFunction

new Signature("min_by", AGGREGATE, parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(UnknownType.NAME)));
InternalAggregationFunction unknownValue = getInternalAggregationFunction("min_by", DOUBLE, UNKNOWN);
assertAggregation(
unknownKey,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it would be more consistent to call this new class SpecialFormExpression.

@dain dain closed this Aug 7, 2019
@dain dain deleted the function-handle branch December 7, 2019 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants