Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -26,6 +26,8 @@
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.block.Block;
import com.facebook.presto.spi.function.AggregationState;
import com.facebook.presto.spi.function.BlockIndex;
import com.facebook.presto.spi.function.BlockPosition;
import com.facebook.presto.spi.function.OutputFunction;
import com.facebook.presto.spi.function.SqlType;
import com.facebook.presto.spi.function.TypeParameter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.facebook.presto.spi.block.BlockBuilder;
import com.facebook.presto.spi.function.AggregationFunction;
import com.facebook.presto.spi.function.AggregationState;
import com.facebook.presto.spi.function.BlockIndex;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I squash the fixup commit to the wrong commit. This two lines should go to the first commit...

import com.facebook.presto.spi.function.BlockPosition;
import com.facebook.presto.spi.function.CombineFunction;
import com.facebook.presto.spi.function.InputFunction;
import com.facebook.presto.spi.function.OperatorDependency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.facebook.presto.spi.block.BlockBuilder;
import com.facebook.presto.spi.function.AggregationFunction;
import com.facebook.presto.spi.function.AggregationState;
import com.facebook.presto.spi.function.BlockIndex;
import com.facebook.presto.spi.function.BlockPosition;
import com.facebook.presto.spi.function.CombineFunction;
import com.facebook.presto.spi.function.InputFunction;
import com.facebook.presto.spi.function.OperatorDependency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.facebook.presto.spi.type.TypeManager;
import com.facebook.presto.spi.type.TypeSignature;

import java.util.Objects;

import static com.facebook.presto.metadata.SignatureBinder.applyBoundVariables;
import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
import static java.util.Objects.requireNonNull;
Expand All @@ -38,4 +40,24 @@ public Type resolve(BoundVariables boundVariables, TypeManager typeManager, Func
{
return typeManager.getType(applyBoundVariables(signature, boundVariables));
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}
TypeImplementationDependency that = (TypeImplementationDependency) o;
return Objects.equals(signature, that.signature);
}

