Skip to content

Commit

Permalink
Rename ScalarFunctionImplementation to SpecializedSqlScalarFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Sep 4, 2022
1 parent ef6b580 commit ff71d41
Show file tree
Hide file tree
Showing 71 changed files with 188 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.google.common.util.concurrent.UncheckedExecutionException;
import io.trino.collect.cache.NonEvictableCache;
import io.trino.operator.aggregation.AggregationMetadata;
import io.trino.operator.scalar.ScalarFunctionImplementation;
import io.trino.operator.scalar.SpecializedSqlScalarFunction;
import io.trino.operator.scalar.annotations.ScalarFromAnnotationsParser;
import io.trino.operator.window.SqlWindowFunction;
import io.trino.operator.window.WindowAnnotationsParser;
Expand Down Expand Up @@ -51,7 +51,7 @@ public class InternalFunctionBundle
implements FunctionBundle
{
// scalar function specialization may involve expensive code generation
private final NonEvictableCache<FunctionKey, ScalarFunctionImplementation> specializedScalarCache;
private final NonEvictableCache<FunctionKey, SpecializedSqlScalarFunction> specializedScalarCache;
private final NonEvictableCache<FunctionKey, AggregationMetadata> specializedAggregationCache;
private final NonEvictableCache<FunctionKey, WindowFunctionSupplier> specializedWindowCache;
private final Map<FunctionId, SqlFunction> functions;
Expand Down Expand Up @@ -115,9 +115,9 @@ public FunctionInvoker getScalarFunctionInvoker(
FunctionDependencies functionDependencies,
InvocationConvention invocationConvention)
{
ScalarFunctionImplementation scalarFunctionImplementation;
SpecializedSqlScalarFunction specializedSqlScalarFunction;
try {
scalarFunctionImplementation = uncheckedCacheGet(
specializedSqlScalarFunction = uncheckedCacheGet(
specializedScalarCache,
new FunctionKey(functionId, boundSignature),
() -> specializeScalarFunction(functionId, boundSignature, functionDependencies));
Expand All @@ -126,10 +126,10 @@ public FunctionInvoker getScalarFunctionInvoker(
throwIfInstanceOf(e.getCause(), TrinoException.class);
throw new RuntimeException(e.getCause());
}
return scalarFunctionImplementation.getScalarFunctionInvoker(invocationConvention);
return specializedSqlScalarFunction.getScalarFunctionInvoker(invocationConvention);
}

private ScalarFunctionImplementation specializeScalarFunction(FunctionId functionId, BoundSignature boundSignature, FunctionDependencies functionDependencies)
private SpecializedSqlScalarFunction specializeScalarFunction(FunctionId functionId, BoundSignature boundSignature, FunctionDependencies functionDependencies)
{
SqlScalarFunction function = (SqlScalarFunction) getSqlFunction(functionId);
return function.specialize(boundSignature, functionDependencies);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Primitives;
import io.airlift.slice.Slice;
import io.trino.operator.scalar.ChoicesScalarFunctionImplementation;
import io.trino.operator.scalar.ScalarFunctionImplementation;
import io.trino.operator.scalar.ChoicesSpecializedSqlScalarFunction;
import io.trino.operator.scalar.SpecializedSqlScalarFunction;
import io.trino.spi.block.Block;
import io.trino.spi.block.BlockEncodingSerde;
import io.trino.spi.type.Type;
Expand Down Expand Up @@ -62,7 +62,7 @@ public LiteralFunction(BlockEncodingSerde blockEncodingSerde)
}

@Override
public ScalarFunctionImplementation specialize(BoundSignature boundSignature)
public SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
Type parameterType = boundSignature.getArgumentTypes().get(0);
Type type = boundSignature.getReturnType();
Expand All @@ -88,7 +88,7 @@ else if (type.getJavaType() != Slice.class) {
parameterType.getJavaType(),
type.getJavaType());

return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
FAIL_ON_NULL,
ImmutableList.of(NEVER_NULL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import io.trino.metadata.PolymorphicScalarFunctionBuilder.MethodAndNativeContainerTypes;
import io.trino.metadata.PolymorphicScalarFunctionBuilder.MethodsGroup;
import io.trino.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext;
import io.trino.operator.scalar.ChoicesScalarFunctionImplementation;
import io.trino.operator.scalar.ChoicesScalarFunctionImplementation.ScalarImplementationChoice;
import io.trino.operator.scalar.ScalarFunctionImplementation;
import io.trino.operator.scalar.ChoicesSpecializedSqlScalarFunction;
import io.trino.operator.scalar.ChoicesSpecializedSqlScalarFunction.ScalarImplementationChoice;
import io.trino.operator.scalar.SpecializedSqlScalarFunction;
import io.trino.spi.function.InvocationConvention.InvocationArgumentConvention;
import io.trino.spi.function.InvocationConvention.InvocationReturnConvention;
import io.trino.spi.type.Type;
Expand Down Expand Up @@ -48,7 +48,7 @@ class PolymorphicScalarFunction
}

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
ImmutableList.Builder<ScalarImplementationChoice> implementationChoices = ImmutableList.builder();

Expand All @@ -58,7 +58,7 @@ protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
implementationChoices.add(getScalarFunctionImplementationChoice(functionBinding, choice));
}

return new ChoicesScalarFunctionImplementation(boundSignature, implementationChoices.build());
return new ChoicesSpecializedSqlScalarFunction(boundSignature, implementationChoices.build());
}

private ScalarImplementationChoice getScalarFunctionImplementationChoice(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package io.trino.metadata;

import io.trino.operator.scalar.ScalarFunctionImplementation;
import io.trino.operator.scalar.SpecializedSqlScalarFunction;

public abstract class SqlScalarFunction
implements SqlFunction
Expand All @@ -31,12 +31,12 @@ public FunctionMetadata getFunctionMetadata()
return functionMetadata;
}

public ScalarFunctionImplementation specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies)
public SpecializedSqlScalarFunction specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies)
{
return specialize(boundSignature);
}

protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public FunctionDependencyDeclaration getFunctionDependencies()
}

@Override
public ScalarFunctionImplementation specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies)
public SpecializedSqlScalarFunction specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies)
{
Type type = boundSignature.getReturnType();
checkArgument(type.isOrderable(), "Type must be orderable");
Expand All @@ -112,7 +112,7 @@ public ScalarFunctionImplementation specialize(BoundSignature boundSignature, Fu
Class<?> clazz = generate(javaTypes, compareMethod);
MethodHandle methodHandle = methodHandle(clazz, getFunctionMetadata().getSignature().getName(), javaTypes.toArray(new Class<?>[0]));

return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
NULLABLE_RETURN,
nCopies(javaTypes.size(), BOXED_NULLABLE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ private ApplyFunction()
}

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
Type argumentType = boundSignature.getArgumentTypes().get(0);
Type returnType = boundSignature.getReturnType();
return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
NULLABLE_RETURN,
ImmutableList.of(BOXED_NULLABLE, FUNCTION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private ArrayConcatFunction()
}

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
if (boundSignature.getArity() < 2) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "There must be two or more arguments to " + FUNCTION_NAME);
Expand All @@ -80,7 +80,7 @@ protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
METHOD_HANDLE.bindTo(arrayType.getElementType()),
USER_STATE_FACTORY.bindTo(arrayType.getElementType()));

return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
FAIL_ON_NULL,
nCopies(boundSignature.getArity(), NEVER_NULL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ArrayConstructor()
}

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
ImmutableList.Builder<Class<?>> builder = ImmutableList.builder();
Type type = boundSignature.getArgumentTypes().get(0);
Expand All @@ -108,7 +108,7 @@ protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
FAIL_ON_NULL,
nCopies(stackTypes.size(), BOXED_NULLABLE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ private ArrayFlattenFunction()
}

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
ArrayType arrayType = (ArrayType) boundSignature.getReturnType();
MethodHandle methodHandle = METHOD_HANDLE
.bindTo(arrayType.getElementType())
.bindTo(arrayType);
return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
FAIL_ON_NULL,
ImmutableList.of(NEVER_NULL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public FunctionDependencyDeclaration getFunctionDependencies()
}

@Override
public ScalarFunctionImplementation specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies)
public SpecializedSqlScalarFunction specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies)
{
return specializeArrayJoin(boundSignature, functionDependencies, METHOD_HANDLE);
}
Expand Down Expand Up @@ -145,12 +145,12 @@ private static FunctionDependencyDeclaration arrayJoinFunctionDependencies()
}

@Override
public ScalarFunctionImplementation specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies)
public SpecializedSqlScalarFunction specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies)
{
return specializeArrayJoin(boundSignature, functionDependencies, METHOD_HANDLE);
}

