Search in sources :

Example 1 with Session

use of com.teradata.tpcds.Session in project presto by prestodb.

the class TpcdsRecordSetProvider method getRecordSet.

private RecordSet getRecordSet(Table table, List<? extends ColumnHandle> columns, double scaleFactor, int partNumber, int totalParts, boolean noSexism) {
    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(com.facebook.presto.spi.ColumnHandle) Column(com.teradata.tpcds.column.Column) Results(com.teradata.tpcds.Results) Results.constructResults(com.teradata.tpcds.Results.constructResults) ImmutableList(com.google.common.collect.ImmutableList) Session(com.teradata.tpcds.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession)

Example 2 with Session

use of com.teradata.tpcds.Session 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

ImmutableList (com.google.common.collect.ImmutableList)2 Results (com.teradata.tpcds.Results)2 Session (com.teradata.tpcds.Session)2 Column (com.teradata.tpcds.column.Column)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ConnectorSession (com.facebook.presto.spi.ConnectorSession)1 RecordCursor (com.facebook.presto.spi.RecordCursor)1 TpcdsRecordSet (com.facebook.presto.tpcds.TpcdsRecordSet)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 Results.constructResults (com.teradata.tpcds.Results.constructResults)1 Table (com.teradata.tpcds.Table)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