Search in sources :

Example 41 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class KafkaMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    List<SchemaTableName> tableNames;
    if (prefix.getTable().isEmpty()) {
        tableNames = listTables(session, prefix.getSchema());
    } else {
        tableNames = ImmutableList.of(prefix.toSchemaTableName());
    }
    for (SchemaTableName tableName : tableNames) {
        try {
            columns.put(tableName, getTableMetadata(session, tableName).getColumns());
        } catch (TableNotFoundException e) {
        // information_schema table or a system table
        }
    }
    return columns.buildOrThrow();
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) SchemaTableName(io.trino.spi.connector.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 42 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class MongoSession method getTableMetadata.

// Internal Schema management
private Document getTableMetadata(String schemaName, String tableName) throws TableNotFoundException {
    MongoDatabase db = client.getDatabase(schemaName);
    MongoCollection<Document> schema = db.getCollection(schemaCollection);
    Document doc = schema.find(new Document(TABLE_NAME_KEY, tableName)).first();
    if (doc == null) {
        if (!collectionExists(db, tableName)) {
            throw new TableNotFoundException(new SchemaTableName(schemaName, tableName), format("Table '%s.%s' not found", schemaName, tableName), null);
        } else {
            Document metadata = new Document(TABLE_NAME_KEY, tableName);
            metadata.append(FIELDS_KEY, guessTableFields(schemaName, tableName));
            if (!indexExists(schema)) {
                schema.createIndex(new Document(TABLE_NAME_KEY, 1), new IndexOptions().unique(true));
            }
            schema.insertOne(metadata);
            return metadata;
        }
    }
    return doc;
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) IndexOptions(com.mongodb.client.model.IndexOptions) Document(org.bson.Document) SchemaTableName(io.trino.spi.connector.SchemaTableName) MongoDatabase(com.mongodb.client.MongoDatabase)

Example 43 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class RaptorMetadata method getTableMetadata.

@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
    RaptorTableHandle handle = (RaptorTableHandle) tableHandle;
    SchemaTableName tableName = new SchemaTableName(handle.getSchemaName(), handle.getTableName());
    List<TableColumn> tableColumns = dao.listTableColumns(handle.getTableId());
    if (tableColumns.isEmpty()) {
        throw new TableNotFoundException(tableName);
    }
    ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder();
    SortedMap<Integer, String> bucketing = new TreeMap<>();
    SortedMap<Integer, String> ordering = new TreeMap<>();
    for (TableColumn column : tableColumns) {
        if (column.isTemporal()) {
            properties.put(TEMPORAL_COLUMN_PROPERTY, column.getColumnName());
        }
        column.getBucketOrdinal().ifPresent(bucketOrdinal -> bucketing.put(bucketOrdinal, column.getColumnName()));
        column.getSortOrdinal().ifPresent(sortOrdinal -> ordering.put(sortOrdinal, column.getColumnName()));
    }
    if (!bucketing.isEmpty()) {
        properties.put(BUCKETED_ON_PROPERTY, ImmutableList.copyOf(bucketing.values()));
    }
    if (!ordering.isEmpty()) {
        properties.put(ORDERING_PROPERTY, ImmutableList.copyOf(ordering.values()));
    }
    handle.getBucketCount().ifPresent(bucketCount -> properties.put(BUCKET_COUNT_PROPERTY, bucketCount));
    handle.getDistributionName().ifPresent(distributionName -> properties.put(DISTRIBUTION_NAME_PROPERTY, distributionName));
    // Only display organization property if set
    if (handle.isOrganized()) {
        properties.put(ORGANIZED_PROPERTY, true);
    }
    List<ColumnMetadata> columns = tableColumns.stream().map(TableColumn::toColumnMetadata).collect(toCollection(ArrayList::new));
    columns.add(hiddenColumn(SHARD_UUID_COLUMN_NAME, SHARD_UUID_COLUMN_TYPE));
    if (handle.isBucketed()) {
        columns.add(hiddenColumn(BUCKET_NUMBER_COLUMN_NAME, INTEGER));
    }
    return new ConnectorTableMetadata(tableName, columns, properties.buildOrThrow());
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TreeMap(java.util.TreeMap) SchemaTableName(io.trino.spi.connector.SchemaTableName) TableColumn(io.trino.plugin.raptor.legacy.metadata.TableColumn) ImmutableMap(com.google.common.collect.ImmutableMap) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Example 44 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class PrometheusMetadata method getColumnHandles.

@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
    PrometheusTableHandle prometheusTableHandle = (PrometheusTableHandle) tableHandle;
    PrometheusTable table = prometheusClient.getTable(prometheusTableHandle.getSchemaName(), prometheusTableHandle.getTableName());
    if (table == null) {
        throw new TableNotFoundException(prometheusTableHandle.toSchemaTableName());
    }
    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    int index = 0;
    for (ColumnMetadata column : table.getColumnsMetadata()) {
        columnHandles.put(column.getName(), new PrometheusColumnHandle(column.getName(), column.getType(), index));
        index++;
    }
    return columnHandles.buildOrThrow();
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) ColumnHandle(io.trino.spi.connector.ColumnHandle) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ImmutableMap(com.google.common.collect.ImmutableMap) Constraint(io.trino.spi.connector.Constraint)