private static ChoicesScalarFunctionImplementation specializeArrayJoin(
private static ChoicesSpecializedSqlScalarFunction specializeArrayJoin(
BoundSignature boundSignature,
FunctionDependencies functionDependencies,
MethodHandle methodHandle)
Expand All @@ -159,7 +159,7 @@ private static ChoicesScalarFunctionImplementation specializeArrayJoin(

Type type = ((ArrayType) boundSignature.getArgumentTypes().get(0)).getElementType();
if (type instanceof UnknownType) {
return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
FAIL_ON_NULL,
argumentConventions,
Expand All @@ -177,7 +177,7 @@ private static ChoicesScalarFunctionImplementation specializeArrayJoin(
}

MethodHandle target = MethodHandles.insertArguments(methodHandle, 0, cast);
return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
FAIL_ON_NULL,
argumentConventions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ private ArrayReduceFunction()
}

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
ArrayType arrayType = (ArrayType) boundSignature.getArgumentTypes().get(0);
Type inputType = arrayType.getElementType();
Type intermediateType = boundSignature.getArgumentTypes().get(1);
Type outputType = boundSignature.getReturnType();
MethodHandle methodHandle = METHOD_HANDLE.bindTo(inputType);
return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
NULLABLE_RETURN,
ImmutableList.of(NEVER_NULL, BOXED_NULLABLE, FUNCTION, FUNCTION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected ArraySubscriptOperator()
}

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
Type elementType = boundSignature.getReturnType();

Expand All @@ -87,7 +87,7 @@ else if (elementType.getJavaType() == Slice.class) {
}
methodHandle = methodHandle.bindTo(elementType);
requireNonNull(methodHandle, "methodHandle is null");
return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
NULLABLE_RETURN,
ImmutableList.of(NEVER_NULL, NEVER_NULL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ArrayToElementConcatFunction()
}

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
Type type = boundSignature.getArgumentTypes().get(1);
MethodHandle methodHandle;
Expand All @@ -78,7 +78,7 @@ else if (type.getJavaType() == Slice.class) {
}
methodHandle = methodHandle.bindTo(type);

return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
FAIL_ON_NULL,
ImmutableList.of(NEVER_NULL, NEVER_NULL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ private ArrayToJsonCast(boolean legacyRowToJson)
}

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
ArrayType arrayType = (ArrayType) boundSignature.getArgumentTypes().get(0);
checkCondition(canCastToJson(arrayType), INVALID_CAST_ARGUMENT, "Cannot cast %s to JSON", arrayType);

JsonGeneratorWriter writer = JsonGeneratorWriter.createJsonGeneratorWriter(arrayType.getElementType(), legacyRowToJson);
MethodHandle methodHandle = METHOD_HANDLE.bindTo(writer);
return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
FAIL_ON_NULL,
ImmutableList.of(NEVER_NULL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ private ArrayTransformFunction()
}

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
Type inputType = ((ArrayType) boundSignature.getArgumentTypes().get(0)).getElementType();
Type outputType = ((ArrayType) boundSignature.getReturnType()).getElementType();
Class<?> generatedClass = generateTransform(inputType, outputType);
return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
FAIL_ON_NULL,
ImmutableList.of(NEVER_NULL, FUNCTION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public CastFromUnknownOperator()
}

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature)
protected SpecializedSqlScalarFunction specialize(BoundSignature boundSignature)
{
Type toType = boundSignature.getReturnType();
MethodHandle methodHandle = METHOD_HANDLE_NON_NULL.asType(METHOD_HANDLE_NON_NULL.type().changeReturnType(toType.getJavaType()));
return new ChoicesScalarFunctionImplementation(
return new ChoicesSpecializedSqlScalarFunction(
boundSignature,
FAIL_ON_NULL,
ImmutableList.of(NEVER_NULL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
import static java.util.Comparator.comparingInt;
import static java.util.Objects.requireNonNull;

public final class ChoicesScalarFunctionImplementation
implements ScalarFunctionImplementation
public final class ChoicesSpecializedSqlScalarFunction
implements SpecializedSqlScalarFunction
{
private final ScalarFunctionAdapter functionAdapter = new ScalarFunctionAdapter(RETURN_NULL_ON_NULL);

private final BoundSignature boundSignature;
private final List<ScalarImplementationChoice> choices;

public ChoicesScalarFunctionImplementation(
public ChoicesSpecializedSqlScalarFunction(
BoundSignature boundSignature,
InvocationReturnConvention returnConvention,
List<InvocationArgumentConvention> argumentConventions,
Expand All @@ -54,7 +54,7 @@ public ChoicesScalarFunctionImplementation(
this(boundSignature, returnConvention, argumentConventions, ImmutableList.of(), methodHandle, Optional.empty());
}

public ChoicesScalarFunctionImplementation(
public ChoicesSpecializedSqlScalarFunction(
BoundSignature boundSignature,
InvocationReturnConvention returnConvention,
List<InvocationArgumentConvention> argumentConventions,
Expand All @@ -64,7 +64,7 @@ public ChoicesScalarFunctionImplementation(
this(boundSignature, returnConvention, argumentConventions, ImmutableList.of(), methodHandle, instanceFactory);
}

public ChoicesScalarFunctionImplementation(
public ChoicesSpecializedSqlScalarFunction(
BoundSignature boundSignature,
InvocationReturnConvention returnConvention,
List<InvocationArgumentConvention> argumentConventions,
Expand All @@ -85,7 +85,7 @@ public ChoicesScalarFunctionImplementation(
* @param boundSignature
* @param choices the list of choices, ordered from generic to specific
*/
public ChoicesScalarFunctionImplementation(BoundSignature boundSignature, List<ScalarImplementationChoice> choices)
public ChoicesSpecializedSqlScalarFunction(BoundSignature boundSignature, List<ScalarImplementationChoice> choices)
{
this.boundSignature = boundSignature;
checkArgument(!choices.isEmpty(), "choices is an empty list");
Expand Down
Loading

0 comments on commit ff71d41

Please sign in to comment.