Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign function management abstraction #196

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f40fa3f
Move static methods from FunctionRegistry to OperatorSignatureUtils a…
rongrong Nov 9, 2018
ffa8a16
Add FunctionManager wrapper around FunctionRegistry
rongrong Nov 9, 2018
c4d6b0b
Simplify SqlToRowExpressionTranslator visitGenericLiteral
dain Jan 13, 2019
cf69cfb
Add FunctionHandle
dain Jan 8, 2019
7915b62
Resolve functions to a handle during analysis
dain Jan 8, 2019
f6f8be3
Switch window function to use FunctionHandle
dain Jan 8, 2019
1066e1f
Switch aggergation function to use FunctionHandle
dain Jan 8, 2019
b5958bd
Switch cast to FunctionHandle
dain Jan 9, 2019
5128b07
Add FunctionManager lookupSaturatedFloorCast
dain Jan 9, 2019
de7eb08
Remove FunctionManager canResolveOperator
dain Jan 9, 2019
ee03112
Switch operators to FunctionHandle
dain Jan 9, 2019
e635940
Convert FunctionManager resolveOperator to TypeSignatureProvider
dain Jan 12, 2019
dd45579
Add system to deserialize a function handle from a SQL expression
dain Jan 9, 2019
f6f70dc
Split special form of row expressions to separate node
dain Jan 10, 2019
f652ef4
Remove FunctionManager isRegistered
dain Jan 12, 2019
37f09ea
Add FunctionManager lookupInternalCastFunction
dain Jan 12, 2019
0a12602
Convert CallExpression to use FunctionHandle
dain Jan 10, 2019
4c921ae
Add name hint to CallExpression
dain Jan 13, 2019
246d126
Removed unused SqlToRowExpressionTranslator functionKind field
dain Jan 13, 2019
f733c4c
Simplify CallExpression bytecode generation
dain Jan 12, 2019
2c1dbaa
Remove unused Signature argument from SpecialFormBytecodeGenerator
dain Jan 12, 2019
7efdb47
Convert function and operator dependencies to FunctionHandle
dain Jan 12, 2019
727ea68
Convert LiteralInterpreter to FunctionHandle
dain Jan 12, 2019
d5d4dda
Remove getScalarFunctionImplementation by Signature
dain Jan 12, 2019
5164aca
Add FunctionManager.getFunctionMetadata
dain Jan 13, 2019
6693fbe
Reduce use of resolveFunction after analysis
dain Feb 8, 2019
5bb184c
Reduce use of resolveOperator after analysis
dain Feb 8, 2019
a14d758
Add some FunctionManager documentation
dain Feb 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public List<SqlFunction> listFunctions()
return functionRegistry.list();
}

public Signature resolveFunction(QualifiedName name, List<TypeSignatureProvider> parameterTypes)
{
return functionRegistry.resolveFunction(name, parameterTypes).getSignature();
}

