Search in sources :

Example 16 with FunctionMetadata

use of com.facebook.presto.spi.function.FunctionMetadata in project presto by prestodb.

the class JdbcFilterToSqlTranslator method translateCall.

@Override
public TranslatedExpression<JdbcExpression> translateCall(CallExpression call, Map<VariableReferenceExpression, ColumnHandle> context, RowExpressionTreeTranslator<JdbcExpression, Map<VariableReferenceExpression, ColumnHandle>> rowExpressionTreeTranslator) {
    List<TranslatedExpression<JdbcExpression>> translatedExpressions = call.getArguments().stream().map(expression -> rowExpressionTreeTranslator.rewrite(expression, context)).collect(toImmutableList());
    FunctionMetadata functionMetadata = functionMetadataManager.getFunctionMetadata(call.getFunctionHandle());
    try {
        return functionTranslator.translate(functionMetadata, call, translatedExpressions);
    } catch (Throwable t) {
    // no-op
    }
    return untranslated(call, translatedExpressions);
}
Also used : TranslatedExpression.untranslated(com.facebook.presto.expressions.translator.TranslatedExpression.untranslated) BooleanType(com.facebook.presto.common.type.BooleanType) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) TranslatedExpression(com.facebook.presto.expressions.translator.TranslatedExpression) IntegerType(com.facebook.presto.common.type.IntegerType) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) TimeWithTimeZoneType(com.facebook.presto.common.type.TimeWithTimeZoneType) CharType(com.facebook.presto.common.type.CharType) CallExpression(com.facebook.presto.spi.relation.CallExpression) RowExpressionTreeTranslator(com.facebook.presto.expressions.translator.RowExpressionTreeTranslator) FunctionMetadataManager(com.facebook.presto.spi.function.FunctionMetadataManager) Type(com.facebook.presto.common.type.Type) SpecialFormExpression(com.facebook.presto.spi.relation.SpecialFormExpression) RowExpressionTranslator(com.facebook.presto.expressions.translator.RowExpressionTranslator) TinyintType(com.facebook.presto.common.type.TinyintType) BigintType(com.facebook.presto.common.type.BigintType) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) LambdaDefinitionExpression(com.facebook.presto.spi.relation.LambdaDefinitionExpression) VarcharType(com.facebook.presto.common.type.VarcharType) RealType(com.facebook.presto.common.type.RealType) String.format(java.lang.String.format) TimeType(com.facebook.presto.common.type.TimeType) TimestampWithTimeZoneType(com.facebook.presto.common.type.TimestampWithTimeZoneType) FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) SmallintType(com.facebook.presto.common.type.SmallintType) List(java.util.List) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Optional(java.util.Optional) DateType(com.facebook.presto.common.type.DateType) FunctionTranslator(com.facebook.presto.expressions.translator.FunctionTranslator) DoubleType(com.facebook.presto.common.type.DoubleType) TimestampType(com.facebook.presto.common.type.TimestampType) JdbcColumnHandle(com.facebook.presto.plugin.jdbc.JdbcColumnHandle) Joiner(com.google.common.base.Joiner) FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) TranslatedExpression(com.facebook.presto.expressions.translator.TranslatedExpression)

Example 17 with FunctionMetadata

use of com.facebook.presto.spi.function.FunctionMetadata 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 18 with FunctionMetadata

use of com.facebook.presto.spi.function.FunctionMetadata in project presto by prestodb.

the class SpatialJoinUtils method isSupportedSpatialComparison.

private static boolean isSupportedSpatialComparison(CallExpression expression, FunctionAndTypeManager functionAndTypeManager) {
    FunctionMetadata metadata = functionAndTypeManager.getFunctionMetadata(expression.getFunctionHandle());
    checkArgument(metadata.getOperatorType().isPresent() && metadata.getOperatorType().get().isComparisonOperator());
    switch(metadata.getOperatorType().get()) {
        case LESS_THAN:
        case LESS_THAN_OR_EQUAL:
            return isSTDistance(expression.getArguments().get(0), functionAndTypeManager);
        case GREATER_THAN:
        case GREATER_THAN_OR_EQUAL:
            return isSTDistance(expression.getArguments().get(1), functionAndTypeManager);
        default:
            return false;
    }
}
Also used : FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata)

Example 19 with FunctionMetadata

use of com.facebook.presto.spi.function.FunctionMetadata 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

FunctionMetadata (com.facebook.presto.spi.function.FunctionMetadata)19 OperatorType (com.facebook.presto.common.function.OperatorType)9 TypeSignature (com.facebook.presto.common.type.TypeSignature)4 PrestoException (com.facebook.presto.spi.PrestoException)4 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)4 CallExpression (com.facebook.presto.spi.relation.CallExpression)4 ImmutableList (com.google.common.collect.ImmutableList)4 Type (com.facebook.presto.common.type.Type)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 List (java.util.List)3 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 SqlInvokedFunction (com.facebook.presto.spi.function.SqlInvokedFunction)2 RowExpression (com.facebook.presto.spi.relation.RowExpression)2 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 String.format (java.lang.String.format)2 MethodHandle (java.lang.invoke.MethodHandle)2 Map (java.util.Map)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2