Search in sources :

Example 16 with OperatorType

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

the class RowExpressionVerifier method visitComparisonExpression.

@Override
protected Boolean visitComparisonExpression(ComparisonExpression expected, RowExpression actual) {
    if (actual instanceof CallExpression) {
        FunctionMetadata functionMetadata = metadata.getFunctionAndTypeManager().getFunctionMetadata(((CallExpression) actual).getFunctionHandle());
        if (!functionMetadata.getOperatorType().isPresent() || !functionMetadata.getOperatorType().get().isComparisonOperator()) {
            return false;
        }
        OperatorType actualOperatorType = functionMetadata.getOperatorType().get();
        OperatorType expectedOperatorType = getOperatorType(expected.getOperator());
        if (expectedOperatorType.equals(actualOperatorType)) {
            if (actualOperatorType == EQUAL) {
                return (process(expected.getLeft(), ((CallExpression) actual).getArguments().get(0)) && process(expected.getRight(), ((CallExpression) actual).getArguments().get(1))) || (process(expected.getLeft(), ((CallExpression) actual).getArguments().get(1)) && process(expected.getRight(), ((CallExpression) actual).getArguments().get(0)));
            }
            // TODO support other comparison operators
            return process(expected.getLeft(), ((CallExpression) actual).getArguments().get(0)) && process(expected.getRight(), ((CallExpression) actual).getArguments().get(1));
        }
    }
    return false;
}
Also used : FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) CallExpression(com.facebook.presto.spi.relation.CallExpression) OperatorType(com.facebook.presto.common.function.OperatorType)

Example 17 with OperatorType

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

the class FunctionsParserHelper method createTypeVariableConstraints.

public static List<TypeVariableConstraint> createTypeVariableConstraints(Iterable<TypeParameter> typeParameters, List<ImplementationDependency> dependencies) {
    Set<String> orderableRequired = new HashSet<>();
    Set<String> comparableRequired = new HashSet<>();
    for (ImplementationDependency dependency : dependencies) {
        if (dependency instanceof OperatorImplementationDependency) {
            OperatorType operator = ((OperatorImplementationDependency) dependency).getOperator();
            if (operator == CAST) {
                continue;
            }
            Set<String> argumentTypes = ((OperatorImplementationDependency) dependency).getArgumentTypes().stream().map(TypeSignature::getBase).collect(toImmutableSet());
            checkArgument(argumentTypes.size() == 1, "Operator dependency must only have arguments of a single type");
            String argumentType = Iterables.getOnlyElement(argumentTypes);
            if (COMPARABLE_TYPE_OPERATORS.contains(operator)) {
                comparableRequired.add(argumentType);
            }
            if (ORDERABLE_TYPE_OPERATORS.contains(operator)) {
                orderableRequired.add(argumentType);
            }
        }
    }
    ImmutableList.Builder<TypeVariableConstraint> typeVariableConstraints = ImmutableList.builder();
    for (TypeParameter typeParameter : typeParameters) {
        String name = typeParameter.value();
        String variadicBound = typeParameter.boundedBy().isEmpty() ? null : typeParameter.boundedBy();
        checkArgument(variadicBound == null || PARAMETRIC_TYPES.contains(variadicBound), "boundedBy must be a parametric type, got %s", variadicBound);
        if (orderableRequired.contains(name)) {
            typeVariableConstraints.add(new TypeVariableConstraint(name, false, true, variadicBound, false));
        } else if (comparableRequired.contains(name)) {
            typeVariableConstraints.add(new TypeVariableConstraint(name, true, false, variadicBound, false));
        } else {
            typeVariableConstraints.add(new TypeVariableConstraint(name, false, false, variadicBound, false));
        }
    }
    return typeVariableConstraints.build();
}
Also used : TypeParameter(com.facebook.presto.spi.function.TypeParameter) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) OperatorType(com.facebook.presto.common.function.OperatorType) TypeVariableConstraint(com.facebook.presto.spi.function.TypeVariableConstraint) HashSet(java.util.HashSet)

Example 18 with OperatorType

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

the class PinotFilterExpressionConverter method visitCall.

@Override
public PinotExpression visitCall(CallExpression call, Function<VariableReferenceExpression, Selection> context) {
    FunctionHandle functionHandle = call.getFunctionHandle();
    if (standardFunctionResolution.isNotFunction(functionHandle)) {
        return handleNot(call, context);
    }
    if (standardFunctionResolution.isCastFunction(functionHandle)) {
        return handleCast(call, context);
    }
    if (standardFunctionResolution.isBetweenFunction(functionHandle)) {
        return handleBetween(call, context);
    }
    FunctionMetadata functionMetadata = functionMetadataManager.getFunctionMetadata(call.getFunctionHandle());
    Optional<OperatorType> operatorTypeOptional = functionMetadata.getOperatorType();
    if (operatorTypeOptional.isPresent()) {
        OperatorType operatorType = operatorTypeOptional.get();
        if (operatorType.isArithmeticOperator()) {
            throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "Arithmetic expressions are not supported in filter: " + call);
        }
        if (operatorType.isComparisonOperator()) {
            return handleLogicalBinary(operatorType.getOperator(), call, context);
        }
    }
    if ("contains".equals(functionMetadata.getName().getObjectName())) {
        return handleContains(call, context);
    }
    // Otherwise TypeManager.canCoerce(...) will return false and directly fail this query.
    if (functionMetadata.getName().getObjectName().equalsIgnoreCase("$literal$timestamp") || functionMetadata.getName().getObjectName().equalsIgnoreCase("$literal$date")) {
        return handleDateAndTimestampMagicLiteralFunction(call, context);
    }
    throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), format("function %s not supported in filter", call));
}
Also used : FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) PinotException(com.facebook.presto.pinot.PinotException) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) 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