Search in sources :

Example 1 with DecimalStatistics

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

the class IcebergOrcFileWriter method toIcebergMinMax.

private static Optional<IcebergMinMax> toIcebergMinMax(ColumnStatistics orcColumnStats, org.apache.iceberg.types.Type icebergType) {
    IntegerStatistics integerStatistics = orcColumnStats.getIntegerStatistics();
    if (integerStatistics != null) {
        Object min = integerStatistics.getMin();
        Object max = integerStatistics.getMax();
        if (min == null || max == null) {
            return Optional.empty();
        }
        if (icebergType.typeId() == org.apache.iceberg.types.Type.TypeID.INTEGER) {
            min = toIntExact((Long) min);
            max = toIntExact((Long) max);
        }
        return Optional.of(new IcebergMinMax(icebergType, min, max));
    }
    DoubleStatistics doubleStatistics = orcColumnStats.getDoubleStatistics();
    if (doubleStatistics != null) {
        Object min = doubleStatistics.getMin();
        Object max = doubleStatistics.getMax();
        if (min == null || max == null) {
            return Optional.empty();
        }
        if (icebergType.typeId() == org.apache.iceberg.types.Type.TypeID.FLOAT) {
            min = ((Double) min).floatValue();
            max = ((Double) max).floatValue();
        }
        return Optional.of(new IcebergMinMax(icebergType, min, max));
    }
    StringStatistics stringStatistics = orcColumnStats.getStringStatistics();
    if (stringStatistics != null) {
        Slice min = stringStatistics.getMin();
        Slice max = stringStatistics.getMax();
        if (min == null || max == null) {
            return Optional.empty();
        }
        return Optional.of(new IcebergMinMax(icebergType, min.toStringUtf8(), max.toStringUtf8()));
    }
    DateStatistics dateStatistics = orcColumnStats.getDateStatistics();
    if (dateStatistics != null) {
        Integer min = dateStatistics.getMin();
        Integer max = dateStatistics.getMax();
        if (min == null || max == null) {
            return Optional.empty();
        }
        return Optional.of(new IcebergMinMax(icebergType, min, max));
    }
    DecimalStatistics decimalStatistics = orcColumnStats.getDecimalStatistics();
    if (decimalStatistics != null) {
        BigDecimal min = decimalStatistics.getMin();
        BigDecimal max = decimalStatistics.getMax();
        if (min == null || max == null) {
            return Optional.empty();
        }
        min = min.setScale(((DecimalType) icebergType).scale());
        max = max.setScale(((DecimalType) icebergType).scale());
        return Optional.of(new IcebergMinMax(icebergType, min, max));
    }
    return Optional.empty();
}
Also used : StringStatistics(com.facebook.presto.orc.metadata.statistics.StringStatistics) DecimalStatistics(com.facebook.presto.orc.metadata.statistics.DecimalStatistics) DoubleStatistics(com.facebook.presto.orc.metadata.statistics.DoubleStatistics) Slice(io.airlift.slice.Slice) DateStatistics(com.facebook.presto.orc.metadata.statistics.DateStatistics) DecimalType(org.apache.iceberg.types.Types.DecimalType) BigDecimal(java.math.BigDecimal) IntegerStatistics(com.facebook.presto.orc.metadata.statistics.IntegerStatistics)

Example 2 with DecimalStatistics

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

the class TestTupleDomainOrcPredicate method decimalColumnStats.

private static ColumnStatistics decimalColumnStats(Long numberOfValues, String minimum, String maximum) {
    BigDecimal minimumDecimal = minimum == null ? null : new BigDecimal(minimum);
    BigDecimal maximumDecimal = maximum == null ? null : new BigDecimal(maximum);
    return new DecimalColumnStatistics(numberOfValues, null, new DecimalStatistics(minimumDecimal, maximumDecimal, SHORT_DECIMAL_VALUE_BYTES));
}
Also used : DecimalStatistics(com.facebook.presto.orc.metadata.statistics.DecimalStatistics) DecimalColumnStatistics(com.facebook.presto.orc.metadata.statistics.DecimalColumnStatistics) BigDecimal(java.math.BigDecimal)

Example 3 with DecimalStatistics

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

the class OrcMetadataReader method toDecimalStatistics.

private static DecimalStatistics toDecimalStatistics(OrcProto.DecimalStatistics decimalStatistics) {
    BigDecimal minimum = decimalStatistics.hasMinimum() ? new BigDecimal(decimalStatistics.getMinimum()) : null;
    BigDecimal maximum = decimalStatistics.hasMaximum() ? new BigDecimal(decimalStatistics.getMaximum()) : null;
    // could be long (16 bytes) or short (8 bytes); use short for estimation
    return new DecimalStatistics(minimum, maximum, SHORT_DECIMAL_VALUE_BYTES);
}
Also used : DecimalStatistics(com.facebook.presto.orc.metadata.statistics.DecimalStatistics) BigDecimal(java.math.BigDecimal)

Aggregations

DecimalStatistics (com.facebook.presto.orc.metadata.statistics.DecimalStatistics)3 BigDecimal (java.math.BigDecimal)3 DateStatistics (com.facebook.presto.orc.metadata.statistics.DateStatistics)1 DecimalColumnStatistics (com.facebook.presto.orc.metadata.statistics.DecimalColumnStatistics)1 DoubleStatistics (com.facebook.presto.orc.metadata.statistics.DoubleStatistics)1 IntegerStatistics (com.facebook.presto.orc.metadata.statistics.IntegerStatistics)1 StringStatistics (com.facebook.presto.orc.metadata.statistics.StringStatistics)1 Slice (io.airlift.slice.Slice)1 DecimalType (org.apache.iceberg.types.Types.DecimalType)1