@Override
public int hashCode()
{
return Objects.hash(signature);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.facebook.presto.spi.function.IsNull;
import com.facebook.presto.spi.function.OperatorDependency;
import com.facebook.presto.spi.function.ScalarOperator;
import com.facebook.presto.spi.function.SqlNullable;
import com.facebook.presto.spi.function.SqlType;
import com.facebook.presto.spi.function.TypeParameter;
import com.facebook.presto.spi.type.StandardTypes;
Expand Down Expand Up @@ -47,9 +46,9 @@ public static boolean isDistinctFrom(
MethodHandle valueDistinctFromFunction,
@TypeParameter("K") Type keyType,
@TypeParameter("V") Type valueType,
@SqlNullable @SqlType("map(K,V)") Block leftMapBlock,
@SqlType("map(K,V)") Block leftMapBlock,
@IsNull boolean leftMapNull,
@SqlNullable @SqlType("map(K,V)") Block rightMapBlock,
@SqlType("map(K,V)") Block rightMapBlock,
@IsNull boolean rightMapNull)
{
if (leftMapNull != rightMapNull) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import com.facebook.presto.metadata.Signature;
import com.facebook.presto.metadata.SqlScalarFunction;
import com.facebook.presto.operator.ParametricImplementationsGroup;
import com.facebook.presto.operator.scalar.annotations.ScalarImplementation;
import com.facebook.presto.operator.scalar.annotations.ScalarImplementation.MethodHandleAndConstructor;
import com.facebook.presto.operator.scalar.annotations.ParametricScalarImplementation;
import com.facebook.presto.spi.PrestoException;
import com.facebook.presto.spi.type.TypeManager;
import com.google.common.annotations.VisibleForTesting;
Expand All @@ -38,12 +37,12 @@ public class ParametricScalar
extends SqlScalarFunction
{
private final ScalarHeader details;
private final ParametricImplementationsGroup<ScalarImplementation> implementations;
private final ParametricImplementationsGroup<ParametricScalarImplementation> implementations;

public ParametricScalar(
Signature signature,
ScalarHeader details,
ParametricImplementationsGroup<ScalarImplementation> implementations)
ParametricImplementationsGroup<ParametricScalarImplementation> implementations)
{
super(signature);
this.details = requireNonNull(details);
Expand All @@ -69,7 +68,7 @@ public String getDescription()
}

@VisibleForTesting
public ParametricImplementationsGroup<ScalarImplementation> getImplementations()
public ParametricImplementationsGroup<ParametricScalarImplementation> getImplementations()
{
return implementations;
}
Expand All @@ -79,44 +78,28 @@ public ScalarFunctionImplementation specialize(BoundVariables boundVariables, in
{
Signature boundSignature = applyBoundVariables(getSignature(), boundVariables, arity);
if (implementations.getExactImplementations().containsKey(boundSignature)) {
ScalarImplementation implementation = implementations.getExactImplementations().get(boundSignature);
Optional<MethodHandleAndConstructor> methodHandleAndConstructor = implementation.specialize(boundSignature, boundVariables, typeManager, functionRegistry);
checkCondition(methodHandleAndConstructor.isPresent(), FUNCTION_IMPLEMENTATION_ERROR, String.format("Exact implementation of %s do not match expected java types.", boundSignature.getName()));
return new ScalarFunctionImplementation(
implementation.isNullable(),
implementation.getArgumentProperties(),
methodHandleAndConstructor.get().getMethodHandle(),
methodHandleAndConstructor.get().getConstructor(),
isDeterministic());
ParametricScalarImplementation implementation = implementations.getExactImplementations().get(boundSignature);
Optional<ScalarFunctionImplementation> scalarFunctionImplementation = implementation.specialize(boundSignature, boundVariables, typeManager, functionRegistry, isDeterministic());
checkCondition(scalarFunctionImplementation.isPresent(), FUNCTION_IMPLEMENTATION_ERROR, String.format("Exact implementation of %s do not match expected java types.", boundSignature.getName()));
return scalarFunctionImplementation.get();
}

ScalarFunctionImplementation selectedImplementation = null;
for (ScalarImplementation implementation : implementations.getSpecializedImplementations()) {
Optional<MethodHandleAndConstructor> methodHandle = implementation.specialize(boundSignature, boundVariables, typeManager, functionRegistry);
if (methodHandle.isPresent()) {
for (ParametricScalarImplementation implementation : implementations.getSpecializedImplementations()) {
Optional<ScalarFunctionImplementation> scalarFunctionImplementation = implementation.specialize(boundSignature, boundVariables, typeManager, functionRegistry, isDeterministic());
if (scalarFunctionImplementation.isPresent()) {
checkCondition(selectedImplementation == null, AMBIGUOUS_FUNCTION_IMPLEMENTATION, "Ambiguous implementation for %s with bindings %s", getSignature(), boundVariables.getTypeVariables());
selectedImplementation = new ScalarFunctionImplementation(
implementation.isNullable(),
implementation.getArgumentProperties(),
methodHandle.get().getMethodHandle(),
methodHandle.get().getConstructor(),
isDeterministic());
selectedImplementation = scalarFunctionImplementation.get();
}
}
if (selectedImplementation != null) {
return selectedImplementation;
}

for (ScalarImplementation implementation : implementations.getGenericImplementations()) {
Optional<MethodHandleAndConstructor> methodHandle = implementation.specialize(boundSignature, boundVariables, typeManager, functionRegistry);
if (methodHandle.isPresent()) {
for (ParametricScalarImplementation implementation : implementations.getGenericImplementations()) {
Optional<ScalarFunctionImplementation> scalarFunctionImplementation = implementation.specialize(boundSignature, boundVariables, typeManager, functionRegistry, isDeterministic());
if (scalarFunctionImplementation.isPresent()) {
checkCondition(selectedImplementation == null, AMBIGUOUS_FUNCTION_IMPLEMENTATION, "Ambiguous implementation for %s with bindings %s", getSignature(), boundVariables.getTypeVariables());
selectedImplementation = new ScalarFunctionImplementation(
implementation.isNullable(),
implementation.getArgumentProperties(),
methodHandle.get().getMethodHandle(),
methodHandle.get().getConstructor(),
isDeterministic());
selectedImplementation = scalarFunctionImplementation.get();
}
}
if (selectedImplementation != null) {
Expand Down
Loading