use of io.trino.spi.connector.FixedPageSource in project trino by trinodb.
the class ColumnRangesSystemTable method pageSource.
@Override
public ConnectorPageSource pageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
String metadataSqlQuery = getColumnRangesMetadataSqlQuery(sourceTable, indexedRaptorColumns);
List<Type> columnTypes = tableMetadata.getColumns().stream().map(ColumnMetadata::getType).collect(toImmutableList());
PageListBuilder pageListBuilder = new PageListBuilder(columnTypes);
try (Connection connection = dbi.open().getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(metadataSqlQuery)) {
if (resultSet.next()) {
pageListBuilder.beginRow();
for (int i = 0; i < columnTypes.size(); ++i) {
BlockBuilder blockBuilder = pageListBuilder.nextBlockBuilder();
Type columnType = columnTypes.get(i);
if (columnType.equals(BIGINT) || columnType.equals(DATE)) {
long value = resultSet.getLong(i + 1);
if (!resultSet.wasNull()) {
columnType.writeLong(blockBuilder, value);
} else {
blockBuilder.appendNull();
}
} else if (columnType.equals(TIMESTAMP_MILLIS)) {
long value = resultSet.getLong(i + 1);
if (!resultSet.wasNull()) {
columnType.writeLong(blockBuilder, value * MICROSECONDS_PER_MILLISECOND);
} else {
blockBuilder.appendNull();
}
} else if (columnType.equals(BOOLEAN)) {
boolean value = resultSet.getBoolean(i + 1);
if (!resultSet.wasNull()) {
BOOLEAN.writeBoolean(blockBuilder, value);
} else {
blockBuilder.appendNull();
}
} else {
throw new VerifyException("Unknown or unsupported column type: " + columnType);
}
}
}
} catch (SQLException | JdbiException e) {
throw metadataError(e);
}
return new FixedPageSource(pageListBuilder.build());
}
Aggregations