Search in sources :

Example 1 with TpcdsRecordSet

use of com.facebook.presto.tpcds.TpcdsRecordSet in project presto by prestodb.

the class TableStatisticsRecorder method recordStatistics.

public TableStatisticsData recordStatistics(Table table, double scaleFactor) {
    Session session = Session.getDefaultSession().withScale(scaleFactor).withParallelism(1).withNoSexism(false);
    List<Column> columns = ImmutableList.copyOf(table.getColumns());
    RecordCursor recordCursor = new TpcdsRecordSet(Results.constructResults(table, session), columns).cursor();
    List<ColumnStatisticsRecorder> statisticsRecorders = createStatisticsRecorders(columns);
    long rowCount = 0;
    while (recordCursor.advanceNextPosition()) {
        rowCount++;
        for (int columnId = 0; columnId < columns.size(); columnId++) {
            Comparable<?> value = getPrestoValue(recordCursor, columns, columnId);
            statisticsRecorders.get(columnId).record(value);
        }
    }
    Map<String, ColumnStatisticsData> columnSampleStatistics = IntStream.range(0, columns.size()).boxed().collect(toImmutableMap(i -> columns.get(i).getName(), i -> statisticsRecorders.get(i).getRecording()));
    return new TableStatisticsData(rowCount, columnSampleStatistics);
}
Also used : IntStream(java.util.stream.IntStream) Session(com.teradata.tpcds.Session) TpcdsRecordSet(com.facebook.presto.tpcds.TpcdsRecordSet) Results(com.teradata.tpcds.Results) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) String.format(java.lang.String.format) RecordCursor(com.facebook.presto.spi.RecordCursor) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableList(com.google.common.collect.ImmutableList) Column(com.teradata.tpcds.column.Column) Map(java.util.Map) ColumnType(com.teradata.tpcds.column.ColumnType) Table(com.teradata.tpcds.Table) RecordCursor(com.facebook.presto.spi.RecordCursor) TpcdsRecordSet(com.facebook.presto.tpcds.TpcdsRecordSet) Column(com.teradata.tpcds.column.Column) Session(com.teradata.tpcds.Session)

Aggregations

RecordCursor (com.facebook.presto.spi.RecordCursor)1 TpcdsRecordSet (com.facebook.presto.tpcds.TpcdsRecordSet)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 Results (com.teradata.tpcds.Results)1 Session (com.teradata.tpcds.Session)1 Table (com.teradata.tpcds.Table)1 Column (com.teradata.tpcds.column.Column)1 ColumnType (com.teradata.tpcds.column.ColumnType)1 String.format (java.lang.String.format)1 List (java.util.List)1 Map (java.util.Map)1 IntStream (java.util.stream.IntStream)1