Search in sources :

Example 1 with EQUAL

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

the class MapDistinctFromOperator method isDistinctFrom.

@TypeParameter("K")
@TypeParameter("V")
@SqlType(StandardTypes.BOOLEAN)
public static boolean isDistinctFrom(@OperatorDependency(operator = EQUAL, argumentTypes = { "K", "K" }) MethodHandle keyEqualsFunction, @OperatorDependency(operator = HASH_CODE, argumentTypes = { "K" }) MethodHandle keyHashcodeFunction, @OperatorDependency(operator = IS_DISTINCT_FROM, argumentTypes = { "V", "V" }, convention = @Convention(arguments = { BLOCK_POSITION, BLOCK_POSITION }, result = FAIL_ON_NULL)) MethodHandle valueDistinctFromFunction, @TypeParameter("map(K, V)") Type mapType, @SqlType("map(K,V)") Block leftMapBlock, @IsNull boolean leftMapNull, @SqlType("map(K,V)") Block rightMapBlock, @IsNull boolean rightMapNull) {
    if (leftMapNull != rightMapNull) {
        return true;
    }
    if (leftMapNull) {
        return false;
    }
    Type keyType = ((MapType) mapType).getKeyType();
    MethodHandle keyBlockEqualsFunction = compose(keyEqualsFunction, nativeValueGetter(keyType));
    MethodHandle keyBlockHashCodeFunction = compose(keyHashcodeFunction, nativeValueGetter(keyType));
    // Note that we compare to NOT distinct here and so negate the result.
    return !MapGenericEquality.genericEqual(keyType, keyHashcodeFunction, keyBlockEqualsFunction, keyBlockHashCodeFunction, leftMapBlock, rightMapBlock, (leftMapIndex, rightMapIndex) -> !(boolean) valueDistinctFromFunction.invokeExact(leftMapBlock, leftMapIndex, rightMapBlock, rightMapIndex));
}
Also used : Convention(com.facebook.presto.spi.function.Convention) HASH_CODE(com.facebook.presto.common.function.OperatorType.HASH_CODE) MethodHandle(java.lang.invoke.MethodHandle) MapType(com.facebook.presto.common.type.MapType) StandardTypes(com.facebook.presto.common.type.StandardTypes) OperatorDependency(com.facebook.presto.spi.function.OperatorDependency) TypeParameter(com.facebook.presto.spi.function.TypeParameter) BLOCK_POSITION(com.facebook.presto.spi.function.InvocationConvention.InvocationArgumentConvention.BLOCK_POSITION) MethodHandleUtil.compose(com.facebook.presto.common.block.MethodHandleUtil.compose) BlockPosition(com.facebook.presto.spi.function.BlockPosition) IS_DISTINCT_FROM(com.facebook.presto.common.function.OperatorType.IS_DISTINCT_FROM) BlockIndex(com.facebook.presto.spi.function.BlockIndex) MethodHandleUtil.nativeValueGetter(com.facebook.presto.common.block.MethodHandleUtil.nativeValueGetter) ScalarOperator(com.facebook.presto.spi.function.ScalarOperator) IsNull(com.facebook.presto.spi.function.IsNull) EQUAL(com.facebook.presto.common.function.OperatorType.EQUAL) FAIL_ON_NULL(com.facebook.presto.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL) Block(com.facebook.presto.common.block.Block) Type(com.facebook.presto.common.type.Type) SqlType(com.facebook.presto.spi.function.SqlType) MapType(com.facebook.presto.common.type.MapType) Type(com.facebook.presto.common.type.Type) SqlType(com.facebook.presto.spi.function.SqlType) MapType(com.facebook.presto.common.type.MapType) MethodHandle(java.lang.invoke.MethodHandle) TypeParameter(com.facebook.presto.spi.function.TypeParameter) SqlType(com.facebook.presto.spi.function.SqlType)

Example 2 with EQUAL

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

the class RowExpressionDomainTranslator method extractDisjuncts.

