Search in sources :

Example 1 with BooleanStatistics

use of io.prestosql.orc.metadata.statistics.BooleanStatistics in project hetu-core by openlookeng.

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 : Varchars.isVarcharType(io.prestosql.spi.type.Varchars.isVarcharType) Slice(io.airlift.slice.Slice) StandardTypes(io.prestosql.spi.type.StandardTypes) ValueSet(io.prestosql.spi.predicate.ValueSet) DecimalType(io.prestosql.spi.type.DecimalType) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) OrcColumnId(io.prestosql.orc.metadata.OrcColumnId) Float.intBitsToFloat(java.lang.Float.intBitsToFloat) Function(java.util.function.Function) Decimals.rescale(io.prestosql.spi.type.Decimals.rescale) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Float.floatToRawIntBits(java.lang.Float.floatToRawIntBits) ImmutableList(com.google.common.collect.ImmutableList) Range(io.prestosql.spi.predicate.Range) BooleanStatistics(io.prestosql.orc.metadata.statistics.BooleanStatistics) Objects.requireNonNull(java.util.Objects.requireNonNull) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Type(io.prestosql.spi.type.Type) DATE(io.prestosql.spi.type.DateType.DATE) REAL(io.prestosql.spi.type.RealType.REAL) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Chars.isCharType(io.prestosql.spi.type.Chars.isCharType) Collection(java.util.Collection) Set(java.util.Set) VarbinaryType(io.prestosql.spi.type.VarbinaryType) Decimals.encodeUnscaledValue(io.prestosql.spi.type.Decimals.encodeUnscaledValue) Decimals.isLongDecimal(io.prestosql.spi.type.Decimals.isLongDecimal) TIMESTAMP(io.prestosql.spi.type.TimestampType.TIMESTAMP) TINYINT(io.prestosql.spi.type.TinyintType.TINYINT) ColumnMetadata(io.prestosql.orc.metadata.ColumnMetadata) Objects(java.util.Objects) Decimals.isShortDecimal(io.prestosql.spi.type.Decimals.isShortDecimal) List(java.util.List) SMALLINT(io.prestosql.spi.type.SmallintType.SMALLINT) Domain(io.prestosql.spi.predicate.Domain) ColumnStatistics(io.prestosql.orc.metadata.statistics.ColumnStatistics) RangeStatistics(io.prestosql.orc.metadata.statistics.RangeStatistics) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Chars.truncateToLengthAndTrimSpaces(io.prestosql.spi.type.Chars.truncateToLengthAndTrimSpaces) VarcharType(io.prestosql.spi.type.VarcharType) HashableBloomFilter(io.prestosql.orc.metadata.statistics.HashableBloomFilter) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) BooleanStatistics(io.prestosql.orc.metadata.statistics.BooleanStatistics) DecimalType(io.prestosql.spi.type.DecimalType) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 ImmutableList (com.google.common.collect.ImmutableList)1 Slice (io.airlift.slice.Slice)1 ColumnMetadata (io.prestosql.orc.metadata.ColumnMetadata)1 OrcColumnId (io.prestosql.orc.metadata.OrcColumnId)1 BooleanStatistics (io.prestosql.orc.metadata.statistics.BooleanStatistics)1 ColumnStatistics (io.prestosql.orc.metadata.statistics.ColumnStatistics)1 HashableBloomFilter (io.prestosql.orc.metadata.statistics.HashableBloomFilter)1 RangeStatistics (io.prestosql.orc.metadata.statistics.RangeStatistics)1 Domain (io.prestosql.spi.predicate.Domain)1 Range (io.prestosql.spi.predicate.Range)1 ValueSet (io.prestosql.spi.predicate.ValueSet)1 BIGINT (io.prestosql.spi.type.BigintType.BIGINT)1 BOOLEAN (io.prestosql.spi.type.BooleanType.BOOLEAN)1 Chars.isCharType (io.prestosql.spi.type.Chars.isCharType)1 Chars.truncateToLengthAndTrimSpaces (io.prestosql.spi.type.Chars.truncateToLengthAndTrimSpaces)1 DATE (io.prestosql.spi.type.DateType.DATE)1 DecimalType (io.prestosql.spi.type.DecimalType)1 Decimals.encodeUnscaledValue (io.prestosql.spi.type.Decimals.encodeUnscaledValue)1