Search in sources :

Example 26 with NullableValue

use of com.facebook.presto.common.predicate.NullableValue in project presto by prestodb.

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 PrestoException(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());
        // delta delete enabled
        BOOLEAN.writeBoolean(pageBuilder.nextBlockBuilder(), tableRow.isTableSupportsDeltaDelete());
    }
    return pageBuilder.build();
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) NullableValue(com.facebook.presto.common.predicate.NullableValue) PrestoException(com.facebook.presto.spi.PrestoException) ColumnMetadataRow(com.facebook.presto.raptor.metadata.ColumnMetadataRow) OptionalInt(java.util.OptionalInt) TreeMap(java.util.TreeMap) OptionalLong(java.util.OptionalLong) TableMetadataRow(com.facebook.presto.raptor.metadata.TableMetadataRow)

Aggregations

NullableValue (com.facebook.presto.common.predicate.NullableValue)26 ColumnHandle (com.facebook.presto.spi.ColumnHandle)17 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)12 ConnectorSession (com.facebook.presto.spi.ConnectorSession)12 ImmutableList (com.google.common.collect.ImmutableList)9 Map (java.util.Map)9 SchemaTableName (com.facebook.presto.spi.SchemaTableName)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Optional (java.util.Optional)8 Set (java.util.Set)8 Domain (com.facebook.presto.common.predicate.Domain)7 Type (com.facebook.presto.common.type.Type)7 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)7 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)7 Constraint (com.facebook.presto.spi.Constraint)7 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 List (java.util.List)7 Objects.requireNonNull (java.util.Objects.requireNonNull)7 PrestoException (com.facebook.presto.spi.PrestoException)6 ImmutableSet (com.google.common.collect.ImmutableSet)6