Search in sources :

Example 1 with OperatorType

use of com.facebook.presto.common.function.OperatorType in project presto by prestodb.

the class DruidAggregationProjectConverter method visitCall.

@Override
public DruidExpression visitCall(CallExpression call, Map<VariableReferenceExpression, DruidQueryGeneratorContext.Selection> context) {
    Optional<DruidExpression> basicCallHandlingResult = basicCallHandling(call, context);
    if (basicCallHandlingResult.isPresent()) {
        return basicCallHandlingResult.get();
    }
    FunctionMetadata functionMetadata = functionMetadataManager.getFunctionMetadata(call.getFunctionHandle());
    Optional<OperatorType> operatorTypeOptional = functionMetadata.getOperatorType();
    if (operatorTypeOptional.isPresent()) {
        OperatorType operatorType = operatorTypeOptional.get();
        if (operatorType.isArithmeticOperator()) {
            return handleArithmeticExpression(call, operatorType, context);
        }
        if (operatorType.isComparisonOperator()) {
            throw new PrestoException(DRUID_PUSHDOWN_UNSUPPORTED_EXPRESSION, "Unsupported operator: " + call + " to pushdown for Druid connector.");
        }
    }
    return handleFunction(call, context);
}
Also used : FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) PrestoException(com.facebook.presto.spi.PrestoException) OperatorType(com.facebook.presto.common.function.OperatorType)

Example 2 with OperatorType

use of com.facebook.presto.common.function.OperatorType in project presto by prestodb.

the class BuiltInTypeAndFunctionNamespaceManager method getFunctionMetadata.

@Override
public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle) {
    checkArgument(functionHandle instanceof BuiltInFunctionHandle, "Expect BuiltInFunctionHandle");
    Signature signature = ((BuiltInFunctionHandle) functionHandle).getSignature();
    SpecializedFunctionKey functionKey;
    try {
        functionKey = specializedFunctionKeyCache.getUnchecked(signature);
    } catch (UncheckedExecutionException e) {
        throwIfInstanceOf(e.getCause(), PrestoException.class);
        throw e;
    }
    SqlFunction function = functionKey.getFunction();
    Optional<OperatorType> operatorType = tryGetOperatorType(signature.getName());
    if (operatorType.isPresent()) {
        return new FunctionMetadata(operatorType.get(), signature.getArgumentTypes(), signature.getReturnType(), signature.getKind(), JAVA, function.isDeterministic(), function.isCalledOnNullInput());
    } else if (function instanceof SqlInvokedFunction) {
        SqlInvokedFunction sqlFunction = (SqlInvokedFunction) function;
        List<String> argumentNames = sqlFunction.getParameters().stream().map(Parameter::getName).collect(toImmutableList());
        return new FunctionMetadata(signature.getName(), signature.getArgumentTypes(), argumentNames, signature.getReturnType(), signature.getKind(), sqlFunction.getRoutineCharacteristics().getLanguage(), SQL, function.isDeterministic(), function.isCalledOnNullInput(), sqlFunction.getVersion());
    } else {
        return new FunctionMetadata(signature.getName(), signature.getArgumentTypes(), signature.getReturnType(), signature.getKind(), JAVA, function.isDeterministic(), function.isCalledOnNullInput());
    }
}
Also used : FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) TypeSignature(com.facebook.presto.common.type.TypeSignature) Parameter(com.facebook.presto.spi.function.Parameter) TypeSignatureParameter(com.facebook.presto.common.type.TypeSignatureParameter) TypeParameter(com.facebook.presto.common.type.TypeParameter) PrestoException(com.facebook.presto.spi.PrestoException) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) OperatorType.tryGetOperatorType(com.facebook.presto.common.function.OperatorType.tryGetOperatorType) OperatorType(com.facebook.presto.common.function.OperatorType) SqlFunction(com.facebook.presto.spi.function.SqlFunction)

Example 3 with OperatorType

use of com.facebook.presto.common.function.OperatorType in project presto by prestodb.

the class PinotAggregationProjectConverter method visitCall.

@Override
public PinotExpression visitCall(CallExpression call, Map<VariableReferenceExpression, PinotQueryGeneratorContext.Selection> context) {
    Optional<PinotExpression> basicCallHandlingResult = basicCallHandling(call, context);
    if (basicCallHandlingResult.isPresent()) {
        return basicCallHandlingResult.get();
    }
    FunctionMetadata functionMetadata = functionMetadataManager.getFunctionMetadata(call.getFunctionHandle());
    Optional<OperatorType> operatorTypeOptional = functionMetadata.getOperatorType();
    if (operatorTypeOptional.isPresent()) {
        OperatorType operatorType = operatorTypeOptional.get();
        if (operatorType.isArithmeticOperator()) {
            return handleArithmeticExpression(call, operatorType, context);
        }
        if (operatorType.isComparisonOperator()) {
            throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "Comparison operator not supported: " + call);
        }
    }
    return handleFunction(call, context);
}
Also used : FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) PinotException(com.facebook.presto.pinot.PinotException) OperatorType(com.facebook.presto.common.function.OperatorType)

Example 4 with OperatorType

use of com.facebook.presto.common.function.OperatorType in project presto by prestodb.

the class AbstractMinMaxAggregationFunction method specialize.

@Override
public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
    Type type = boundVariables.getTypeVariable("E");
    MethodHandle compareMethodHandle = functionAndTypeManager.getJavaScalarFunctionImplementation(functionAndTypeManager.resolveOperator(operatorType, fromTypes(type, type))).getMethodHandle();
    return generateAggregation(type, compareMethodHandle);
}
Also used : Type(com.facebook.presto.common.type.Type) OperatorType(com.facebook.presto.common.function.OperatorType) MethodHandle(java.lang.invoke.MethodHandle)

Example 5 with OperatorType

use of com.facebook.presto.common.function.OperatorType in project presto by prestodb.

the class TestEqualityInference method isOperation.

private static boolean isOperation(RowExpression expression, OperatorType type) {
    if (expression instanceof CallExpression) {
        CallExpression call = (CallExpression) expression;
        Optional<OperatorType> expressionOperatorType = METADATA.getFunctionAndTypeManager().getFunctionMetadata(call.getFunctionHandle()).getOperatorType();
        if (expressionOperatorType.isPresent()) {
            return expressionOperatorType.get() == type;
        }
    }
    return false;
}
Also used : CallExpression(com.facebook.presto.spi.relation.CallExpression) OperatorType(com.facebook.presto.common.function.OperatorType)

Aggregations

OperatorType (com.facebook.presto.common.function.OperatorType)18 FunctionMetadata (com.facebook.presto.spi.function.FunctionMetadata)9 Type (com.facebook.presto.common.type.Type)5 PrestoException (com.facebook.presto.spi.PrestoException)5 CallExpression (com.facebook.presto.spi.relation.CallExpression)5 ImmutableList (com.google.common.collect.ImmutableList)5 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 MethodHandle (java.lang.invoke.MethodHandle)4 OperatorType.tryGetOperatorType (com.facebook.presto.common.function.OperatorType.tryGetOperatorType)3 TypeSignature (com.facebook.presto.common.type.TypeSignature)3 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)3 CallSiteBinder (com.facebook.presto.bytecode.CallSiteBinder)2 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)2 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)2 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)2 ArrayType (com.facebook.presto.common.type.ArrayType)2 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)2 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)2 Signature (com.facebook.presto.spi.function.Signature)2