private List<RowExpression> extractDisjuncts(Type type, DiscreteValues discreteValues, RowExpression reference) {
    List<RowExpression> values = discreteValues.getValues().stream().map(object -> toRowExpression(reference.getSourceLocation(), object, type)).collect(toList());
    // If values is empty, then the equatableValues was either ALL or NONE, both of which should already have been checked for
    checkState(!values.isEmpty());
    RowExpression predicate;
    if (values.size() == 1) {
        predicate = equal(reference, getOnlyElement(values));
    } else {
        predicate = in(reference, values);
    }
    if (!discreteValues.isWhiteList()) {
        predicate = not(functionResolution, predicate);
    }
    return ImmutableList.of(predicate);
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) SATURATED_FLOOR_CAST(com.facebook.presto.metadata.CastType.SATURATED_FLOOR_CAST) IS_NULL(com.facebook.presto.spi.relation.SpecialFormExpression.Form.IS_NULL) DiscreteValues(com.facebook.presto.common.predicate.DiscreteValues) RowExpressionVisitor(com.facebook.presto.spi.relation.RowExpressionVisitor) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) IS_DISTINCT_FROM(com.facebook.presto.common.function.OperatorType.IS_DISTINCT_FROM) SortedRangeSet(com.facebook.presto.common.predicate.SortedRangeSet) StandardFunctionResolution(com.facebook.presto.spi.function.StandardFunctionResolution) PeekingIterator(com.google.common.collect.PeekingIterator) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Map(java.util.Map) EQUAL(com.facebook.presto.common.function.OperatorType.EQUAL) FALSE_CONSTANT(com.facebook.presto.expressions.LogicalRowExpressions.FALSE_CONSTANT) AND(com.facebook.presto.spi.relation.SpecialFormExpression.Form.AND) LESS_THAN(com.facebook.presto.common.function.OperatorType.LESS_THAN) CallExpression(com.facebook.presto.spi.relation.CallExpression) Marker(com.facebook.presto.common.predicate.Marker) SpecialFormExpression(com.facebook.presto.spi.relation.SpecialFormExpression) IN(com.facebook.presto.spi.relation.SpecialFormExpression.Form.IN) RowExpressionInterpreter(com.facebook.presto.sql.planner.RowExpressionInterpreter) NullableValue(com.facebook.presto.common.predicate.NullableValue) InterpretedFunctionInvoker(com.facebook.presto.sql.InterpretedFunctionInvoker) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) DomainTranslator(com.facebook.presto.spi.relation.DomainTranslator) LambdaDefinitionExpression(com.facebook.presto.spi.relation.LambdaDefinitionExpression) LiteralEncoder.toRowExpression(com.facebook.presto.sql.planner.LiteralEncoder.toRowExpression) TRUE_CONSTANT(com.facebook.presto.expressions.LogicalRowExpressions.TRUE_CONSTANT) Range(com.facebook.presto.common.predicate.Range) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ConnectorSession(com.facebook.presto.spi.ConnectorSession) FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) List(java.util.List) OperatorNotFoundException(com.facebook.presto.metadata.OperatorNotFoundException) Optional(java.util.Optional) InputReferenceExpression(com.facebook.presto.spi.relation.InputReferenceExpression) CAST(com.facebook.presto.metadata.CastType.CAST) Ranges(com.facebook.presto.common.predicate.Ranges) DeterminismEvaluator(com.facebook.presto.spi.relation.DeterminismEvaluator) NOT_EQUAL(com.facebook.presto.common.function.OperatorType.NOT_EQUAL) Utils(com.facebook.presto.common.Utils) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) Expressions.call(com.facebook.presto.sql.relational.Expressions.call) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) LESS_THAN_OR_EQUAL(com.facebook.presto.common.function.OperatorType.LESS_THAN_OR_EQUAL) ImmutableList(com.google.common.collect.ImmutableList) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) Objects.requireNonNull(java.util.Objects.requireNonNull) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) Form(com.facebook.presto.spi.relation.SpecialFormExpression.Form) OR(com.facebook.presto.spi.relation.SpecialFormExpression.Form.OR) Iterators.peekingIterator(com.google.common.collect.Iterators.peekingIterator) Type(com.facebook.presto.common.type.Type) Nullable(javax.annotation.Nullable) RowExpression(com.facebook.presto.spi.relation.RowExpression) LogicalRowExpressions.and(com.facebook.presto.expressions.LogicalRowExpressions.and) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) OperatorType(com.facebook.presto.common.function.OperatorType) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) GREATER_THAN_OR_EQUAL(com.facebook.presto.common.function.OperatorType.GREATER_THAN_OR_EQUAL) GREATER_THAN(com.facebook.presto.common.function.OperatorType.GREATER_THAN) OPTIMIZED(com.facebook.presto.spi.relation.ExpressionOptimizer.Level.OPTIMIZED) Collectors.toList(java.util.stream.Collectors.toList) BETWEEN(com.facebook.presto.common.function.OperatorType.BETWEEN) LogicalRowExpressions.or(com.facebook.presto.expressions.LogicalRowExpressions.or) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Block(com.facebook.presto.common.block.Block) ValueSet(com.facebook.presto.common.predicate.ValueSet) Metadata(com.facebook.presto.metadata.Metadata) LiteralEncoder.toRowExpression(com.facebook.presto.sql.planner.LiteralEncoder.toRowExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression)

Aggregations

Block (com.facebook.presto.common.block.Block)2 EQUAL (com.facebook.presto.common.function.OperatorType.EQUAL)2 IS_DISTINCT_FROM (com.facebook.presto.common.function.OperatorType.IS_DISTINCT_FROM)2 Type (com.facebook.presto.common.type.Type)2 Utils (com.facebook.presto.common.Utils)1 MethodHandleUtil.compose (com.facebook.presto.common.block.MethodHandleUtil.compose)1 MethodHandleUtil.nativeValueGetter (com.facebook.presto.common.block.MethodHandleUtil.nativeValueGetter)1 OperatorType (com.facebook.presto.common.function.OperatorType)1 BETWEEN (com.facebook.presto.common.function.OperatorType.BETWEEN)1 GREATER_THAN (com.facebook.presto.common.function.OperatorType.GREATER_THAN)1 GREATER_THAN_OR_EQUAL (com.facebook.presto.common.function.OperatorType.GREATER_THAN_OR_EQUAL)1 HASH_CODE (com.facebook.presto.common.function.OperatorType.HASH_CODE)1 LESS_THAN (com.facebook.presto.common.function.OperatorType.LESS_THAN)1 LESS_THAN_OR_EQUAL (com.facebook.presto.common.function.OperatorType.LESS_THAN_OR_EQUAL)1 NOT_EQUAL (com.facebook.presto.common.function.OperatorType.NOT_EQUAL)1 DiscreteValues (com.facebook.presto.common.predicate.DiscreteValues)1 Domain (com.facebook.presto.common.predicate.Domain)1 Marker (com.facebook.presto.common.predicate.Marker)1 NullableValue (com.facebook.presto.common.predicate.NullableValue)1 Range (com.facebook.presto.common.predicate.Range)1