Search in sources :

Example 1 with DoubleColumnStatsData

use of alluxio.grpc.table.DoubleColumnStatsData in project presto by prestodb.

the class AlluxioProtoUtils method fromProto.

public static HiveColumnStatistics fromProto(ColumnStatisticsData columnStatistics, OptionalLong rowCount) {
    if (columnStatistics.hasLongStats()) {
        LongColumnStatsData longStatsData = columnStatistics.getLongStats();
        OptionalLong min = longStatsData.hasLowValue() ? OptionalLong.of(longStatsData.getLowValue()) : OptionalLong.empty();
        OptionalLong max = longStatsData.hasHighValue() ? OptionalLong.of(longStatsData.getHighValue()) : OptionalLong.empty();
        OptionalLong nullsCount = longStatsData.hasNumNulls() ? fromMetastoreNullsCount(longStatsData.getNumNulls()) : OptionalLong.empty();
        OptionalLong distinctValuesCount = longStatsData.hasNumDistincts() ? OptionalLong.of(longStatsData.getNumDistincts()) : OptionalLong.empty();
        return createIntegerColumnStatistics(min, max, nullsCount, fromMetastoreDistinctValuesCount(distinctValuesCount, nullsCount, rowCount));
    }
    if (columnStatistics.hasDoubleStats()) {
        DoubleColumnStatsData doubleStatsData = columnStatistics.getDoubleStats();
        OptionalDouble min = doubleStatsData.hasLowValue() ? OptionalDouble.of(doubleStatsData.getLowValue()) : OptionalDouble.empty();
        OptionalDouble max = doubleStatsData.hasHighValue() ? OptionalDouble.of(doubleStatsData.getHighValue()) : OptionalDouble.empty();
        OptionalLong nullsCount = doubleStatsData.hasNumNulls() ? fromMetastoreNullsCount(doubleStatsData.getNumNulls()) : OptionalLong.empty();
        OptionalLong distinctValuesCount = doubleStatsData.hasNumDistincts() ? OptionalLong.of(doubleStatsData.getNumDistincts()) : OptionalLong.empty();
        return createDoubleColumnStatistics(min, max, nullsCount, fromMetastoreDistinctValuesCount(distinctValuesCount, nullsCount, rowCount));
    }
    if (columnStatistics.hasDecimalStats()) {
        DecimalColumnStatsData decimalStatsData = columnStatistics.getDecimalStats();
        Optional<BigDecimal> min = decimalStatsData.hasLowValue() ? fromMetastoreDecimal(decimalStatsData.getLowValue()) : Optional.empty();
        Optional<BigDecimal> max = decimalStatsData.hasHighValue() ? fromMetastoreDecimal(decimalStatsData.getHighValue()) : Optional.empty();
        OptionalLong nullsCount = decimalStatsData.hasNumNulls() ? fromMetastoreNullsCount(decimalStatsData.getNumNulls()) : OptionalLong.empty();
        OptionalLong distinctValuesCount = decimalStatsData.hasNumDistincts() ? OptionalLong.of(decimalStatsData.getNumDistincts()) : OptionalLong.empty();
        return createDecimalColumnStatistics(min, max, nullsCount, fromMetastoreDistinctValuesCount(distinctValuesCount, nullsCount, rowCount));
    }
    if (columnStatistics.hasDateStats()) {
        DateColumnStatsData dateStatsData = columnStatistics.getDateStats();
        Optional<LocalDate> min = dateStatsData.hasLowValue() ? fromMetastoreDate(dateStatsData.getLowValue()) : Optional.empty();
        Optional<LocalDate> max = dateStatsData.hasHighValue() ? fromMetastoreDate(dateStatsData.getHighValue()) : Optional.empty();
        OptionalLong nullsCount = dateStatsData.hasNumNulls() ? fromMetastoreNullsCount(dateStatsData.getNumNulls()) : OptionalLong.empty();
        OptionalLong distinctValuesCount = dateStatsData.hasNumDistincts() ? OptionalLong.of(dateStatsData.getNumDistincts()) : OptionalLong.empty();
        return createDateColumnStatistics(min, max, nullsCount, fromMetastoreDistinctValuesCount(distinctValuesCount, nullsCount, rowCount));
    }
    if (columnStatistics.hasBooleanStats()) {
        BooleanColumnStatsData booleanStatsData = columnStatistics.getBooleanStats();
        OptionalLong trueCount = OptionalLong.empty();
        OptionalLong falseCount = OptionalLong.empty();
        if (booleanStatsData.hasNumTrues() && booleanStatsData.hasNumFalses() && (booleanStatsData.getNumFalses() != -1)) {
            trueCount = OptionalLong.of(booleanStatsData.getNumTrues());
            falseCount = OptionalLong.of(booleanStatsData.getNumFalses());
        }
        return createBooleanColumnStatistics(trueCount, falseCount, booleanStatsData.hasNumNulls() ? fromMetastoreNullsCount(booleanStatsData.getNumNulls()) : OptionalLong.empty());
    }
    if (columnStatistics.hasStringStats()) {
        StringColumnStatsData stringStatsData = columnStatistics.getStringStats();
        OptionalLong maxColumnLength = stringStatsData.hasMaxColLen() ? OptionalLong.of(stringStatsData.getMaxColLen()) : OptionalLong.empty();
        OptionalDouble averageColumnLength = stringStatsData.hasAvgColLen() ? OptionalDouble.of(stringStatsData.getAvgColLen()) : OptionalDouble.empty();
        OptionalLong nullsCount = stringStatsData.hasNumNulls() ? fromMetastoreNullsCount(stringStatsData.getNumNulls()) : OptionalLong.empty();
        OptionalLong distinctValuesCount = stringStatsData.hasNumDistincts() ? OptionalLong.of(stringStatsData.getNumDistincts()) : OptionalLong.empty();
        return createStringColumnStatistics(maxColumnLength, getTotalSizeInBytes(averageColumnLength, rowCount, nullsCount), nullsCount, fromMetastoreDistinctValuesCount(distinctValuesCount, nullsCount, rowCount));
    }
    if (columnStatistics.hasBinaryStats()) {
        BinaryColumnStatsData binaryStatsData = columnStatistics.getBinaryStats();
        OptionalLong maxColumnLength = binaryStatsData.hasMaxColLen() ? OptionalLong.of(binaryStatsData.getMaxColLen()) : OptionalLong.empty();
        OptionalDouble averageColumnLength = binaryStatsData.hasAvgColLen() ? OptionalDouble.of(binaryStatsData.getAvgColLen()) : OptionalDouble.empty();
        OptionalLong nullsCount = binaryStatsData.hasNumNulls() ? fromMetastoreNullsCount(binaryStatsData.getNumNulls()) : OptionalLong.empty();
        return createBinaryColumnStatistics(maxColumnLength, getTotalSizeInBytes(averageColumnLength, rowCount, nullsCount), nullsCount);
    }
    throw new PrestoException(HIVE_INVALID_METADATA, "Invalid column statistics data: " + columnStatistics);
}
Also used : BooleanColumnStatsData(alluxio.grpc.table.BooleanColumnStatsData) DateColumnStatsData(alluxio.grpc.table.DateColumnStatsData) StringColumnStatsData(alluxio.grpc.table.StringColumnStatsData) PrestoException(com.facebook.presto.spi.PrestoException) LongColumnStatsData(alluxio.grpc.table.LongColumnStatsData) LocalDate(java.time.LocalDate) OptionalDouble(java.util.OptionalDouble) BigDecimal(java.math.BigDecimal) BinaryColumnStatsData(alluxio.grpc.table.BinaryColumnStatsData) DoubleColumnStatsData(alluxio.grpc.table.DoubleColumnStatsData) DecimalColumnStatsData(alluxio.grpc.table.DecimalColumnStatsData) OptionalLong(java.util.OptionalLong)

Aggregations

BinaryColumnStatsData (alluxio.grpc.table.BinaryColumnStatsData)1 BooleanColumnStatsData (alluxio.grpc.table.BooleanColumnStatsData)1 DateColumnStatsData (alluxio.grpc.table.DateColumnStatsData)1 DecimalColumnStatsData (alluxio.grpc.table.DecimalColumnStatsData)1 DoubleColumnStatsData (alluxio.grpc.table.DoubleColumnStatsData)1 LongColumnStatsData (alluxio.grpc.table.LongColumnStatsData)1 StringColumnStatsData (alluxio.grpc.table.StringColumnStatsData)1 PrestoException (com.facebook.presto.spi.PrestoException)1 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 OptionalDouble (java.util.OptionalDouble)1 OptionalLong (java.util.OptionalLong)1