Example 45 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class IcebergMetadata method getRawSystemTable.

private Optional<SystemTable> getRawSystemTable(ConnectorSession session, SchemaTableName tableName) {
    IcebergTableName name = IcebergTableName.from(tableName.getTableName());
    if (name.getTableType() == DATA) {
        return Optional.empty();
    }
    // load the base table for the system table
    Table table;
    try {
        table = catalog.loadTable(session, new SchemaTableName(tableName.getSchemaName(), name.getTableName()));
    } catch (TableNotFoundException e) {
        return Optional.empty();
    }
    SchemaTableName systemTableName = new SchemaTableName(tableName.getSchemaName(), name.getTableNameWithType());
    switch(name.getTableType()) {
        case DATA:
            // Handled above.
            break;
        case HISTORY:
            if (name.getSnapshotId().isPresent()) {
                throw new TrinoException(NOT_SUPPORTED, "Snapshot ID not supported for history table: " + systemTableName);
            }
            return Optional.of(new HistoryTable(systemTableName, table));
        case SNAPSHOTS:
            if (name.getSnapshotId().isPresent()) {
                throw new TrinoException(NOT_SUPPORTED, "Snapshot ID not supported for snapshots table: " + systemTableName);
            }
            return Optional.of(new SnapshotsTable(systemTableName, typeManager, table));
        case PARTITIONS:
            return Optional.of(new PartitionTable(systemTableName, typeManager, table, getSnapshotId(table, name.getSnapshotId())));
        case MANIFESTS:
            return Optional.of(new ManifestsTable(systemTableName, table, getSnapshotId(table, name.getSnapshotId())));
        case FILES:
            return Optional.of(new FilesTable(systemTableName, typeManager, table, getSnapshotId(table, name.getSnapshotId())));
        case PROPERTIES:
            return Optional.of(new PropertiesTable(systemTableName, table));
    }
    return Optional.empty();
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Table(org.apache.iceberg.Table) ClassLoaderSafeSystemTable(io.trino.plugin.base.classloader.ClassLoaderSafeSystemTable) SystemTable(io.trino.spi.connector.SystemTable) TrinoException(io.trino.spi.TrinoException) SchemaTableName(io.trino.spi.connector.SchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName)

Aggregations

TableNotFoundException (io.trino.spi.connector.TableNotFoundException)84 SchemaTableName (io.trino.spi.connector.SchemaTableName)65 TrinoException (io.trino.spi.TrinoException)39 Table (io.trino.plugin.hive.metastore.Table)33 ImmutableMap (com.google.common.collect.ImmutableMap)27 ImmutableList (com.google.common.collect.ImmutableList)26 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)26 List (java.util.List)25 Optional (java.util.Optional)24 HdfsContext (io.trino.plugin.hive.HdfsEnvironment.HdfsContext)22 Path (org.apache.hadoop.fs.Path)22 ColumnHandle (io.trino.spi.connector.ColumnHandle)21 Map (java.util.Map)21 Objects.requireNonNull (java.util.Objects.requireNonNull)20 ConnectorSession (io.trino.spi.connector.ConnectorSession)19 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)18 TupleDomain (io.trino.spi.predicate.TupleDomain)18 Set (java.util.Set)18 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)17 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)17