Search in sources :

Example 1 with Session

use of io.trino.tpcds.Session in project trino by trinodb.

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 = getTrinoValue(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) RecordCursor(io.trino.spi.connector.RecordCursor) Session(io.trino.tpcds.Session) ColumnType(io.trino.tpcds.column.ColumnType) TpcdsRecordSet(io.trino.plugin.tpcds.TpcdsRecordSet) Results(io.trino.tpcds.Results) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) String.format(java.lang.String.format) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableList(com.google.common.collect.ImmutableList) Column(io.trino.tpcds.column.Column) Map(java.util.Map) Table(io.trino.tpcds.Table) RecordCursor(io.trino.spi.connector.RecordCursor) TpcdsRecordSet(io.trino.plugin.tpcds.TpcdsRecordSet) Column(io.trino.tpcds.column.Column) Session(io.trino.tpcds.Session)

Example 2 with Session

use of io.trino.tpcds.Session in project trino by trinodb.

the class TpcdsRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transaction, ConnectorSession connectorSession, ConnectorSplit split, ConnectorTableHandle tableHandle, List<? extends ColumnHandle> columns) {
    TpcdsSplit tpcdsSplit = (TpcdsSplit) split;
    TpcdsTableHandle tpcdsTable = (TpcdsTableHandle) tableHandle;
    Table table = getTable(tpcdsTable.getTableName());
    double scaleFactor = tpcdsTable.getScaleFactor();
    int partNumber = tpcdsSplit.getPartNumber();
    int totalParts = tpcdsSplit.getTotalParts();
    boolean noSexism = tpcdsSplit.isNoSexism();
    ImmutableList.Builder<Column> builder = ImmutableList.builder();
    for (ColumnHandle column : columns) {
        String columnName = ((TpcdsColumnHandle) column).getColumnName();
        builder.add(table.getColumn(columnName));
    }
    Session session = Session.getDefaultSession().withScale(scaleFactor).withParallelism(totalParts).withChunkNumber(partNumber + 1).withTable(table).withNoSexism(noSexism);
    Results results = constructResults(table, session);
    return new TpcdsRecordSet(results, builder.build());
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) Table.getTable(io.trino.tpcds.Table.getTable) Table(io.trino.tpcds.Table) ImmutableList(com.google.common.collect.ImmutableList) Column(io.trino.tpcds.column.Column) Results.constructResults(io.trino.tpcds.Results.constructResults) Results(io.trino.tpcds.Results) Session(io.trino.tpcds.Session) ConnectorSession(io.trino.spi.connector.ConnectorSession)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 Results (io.trino.tpcds.Results)2 Session (io.trino.tpcds.Session)2 Table (io.trino.tpcds.Table)2 Column (io.trino.tpcds.column.Column)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 TpcdsRecordSet (io.trino.plugin.tpcds.TpcdsRecordSet)1 ColumnHandle (io.trino.spi.connector.ColumnHandle)1 ConnectorSession (io.trino.spi.connector.ConnectorSession)1 RecordCursor (io.trino.spi.connector.RecordCursor)1 Results.constructResults (io.trino.tpcds.Results.constructResults)1 Table.getTable (io.trino.tpcds.Table.getTable)1 ColumnType (io.trino.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