Search in sources :

Example 1 with FloatRange

use of com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange in project presto by prestodb.

the class TupleDomainFilterUtils method toFilter.

public static TupleDomainFilter toFilter(Domain domain) {
    ValueSet values = domain.getValues();
    boolean nullAllowed = domain.isNullAllowed();
    if (values.isAll()) {
        checkArgument(!nullAllowed, "Unexpected allways-true filter");
        return IS_NOT_NULL;
    }
    if (values.isNone()) {
        checkArgument(nullAllowed, "Unexpected allways-false filter");
        return IS_NULL;
    }
    checkArgument(values instanceof SortedRangeSet, "Unexpected domain type: " + values.getClass().getSimpleName());
    List<Range> ranges = ((SortedRangeSet) values).getOrderedRanges();
    if (ranges.isEmpty() && nullAllowed) {
        return IS_NULL;
    }
    Type type = domain.getType();
    if (ranges.size() == 1) {
        return createRangeFilter(type, ranges.get(0), nullAllowed);
    }
    if (type == BOOLEAN) {
        return createBooleanFilter(ranges, nullAllowed);
    }
    List<TupleDomainFilter> rangeFilters = ranges.stream().map(range -> createRangeFilter(type, range, false)).filter(rangeFilter -> !rangeFilter.equals(ALWAYS_FALSE)).collect(toList());
    if (rangeFilters.isEmpty()) {
        return nullAllowed ? IS_NULL : ALWAYS_FALSE;
    }
    TupleDomainFilter firstRangeFilter = rangeFilters.get(0);
    if (firstRangeFilter instanceof BigintRange) {
        List<BigintRange> bigintRanges = rangeFilters.stream().map(BigintRange.class::cast).collect(toList());
        if (bigintRanges.stream().allMatch(BigintRange::isSingleValue)) {
            return toBigintValues(bigintRanges.stream().mapToLong(BigintRange::getLower).toArray(), nullAllowed);
        }
        return BigintMultiRange.of(bigintRanges, nullAllowed);
    }
    if (firstRangeFilter instanceof BytesRange) {
        List<BytesRange> bytesRanges = rangeFilters.stream().map(BytesRange.class::cast).collect(toList());
        if (bytesRanges.stream().allMatch(BytesRange::isSingleValue)) {
            return BytesValues.of(bytesRanges.stream().map(BytesRange::getLower).toArray(byte[][]::new), nullAllowed);
        }
        if (isNotIn(ranges)) {
            return BytesValuesExclusive.of(bytesRanges.stream().map(BytesRange::getLower).filter(Objects::nonNull).toArray(byte[][]::new), nullAllowed);
        }
    }
    if (firstRangeFilter instanceof DoubleRange || firstRangeFilter instanceof FloatRange) {
        // != and NOT IN filters should return true when applied to NaN
        // E.g. NaN != 1.0 as well as NaN NOT IN (1.0, 2.5, 3.6) should return true; otherwise false.
        boolean nanAllowed = isNotIn(ranges);
        return MultiRange.of(rangeFilters, nullAllowed, nanAllowed);
    }
    return MultiRange.of(rangeFilters, nullAllowed, false);
}
Also used : DecimalType(com.facebook.presto.common.type.DecimalType) Slice(io.airlift.slice.Slice) LongDecimalRange(com.facebook.presto.common.predicate.TupleDomainFilter.LongDecimalRange) TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) Float.intBitsToFloat(java.lang.Float.intBitsToFloat) DATE(com.facebook.presto.common.type.DateType.DATE) REAL(com.facebook.presto.common.type.RealType.REAL) BytesRange(com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange) FloatRange(com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) Varchars.isVarcharType(com.facebook.presto.common.type.Varchars.isVarcharType) CharType(com.facebook.presto.common.type.CharType) BigInteger(java.math.BigInteger) Math.toIntExact(java.lang.Math.toIntExact) Type(com.facebook.presto.common.type.Type) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) BigintValuesUsingHashTable(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingHashTable) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) BigintMultiRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintMultiRange) ALWAYS_FALSE(com.facebook.presto.common.predicate.TupleDomainFilter.ALWAYS_FALSE) BooleanValue(com.facebook.presto.common.predicate.TupleDomainFilter.BooleanValue) BigintValuesUsingBitmask(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingBitmask) Objects(java.util.Objects) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) IS_NOT_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) SIZE_OF_LONG(io.airlift.slice.SizeOf.SIZE_OF_LONG) MultiRange(com.facebook.presto.common.predicate.TupleDomainFilter.MultiRange) IS_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL) BytesValues(com.facebook.presto.common.predicate.TupleDomainFilter.BytesValues) DoubleRange(com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange) BytesValuesExclusive(com.facebook.presto.common.predicate.TupleDomainFilter.BytesValuesExclusive) BytesRange(com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) LongDecimalRange(com.facebook.presto.common.predicate.TupleDomainFilter.LongDecimalRange) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) BytesRange(com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange) FloatRange(com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange) BigintMultiRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintMultiRange) MultiRange(com.facebook.presto.common.predicate.TupleDomainFilter.MultiRange) DoubleRange(com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange) DoubleRange(com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange) DecimalType(com.facebook.presto.common.type.DecimalType) Varchars.isVarcharType(com.facebook.presto.common.type.Varchars.isVarcharType) CharType(com.facebook.presto.common.type.CharType) Type(com.facebook.presto.common.type.Type) FloatRange(com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange) Objects(java.util.Objects)

Aggregations

ALWAYS_FALSE (com.facebook.presto.common.predicate.TupleDomainFilter.ALWAYS_FALSE)1 BigintMultiRange (com.facebook.presto.common.predicate.TupleDomainFilter.BigintMultiRange)1 BigintRange (com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange)1 BigintValuesUsingBitmask (com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingBitmask)1 BigintValuesUsingHashTable (com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingHashTable)1 BooleanValue (com.facebook.presto.common.predicate.TupleDomainFilter.BooleanValue)1 BytesRange (com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange)1 BytesValues (com.facebook.presto.common.predicate.TupleDomainFilter.BytesValues)1 BytesValuesExclusive (com.facebook.presto.common.predicate.TupleDomainFilter.BytesValuesExclusive)1 DoubleRange (com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange)1 FloatRange (com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange)1 IS_NOT_NULL (com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL)1 IS_NULL (com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL)1 LongDecimalRange (com.facebook.presto.common.predicate.TupleDomainFilter.LongDecimalRange)1 MultiRange (com.facebook.presto.common.predicate.TupleDomainFilter.MultiRange)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 BOOLEAN (com.facebook.presto.common.type.BooleanType.BOOLEAN)1 CharType (com.facebook.presto.common.type.CharType)1 DATE (com.facebook.presto.common.type.DateType.DATE)1 DecimalType (com.facebook.presto.common.type.DecimalType)1