public FunctionHandle resolveFunction(Session session, QualifiedName name, List<TypeSignatureProvider> parameterTypes)
{
return functionRegistry.resolveFunction(name, parameterTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.prestosql.execution.warnings.WarningCollector;
import io.prestosql.metadata.FunctionHandle;
import io.prestosql.metadata.Metadata;
import io.prestosql.metadata.Signature;
import io.prestosql.operator.scalar.ArraySubscriptOperator;
import io.prestosql.operator.scalar.ScalarFunctionImplementation;
import io.prestosql.spi.Page;
Expand Down Expand Up @@ -144,7 +143,8 @@ public class ExpressionInterpreter
private final Expression expression;
private final Metadata metadata;
private final LiteralEncoder literalEncoder;
private final ConnectorSession session;
private final Session session;
private final ConnectorSession connectorSession;
private final boolean optimize;
private final Map<NodeRef<Expression>, Type> expressionTypes;
private final InterpretedFunctionInvoker functionInvoker;
Expand Down Expand Up @@ -232,7 +232,8 @@ private ExpressionInterpreter(Expression expression, Metadata metadata, Session
this.expression = requireNonNull(expression, "expression is null");
this.metadata = requireNonNull(metadata, "metadata is null");
this.literalEncoder = new LiteralEncoder(metadata.getBlockEncodingSerde());
this.session = requireNonNull(session, "session is null").toConnectorSession();
this.session = requireNonNull(session, "session is null");
this.connectorSession = session.toConnectorSession();
this.expressionTypes = ImmutableMap.copyOf(requireNonNull(expressionTypes, "expressionTypes is null"));
verify((expressionTypes.containsKey(NodeRef.of(expression))));
this.optimize = optimize;
Expand Down Expand Up @@ -395,7 +396,7 @@ protected Object visitSymbolReference(SymbolReference node, Object context)
@Override
protected Object visitLiteral(Literal node, Object context)
{
return LiteralInterpreter.evaluate(metadata, session, node);
return LiteralInterpreter.evaluate(metadata, connectorSession, node);
}

@Override
Expand Down Expand Up @@ -712,7 +713,7 @@ protected Object visitArithmeticUnary(ArithmeticUnaryExpression node, Object con
MethodHandle handle = metadata.getFunctionManager().getScalarFunctionImplementation(operatorHandle).getMethodHandle();

if (handle.type().parameterCount() > 0 && handle.type().parameterType(0) == ConnectorSession.class) {
handle = handle.bindTo(session);
handle = handle.bindTo(connectorSession);
}
try {
return handle.invokeWithArguments(value);
Expand Down Expand Up @@ -831,8 +832,8 @@ protected Object visitNullIfExpression(NullIfExpression node, Object context)
OperatorType.EQUAL,
ImmutableList.of(commonType, commonType),
ImmutableList.of(
functionInvoker.invoke(firstCast, session, ImmutableList.of(first)),
functionInvoker.invoke(secondCast, session, ImmutableList.of(second)))));
functionInvoker.invoke(firstCast, connectorSession, ImmutableList.of(first)),
functionInvoker.invoke(secondCast, connectorSession, ImmutableList.of(second)))));

if (equal) {
return null;
Expand Down Expand Up @@ -926,8 +927,8 @@ protected Object visitFunctionCall(FunctionCall node, Object context)
argumentValues.add(value);
argumentTypes.add(type);
}
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.

for (int i = 0; i < argumentValues.size(); i++) {
Object value = argumentValues.get(i);
if (value == null && function.getArgumentProperty(i).getNullConvention() == RETURN_NULL_ON_NULL) {
Expand All @@ -939,7 +940,7 @@ protected Object visitFunctionCall(FunctionCall node, Object context)
if (optimize && (!function.isDeterministic() || hasUnresolvedValue(argumentValues) || node.getName().equals(QualifiedName.of("fail")))) {
return new FunctionCall(node.getName(), node.getWindow(), node.isDistinct(), toExpressions(argumentValues, argumentTypes));
}
return functionInvoker.invoke(functionSignature, session, argumentValues);
return functionInvoker.invoke(functionHandle, connectorSession, argumentValues);
}

@Override
Expand Down Expand Up @@ -1134,7 +1135,7 @@ public Object visitCast(Cast node, Object context)
FunctionHandle operator = metadata.getFunctionManager().lookupCast(sourceType.getTypeSignature(), targetType.getTypeSignature());

try {
return functionInvoker.invoke(operator, session, ImmutableList.of(value));
return functionInvoker.invoke(operator, connectorSession, ImmutableList.of(value));
}
catch (RuntimeException e) {
if (node.isSafe()) {
Expand Down Expand Up @@ -1263,7 +1264,7 @@ private boolean hasUnresolvedValue(List<Object> values)
private Object invokeOperator(OperatorType operatorType, List<? extends Type> argumentTypes, List<Object> argumentValues)
{
FunctionHandle operatorHandle = metadata.getFunctionManager().resolveOperator(operatorType, fromTypes(argumentTypes));
return functionInvoker.invoke(operatorHandle, session, argumentValues);
return functionInvoker.invoke(operatorHandle, connectorSession, argumentValues);
}

private Expression toExpression(Object base, Type type)
Expand Down