Search in sources :

Example 1 with BooleanStatistics

use of com.facebook.presto.orc.metadata.statistics.BooleanStatistics in project presto by prestodb.

the class TupleDomainOrcPredicate method getDomain.

@VisibleForTesting
public static Domain getDomain(Type type, long rowCount, ColumnStatistics columnStatistics) {
    if (rowCount == 0) {
        return Domain.none(type);
    }
    if (columnStatistics == null) {
        return Domain.all(type);
    }
    if (columnStatistics.hasNumberOfValues() && columnStatistics.getNumberOfValues() == 0) {
        return Domain.onlyNull(type);
    }
    boolean hasNullValue = columnStatistics.getNumberOfValues() != rowCount;
    if (type.getJavaType() == boolean.class && columnStatistics.getBooleanStatistics() != null) {
        BooleanStatistics booleanStatistics = columnStatistics.getBooleanStatistics();
        boolean hasTrueValues = (booleanStatistics.getTrueValueCount() != 0);
        boolean hasFalseValues = (columnStatistics.getNumberOfValues() != booleanStatistics.getTrueValueCount());
        if (hasTrueValues && hasFalseValues) {
            return Domain.all(BOOLEAN);
        }
        if (hasTrueValues) {
            return Domain.create(ValueSet.of(BOOLEAN, true), hasNullValue);
        }
        if (hasFalseValues) {
            return Domain.create(ValueSet.of(BOOLEAN, false), hasNullValue);
        }
    } else if (isShortDecimal(type) && columnStatistics.getDecimalStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getDecimalStatistics(), value -> rescale(value, (DecimalType) type).unscaledValue().longValue());
    } else if (isLongDecimal(type) && columnStatistics.getDecimalStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getDecimalStatistics(), value -> encodeUnscaledValue(rescale(value, (DecimalType) type).unscaledValue()));
    } else if (isCharType(type) && columnStatistics.getStringStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getStringStatistics(), value -> truncateToLengthAndTrimSpaces(value, type));
    } else if (isVarcharType(type) && columnStatistics.getStringStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getStringStatistics());
    } else if (type.getTypeSignature().getBase().equals(StandardTypes.DATE) && columnStatistics.getDateStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getDateStatistics(), value -> (long) value);
    } else if (type.getJavaType() == long.class && columnStatistics.getIntegerStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getIntegerStatistics());
    } else if (type.getJavaType() == double.class && columnStatistics.getDoubleStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getDoubleStatistics());
    } else if (REAL.equals(type) && columnStatistics.getDoubleStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getDoubleStatistics(), value -> (long) floatToRawIntBits(value.floatValue()));
    }
    return Domain.create(ValueSet.all(type), hasNullValue);
}
Also used : StandardTypes(com.facebook.presto.common.type.StandardTypes) DecimalType(com.facebook.presto.common.type.DecimalType) Slice(io.airlift.slice.Slice) Chars.isCharType(com.facebook.presto.common.type.Chars.isCharType) Decimals.encodeUnscaledValue(com.facebook.presto.common.type.Decimals.encodeUnscaledValue) TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) Function(java.util.function.Function) REAL(com.facebook.presto.common.type.RealType.REAL) Float.floatToRawIntBits(java.lang.Float.floatToRawIntBits) Chars.truncateToLengthAndTrimSpaces(com.facebook.presto.common.type.Chars.truncateToLengthAndTrimSpaces) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) HiveBloomFilter(com.facebook.presto.orc.metadata.statistics.HiveBloomFilter) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) Varchars.isVarcharType(com.facebook.presto.common.type.Varchars.isVarcharType) Type(com.facebook.presto.common.type.Type) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Collection(java.util.Collection) VarcharType(com.facebook.presto.common.type.VarcharType) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Decimals.isLongDecimal(com.facebook.presto.common.type.Decimals.isLongDecimal) Range(com.facebook.presto.common.predicate.Range) ColumnStatistics(com.facebook.presto.orc.metadata.statistics.ColumnStatistics) List(java.util.List) Decimals.isShortDecimal(com.facebook.presto.common.type.Decimals.isShortDecimal) BooleanStatistics(com.facebook.presto.orc.metadata.statistics.BooleanStatistics) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) Decimals.rescale(com.facebook.presto.common.type.Decimals.rescale) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) VarbinaryType(com.facebook.presto.common.type.VarbinaryType) Optional(java.util.Optional) BloomFilter(com.facebook.presto.orc.metadata.statistics.BloomFilter) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ValueSet(com.facebook.presto.common.predicate.ValueSet) RangeStatistics(com.facebook.presto.orc.metadata.statistics.RangeStatistics) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) BooleanStatistics(com.facebook.presto.orc.metadata.statistics.BooleanStatistics) DecimalType(com.facebook.presto.common.type.DecimalType) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Domain (com.facebook.presto.common.predicate.Domain)1 Range (com.facebook.presto.common.predicate.Range)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 ValueSet (com.facebook.presto.common.predicate.ValueSet)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 BOOLEAN (com.facebook.presto.common.type.BooleanType.BOOLEAN)1 Chars.isCharType (com.facebook.presto.common.type.Chars.isCharType)1 Chars.truncateToLengthAndTrimSpaces (com.facebook.presto.common.type.Chars.truncateToLengthAndTrimSpaces)1 DecimalType (com.facebook.presto.common.type.DecimalType)1 Decimals.encodeUnscaledValue (com.facebook.presto.common.type.Decimals.encodeUnscaledValue)1 Decimals.isLongDecimal (com.facebook.presto.common.type.Decimals.isLongDecimal)1 Decimals.isShortDecimal (com.facebook.presto.common.type.Decimals.isShortDecimal)1 Decimals.rescale (com.facebook.presto.common.type.Decimals.rescale)1 DOUBLE (com.facebook.presto.common.type.DoubleType.DOUBLE)1 INTEGER (com.facebook.presto.common.type.IntegerType.INTEGER)1 REAL (com.facebook.presto.common.type.RealType.REAL)1 SMALLINT (com.facebook.presto.common.type.SmallintType.SMALLINT)1 StandardTypes (com.facebook.presto.common.type.StandardTypes)1 TINYINT (com.facebook.presto.common.type.TinyintType.TINYINT)1 Type (com.facebook.presto.common.type.Type)1