Search in sources :

Example 6 with ColumnStats

use of com.facebook.presto.raptor.metadata.ColumnStats in project presto by prestodb.

the class TestShardOrganizerUtil method getShardIndexInfo.

private static List<ShardIndexInfo> getShardIndexInfo(Table tableInfo, List<ShardInfo> shards, TableColumn temporalColumn, Optional<List<TableColumn>> sortColumns) {
    long tableId = tableInfo.getTableId();
    Type temporalType = temporalColumn.getDataType();
    ImmutableList.Builder<ShardIndexInfo> builder = ImmutableList.builder();
    for (ShardInfo shard : shards) {
        ColumnStats temporalColumnStats = shard.getColumnStats().stream().filter(columnStats -> columnStats.getColumnId() == temporalColumn.getColumnId()).findFirst().get();
        if (temporalColumnStats.getMin() == null || temporalColumnStats.getMax() == null) {
            continue;
        }
        Optional<ShardRange> sortRange = Optional.empty();
        if (sortColumns.isPresent()) {
            Map<Long, ColumnStats> columnIdToStats = Maps.uniqueIndex(shard.getColumnStats(), ColumnStats::getColumnId);
            ImmutableList.Builder<Type> typesBuilder = ImmutableList.builder();
            ImmutableList.Builder<Object> minBuilder = ImmutableList.builder();
            ImmutableList.Builder<Object> maxBuilder = ImmutableList.builder();
            boolean isShardEligible = true;
            for (TableColumn sortColumn : sortColumns.get()) {
                ColumnStats columnStats = columnIdToStats.get(sortColumn.getColumnId());
                typesBuilder.add(sortColumn.getDataType());
                if (columnStats.getMin() == null || columnStats.getMax() == null) {
                    isShardEligible = false;
                    break;
                }
                minBuilder.add(columnStats.getMin());
                maxBuilder.add(columnStats.getMax());
            }
            if (!isShardEligible) {
                continue;
            }
            List<Type> types = typesBuilder.build();
            List<Object> minValues = minBuilder.build();
            List<Object> maxValues = maxBuilder.build();
            sortRange = Optional.of(ShardRange.of(new Tuple(types, minValues), new Tuple(types, maxValues)));
        }
        builder.add(new ShardIndexInfo(tableId, OptionalInt.empty(), shard.getShardUuid(), shard.getRowCount(), shard.getUncompressedSize(), sortRange, Optional.of(ShardRange.of(new Tuple(temporalType, temporalColumnStats.getMin()), new Tuple(temporalType, temporalColumnStats.getMax())))));
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TableColumn(com.facebook.presto.raptor.metadata.TableColumn) Type(com.facebook.presto.spi.type.Type) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) ColumnStats(com.facebook.presto.raptor.metadata.ColumnStats) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo)

Example 7 with ColumnStats

use of com.facebook.presto.raptor.metadata.ColumnStats in project presto by prestodb.

the class TestOrcStorageManager method assertColumnStats.

private static void assertColumnStats(List<ColumnStats> list, long columnId, Object min, Object max) {
    for (ColumnStats stats : list) {
        if (stats.getColumnId() == columnId) {
            assertEquals(stats.getMin(), min);
            assertEquals(stats.getMax(), max);
            return;
        }
    }
    fail(format("no stats for column: %s: %s", columnId, list));
}
Also used : ColumnStats(com.facebook.presto.raptor.metadata.ColumnStats)

Example 8 with ColumnStats

use of com.facebook.presto.raptor.metadata.ColumnStats in project presto by prestodb.

the class OrcStorageManager method computeShardStats.

private List<ColumnStats> computeShardStats(File file) {
    try (OrcDataSource dataSource = fileOrcDataSource(defaultReaderAttributes, file)) {
        OrcReader reader = new OrcReader(dataSource, new OrcMetadataReader(), defaultReaderAttributes.getMaxMergeDistance(), defaultReaderAttributes.getMaxReadSize());
        ImmutableList.Builder<ColumnStats> list = ImmutableList.builder();
        for (ColumnInfo info : getColumnInfo(reader)) {
            computeColumnStats(reader, info.getColumnId(), info.getType()).ifPresent(list::add);
        }
        return list.build();
    } catch (IOException e) {
        throw new PrestoException(RAPTOR_ERROR, "Failed to read file: " + file, e);
    }
}
Also used : FileOrcDataSource(com.facebook.presto.orc.FileOrcDataSource) OrcDataSource(com.facebook.presto.orc.OrcDataSource) OrcReader(com.facebook.presto.orc.OrcReader) ImmutableList(com.google.common.collect.ImmutableList) ColumnStats(com.facebook.presto.raptor.metadata.ColumnStats) ShardStats.computeColumnStats(com.facebook.presto.raptor.storage.ShardStats.computeColumnStats) OrcMetadataReader(com.facebook.presto.orc.metadata.OrcMetadataReader) ColumnInfo(com.facebook.presto.raptor.metadata.ColumnInfo) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException)

Aggregations

ColumnStats (com.facebook.presto.raptor.metadata.ColumnStats)8 Block (com.facebook.presto.spi.block.Block)4 ShardInfo (com.facebook.presto.raptor.metadata.ShardInfo)2 TableColumn (com.facebook.presto.raptor.metadata.TableColumn)2 ImmutableList (com.google.common.collect.ImmutableList)2 FileOrcDataSource (com.facebook.presto.orc.FileOrcDataSource)1 OrcDataSource (com.facebook.presto.orc.OrcDataSource)1 OrcReader (com.facebook.presto.orc.OrcReader)1 OrcMetadataReader (com.facebook.presto.orc.metadata.OrcMetadataReader)1 ColumnInfo (com.facebook.presto.raptor.metadata.ColumnInfo)1 ShardMetadata (com.facebook.presto.raptor.metadata.ShardMetadata)1 Table (com.facebook.presto.raptor.metadata.Table)1 ShardStats.computeColumnStats (com.facebook.presto.raptor.storage.ShardStats.computeColumnStats)1 PrestoException (com.facebook.presto.spi.PrestoException)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 Type (com.facebook.presto.spi.type.Type)1 VarcharType.createVarcharType (com.facebook.presto.spi.type.VarcharType.createVarcharType)1 Slice (io.airlift.slice.Slice)1 IOException (java.io.IOException)1 Test (org.testng.annotations.Test)1