Search in sources :

Example 1 with ColumnMetadataRow

use of io.trino.plugin.raptor.legacy.metadata.ColumnMetadataRow in project trino by trinodb.

the class TableMetadataSystemTable method buildPages.

private static List<Page> buildPages(MetadataDao dao, ConnectorTableMetadata tableMetadata, TupleDomain<Integer> tupleDomain) {
    Map<Integer, NullableValue> domainValues = extractFixedValues(tupleDomain).orElse(ImmutableMap.of());
    String schemaName = getStringValue(domainValues.get(getColumnIndex(tableMetadata, SCHEMA_NAME)));
    String tableName = getStringValue(domainValues.get(getColumnIndex(tableMetadata, TABLE_NAME)));
    PageListBuilder pageBuilder = new PageListBuilder(tableMetadata.getColumns().stream().map(ColumnMetadata::getType).collect(toList()));
    List<TableMetadataRow> tableRows = dao.getTableMetadataRows(schemaName, tableName);
    PeekingIterator<ColumnMetadataRow> columnRowIterator = peekingIterator(dao.getColumnMetadataRows(schemaName, tableName).iterator());
    for (TableMetadataRow tableRow : tableRows) {
        while (columnRowIterator.hasNext() && columnRowIterator.peek().getTableId() < tableRow.getTableId()) {
            columnRowIterator.next();
        }
        String temporalColumnName = null;
        SortedMap<Integer, String> sortColumnNames = new TreeMap<>();
        SortedMap<Integer, String> bucketColumnNames = new TreeMap<>();
        OptionalLong temporalColumnId = tableRow.getTemporalColumnId();
        while (columnRowIterator.hasNext() && columnRowIterator.peek().getTableId() == tableRow.getTableId()) {
            ColumnMetadataRow columnRow = columnRowIterator.next();
            if (temporalColumnId.isPresent() && columnRow.getColumnId() == temporalColumnId.getAsLong()) {
                temporalColumnName = columnRow.getColumnName();
            }
            OptionalInt sortOrdinalPosition = columnRow.getSortOrdinalPosition();
            if (sortOrdinalPosition.isPresent()) {
                sortColumnNames.put(sortOrdinalPosition.getAsInt(), columnRow.getColumnName());
            }
            OptionalInt bucketOrdinalPosition = columnRow.getBucketOrdinalPosition();
            if (bucketOrdinalPosition.isPresent()) {
                bucketColumnNames.put(bucketOrdinalPosition.getAsInt(), columnRow.getColumnName());
            }
        }
        pageBuilder.beginRow();
        // schema_name, table_name
        VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(tableRow.getSchemaName()));
        VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(tableRow.getTableName()));
        // temporal_column
        if (temporalColumnId.isPresent()) {
            if (temporalColumnName == null) {
                throw new TrinoException(RAPTOR_CORRUPT_METADATA, format("Table ID %s has corrupt metadata (invalid temporal column ID)", tableRow.getTableId()));
            }
            VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(temporalColumnName));
        } else {
            pageBuilder.nextBlockBuilder().appendNull();
        }
        // ordering_columns
        writeArray(pageBuilder.nextBlockBuilder(), sortColumnNames.values());
        // distribution_name
        Optional<String> distributionName = tableRow.getDistributionName();
        if (distributionName.isPresent()) {
            VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(distributionName.get()));
        } else {
            pageBuilder.nextBlockBuilder().appendNull();
        }
        // bucket_count
        OptionalInt bucketCount = tableRow.getBucketCount();
        if (bucketCount.isPresent()) {
            BIGINT.writeLong(pageBuilder.nextBlockBuilder(), bucketCount.getAsInt());
        } else {
            pageBuilder.nextBlockBuilder().appendNull();
        }
        // bucketing_columns
        writeArray(pageBuilder.nextBlockBuilder(), bucketColumnNames.values());
        // organized
        BOOLEAN.writeBoolean(pageBuilder.nextBlockBuilder(), tableRow.isOrganized());
    }
    return pageBuilder.build();
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) NullableValue(io.trino.spi.predicate.NullableValue) ColumnMetadataRow(io.trino.plugin.raptor.legacy.metadata.ColumnMetadataRow) OptionalInt(java.util.OptionalInt) TreeMap(java.util.TreeMap) OptionalLong(java.util.OptionalLong) TrinoException(io.trino.spi.TrinoException) TableMetadataRow(io.trino.plugin.raptor.legacy.metadata.TableMetadataRow)

Aggregations

ColumnMetadataRow (io.trino.plugin.raptor.legacy.metadata.ColumnMetadataRow)1 TableMetadataRow (io.trino.plugin.raptor.legacy.metadata.TableMetadataRow)1 TrinoException (io.trino.spi.TrinoException)1 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)1 NullableValue (io.trino.spi.predicate.NullableValue)1 OptionalInt (java.util.OptionalInt)1 OptionalLong (java.util.OptionalLong)1 TreeMap (java.util.TreeMap)1