Skip to content

Commit

Permalink
Remove FunctionRegistry.getCoercion(Type, Type)
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Jun 16, 2019
1 parent 4b63026 commit 0ec41a9
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion presto-main/src/main/java/io/prestosql/cost/StatsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static OptionalDouble toStatsRepresentation(Metadata metadata, Session session,
{
if (convertibleToDoubleWithCast(type)) {
InterpretedFunctionInvoker functionInvoker = new InterpretedFunctionInvoker(metadata.getFunctionRegistry());
Signature castSignature = metadata.getFunctionRegistry().getCoercion(type, DoubleType.DOUBLE);
Signature castSignature = metadata.getFunctionRegistry().getCoercion(type.getTypeSignature(), DoubleType.DOUBLE.getTypeSignature());
return OptionalDouble.of((double) functionInvoker.invoke(castSignature, session.toConnectorSession(), singletonList(value)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,11 +1098,6 @@ public Signature resolveOperator(OperatorType operatorType, List<? extends Type>
}
}

public Signature getCoercion(Type fromType, Type toType)
{
return getCoercion(fromType.getTypeSignature(), toType.getTypeSignature());
}

public Signature getCoercion(TypeSignature fromType, TypeSignature toType)
{
Signature signature = internalOperator(OperatorType.CAST.name(), toType, ImmutableList.of(fromType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ else if (type.getJavaType() == Slice.class) {
private static MethodHandle castToVarchar(FunctionRegistry functionRegistry, Type type)
{
try {
Signature cast = functionRegistry.getCoercion(type, VARCHAR);
Signature cast = functionRegistry.getCoercion(type.getTypeSignature(), VARCHAR.getTypeSignature());
return functionRegistry.getScalarFunctionImplementation(cast).getMethodHandle();
}
catch (OperatorNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.prestosql.metadata.BoundVariables;
import io.prestosql.metadata.FunctionRegistry;
import io.prestosql.metadata.Metadata;
import io.prestosql.metadata.Signature;
import io.prestosql.metadata.SqlOperator;
import io.prestosql.operator.aggregation.TypedSet;
import io.prestosql.spi.PrestoException;
Expand Down Expand Up @@ -107,7 +108,8 @@ private MethodHandle buildProcessor(FunctionRegistry functionRegistry, Type from
MethodHandle getter = nativeValueGetter(fromType);

// Adapt cast that takes ([ConnectorSession,] ?) to one that takes (?, ConnectorSession), where ? is the return type of getter.
ScalarFunctionImplementation castImplementation = functionRegistry.getScalarFunctionImplementation(functionRegistry.getCoercion(fromType, toType));
Signature signature = functionRegistry.getCoercion(fromType.getTypeSignature(), toType.getTypeSignature());
ScalarFunctionImplementation castImplementation = functionRegistry.getScalarFunctionImplementation(signature);
MethodHandle cast = castImplementation.getMethodHandle();
if (cast.type().parameterArray()[0] != ConnectorSession.class) {
cast = MethodHandles.dropArguments(cast, 0, ConnectorSession.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ScalarFunctionImplementation specialize(BoundVariables boundVariables, in

// the resulting method needs to return a boxed type
FunctionRegistry functionRegistry = metadata.getFunctionRegistry();
Signature signature = functionRegistry.getCoercion(fromType, toType);
Signature signature = functionRegistry.getCoercion(fromType.getTypeSignature(), toType.getTypeSignature());
ScalarFunctionImplementation implementation = functionRegistry.getScalarFunctionImplementation(signature);
argumentProperties = ImmutableList.of(implementation.getArgumentProperty(0));
MethodHandle coercion = implementation.getMethodHandle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ protected Type visitGenericLiteral(GenericLiteral node, StackableAstVisitorConte

if (!JSON.equals(type)) {
try {
metadata.getFunctionRegistry().getCoercion(VARCHAR, type);
metadata.getFunctionRegistry().getCoercion(VARCHAR.getTypeSignature(), type.getTypeSignature());
}
catch (IllegalArgumentException e) {
throw new SemanticException(TYPE_MISMATCH, node, "No literal form for type %s", type);
Expand Down Expand Up @@ -1054,7 +1054,7 @@ public Type visitCast(Cast node, StackableAstVisitorContext<Context> context)
Type value = process(node.getExpression(), context);
if (!value.equals(UNKNOWN) && !node.isTypeOnly()) {
try {
metadata.getFunctionRegistry().getCoercion(value, type);
metadata.getFunctionRegistry().getCoercion(value.getTypeSignature(), type.getTypeSignature());
}
catch (OperatorNotFoundException e) {
throw new SemanticException(TYPE_MISMATCH, node, "Cannot cast %s to %s", value, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public BytecodeNode generateExpression(Signature signature, BytecodeGeneratorCon

Signature function = generatorContext
.getRegistry()
.getCoercion(argument.getType(), returnType);
.getCoercion(argument.getType().getTypeSignature(), returnType.getTypeSignature());

return generatorContext.generateCall(function.getName(), generatorContext.getRegistry().getScalarFunctionImplementation(function), ImmutableList.of(generatorContext.generate(argument)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ private Optional<Signature> getSaturatedFloorCastOperator(Type fromType, Type to

private int compareOriginalValueToCoerced(Type originalValueType, Object originalValue, Type coercedValueType, Object coercedValue)
{
Signature castToOriginalTypeOperator = metadata.getFunctionRegistry().getCoercion(coercedValueType, originalValueType);
Signature castToOriginalTypeOperator = metadata.getFunctionRegistry().getCoercion(coercedValueType.getTypeSignature(), originalValueType.getTypeSignature());
Object coercedValueInOriginalType = functionInvoker.invoke(castToOriginalTypeOperator, session.toConnectorSession(), coercedValue);
Block originalValueBlock = Utils.nativeValueToBlock(originalValueType, originalValue);
Block coercedValueBlock = Utils.nativeValueToBlock(originalValueType, coercedValueInOriginalType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ protected Object visitNullIfExpression(NullIfExpression node, Object context)

Type commonType = typeCoercion.getCommonSuperType(firstType, secondType).get();

Signature firstCast = metadata.getFunctionRegistry().getCoercion(firstType, commonType);
Signature secondCast = metadata.getFunctionRegistry().getCoercion(secondType, commonType);
Signature firstCast = metadata.getFunctionRegistry().getCoercion(firstType.getTypeSignature(), commonType.getTypeSignature());
Signature secondCast = metadata.getFunctionRegistry().getCoercion(secondType.getTypeSignature(), commonType.getTypeSignature());

// cast(first as <common type>) == cast(second as <common type>)
boolean equal = Boolean.TRUE.equals(invokeOperator(
Expand Down Expand Up @@ -1089,7 +1089,7 @@ public Object visitCast(Cast node, Object context)
return null;
}

Signature operator = metadata.getFunctionRegistry().getCoercion(sourceType, targetType);
Signature operator = metadata.getFunctionRegistry().getCoercion(sourceType.getTypeSignature(), targetType.getTypeSignature());

try {
return functionInvoker.invoke(operator, session, ImmutableList.of(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected Object visitGenericLiteral(GenericLiteral node, ConnectorSession sessi
}

try {
Signature signature = metadata.getFunctionRegistry().getCoercion(VARCHAR, type);
Signature signature = metadata.getFunctionRegistry().getCoercion(VARCHAR.getTypeSignature(), type.getTypeSignature());
return functionInvoker.invoke(signature, session, ImmutableList.of(utf8Slice(node.getValue())));
}
catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private Expression unwrapCast(ComparisonExpression expression)
return expression;
}

Signature sourceToTarget = metadata.getFunctionRegistry().getCoercion(sourceType, targetType);
Signature sourceToTarget = metadata.getFunctionRegistry().getCoercion(sourceType.getTypeSignature(), targetType.getTypeSignature());

Optional<Type.Range> sourceRange = sourceType.getRange();
if (sourceRange.isPresent()) {
Expand Down Expand Up @@ -269,7 +269,7 @@ private Expression unwrapCast(ComparisonExpression expression)

Signature targetToSource;
try {
targetToSource = metadata.getFunctionRegistry().getCoercion(targetType, sourceType);
targetToSource = metadata.getFunctionRegistry().getCoercion(targetType.getTypeSignature(), sourceType.getTypeSignature());
}
catch (OperatorNotFoundException e) {
// Without a cast between target -> source, there's nothing more we can do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private CallExpression rewriteCast(CallExpression call)
}

return call(
metadata.getFunctionRegistry().getCoercion(call.getArguments().get(0).getType(), call.getType()),
metadata.getFunctionRegistry().getCoercion(call.getArguments().get(0).getType().getTypeSignature(), call.getType().getTypeSignature()),
call.getType(),
call.getArguments());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class TestFunctionRegistry
public void testIdentityCast()
{
FunctionRegistry registry = createTestMetadataManager().getFunctionRegistry();
Signature exactOperator = registry.getCoercion(HYPER_LOG_LOG, HYPER_LOG_LOG);
Signature exactOperator = registry.getCoercion(HYPER_LOG_LOG.getTypeSignature(), HYPER_LOG_LOG.getTypeSignature());
assertEquals(exactOperator.getName(), mangleOperatorName(OperatorType.CAST.name()));
assertEquals(transform(exactOperator.getArgumentTypes(), Functions.toStringFunction()), ImmutableList.of(StandardTypes.HYPER_LOG_LOG));
assertEquals(exactOperator.getReturnType().getBase(), StandardTypes.HYPER_LOG_LOG);
Expand Down

0 comments on commit 0ec41a9

Please sign in to comment.