use of com.teradata.tpcds.column.Column in project presto by prestodb.
the class TpcdsMetadata method getTableMetadata.
private static ConnectorTableMetadata getTableMetadata(String schemaName, Table tpcdsTable) {
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
for (Column column : tpcdsTable.getColumns()) {
columns.add(new ColumnMetadata(column.getName(), getPrestoType(column.getType())));
}
SchemaTableName tableName = new SchemaTableName(schemaName, tpcdsTable.getName());
return new ConnectorTableMetadata(tableName, columns.build());
}
use of com.teradata.tpcds.column.Column 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());
}
use of com.teradata.tpcds.column.Column 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);
}
use of com.teradata.tpcds.column.Column in project presto by prestodb.
the class TableStatisticsRecorder method getPrestoValue.
private Comparable<?> getPrestoValue(RecordCursor recordCursor, List<Column> columns, int columnId) {
if (recordCursor.isNull(columnId)) {
return null;
}
Column column = columns.get(columnId);
ColumnType.Base baseType = column.getType().getBase();
switch(baseType) {
case IDENTIFIER:
case INTEGER:
case DATE:
case TIME:
case DECIMAL:
return recordCursor.getLong(columnId);
case VARCHAR:
case CHAR:
return recordCursor.getSlice(columnId).toStringAscii();
}
throw new UnsupportedOperationException(format("Unsupported TPCDS base type [%s]", baseType));
}
Aggregations