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);
}
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());
}
Aggregations