Search in sources :

Example 11 with CatalogName

use of io.trino.connector.CatalogName in project trino by trinodb.

the class MetadataManager method getTableHandle.

@Override
public Optional<TableHandle> getTableHandle(Session session, QualifiedObjectName table, Optional<TableVersion> startVersion, Optional<TableVersion> endVersion) {
    requireNonNull(table, "table is null");
    if (table.getCatalogName().isEmpty() || table.getSchemaName().isEmpty() || table.getObjectName().isEmpty()) {
        // Table cannot exist
        return Optional.empty();
    }
    return getOptionalCatalogMetadata(session, table.getCatalogName()).flatMap(catalogMetadata -> {
        CatalogName catalogName = catalogMetadata.getConnectorId(session, table);
        ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
        ConnectorSession connectorSession = session.toConnectorSession(catalogName);
        // GetTableHandle with the optional version handle field will throw an error if it is not implemented, so only try calling it when we have a version
        if (startVersion.isPresent() || endVersion.isPresent()) {
            ConnectorTableHandle versionedTableHandle = metadata.getTableHandle(connectorSession, table.asSchemaTableName(), toConnectorVersion(startVersion), toConnectorVersion(endVersion));
            return Optional.ofNullable(versionedTableHandle).map(connectorTableHandle -> new TableHandle(catalogName, connectorTableHandle, catalogMetadata.getTransactionHandleFor(catalogName)));
        }
        return Optional.ofNullable(metadata.getTableHandle(connectorSession, table.asSchemaTableName())).map(connectorTableHandle -> new TableHandle(catalogName, connectorTableHandle, catalogMetadata.getTransactionHandleFor(catalogName)));
    });
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) ConnectorInsertTableHandle(io.trino.spi.connector.ConnectorInsertTableHandle) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle)

Example 12 with CatalogName

use of io.trino.connector.CatalogName in project trino by trinodb.

the class MetadataManager method validateScan.

@Override
public void validateScan(Session session, TableHandle table) {
    CatalogName catalogName = table.getCatalogName();
    ConnectorMetadata metadata = getMetadata(session, catalogName);
    metadata.validateScan(session.toConnectorSession(catalogName), table.getConnectorHandle());
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 13 with CatalogName

use of io.trino.connector.CatalogName in project trino by trinodb.

the class MetadataManager method applyDelete.

@Override
public Optional<TableHandle> applyDelete(Session session, TableHandle table) {
    CatalogName catalogName = table.getCatalogName();
    ConnectorMetadata metadata = getMetadata(session, catalogName);
    ConnectorSession connectorSession = session.toConnectorSession(catalogName);
    return metadata.applyDelete(connectorSession, table.getConnectorHandle()).map(newHandle -> new TableHandle(catalogName, newHandle, table.getTransaction()));
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) ConnectorInsertTableHandle(io.trino.spi.connector.ConnectorInsertTableHandle) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 14 with CatalogName

use of io.trino.connector.CatalogName in project trino by trinodb.

the class MetadataManager method listTables.

@Override
public List<QualifiedObjectName> listTables(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<QualifiedObjectName> objectName = prefix.asQualifiedObjectName();
    if (objectName.isPresent()) {
        Optional<Boolean> exists = isExistingRelationForListing(session, objectName.get());
        if (exists.isPresent()) {
            return exists.get() ? ImmutableList.of(objectName.get()) : ImmutableList.of();
        }
    }
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Set<QualifiedObjectName> tables = new LinkedHashSet<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        for (CatalogName catalogName : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
            ConnectorSession connectorSession = session.toConnectorSession(catalogName);
            metadata.listTables(connectorSession, prefix.getSchemaName()).stream().map(convertFromSchemaTableName(prefix.getCatalogName())).filter(prefix::matches).forEach(tables::add);
        }
    }
    return ImmutableList.copyOf(tables);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 15 with CatalogName

use of io.trino.connector.CatalogName in project trino by trinodb.

the class MetadataManager method beginTableExecute.

@Override
public BeginTableExecuteResult<TableExecuteHandle, TableHandle> beginTableExecute(Session session, TableExecuteHandle tableExecuteHandle, TableHandle sourceHandle) {
    CatalogName catalogName = tableExecuteHandle.getCatalogName();
    CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName);
    ConnectorMetadata metadata = catalogMetadata.getMetadata(session);
    BeginTableExecuteResult<ConnectorTableExecuteHandle, ConnectorTableHandle> connectorBeginResult = metadata.beginTableExecute(session.toConnectorSession(), tableExecuteHandle.getConnectorHandle(), sourceHandle.getConnectorHandle());
    return new BeginTableExecuteResult<>(tableExecuteHandle.withConnectorHandle(connectorBeginResult.getTableExecuteHandle()), sourceHandle.withConnectorHandle(connectorBeginResult.getSourceHandle()));
}
Also used : ConnectorTableExecuteHandle(io.trino.spi.connector.ConnectorTableExecuteHandle) CatalogName(io.trino.connector.CatalogName) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) BeginTableExecuteResult(io.trino.spi.connector.BeginTableExecuteResult) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle)

Aggregations

CatalogName (io.trino.connector.CatalogName)175 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)102 ConnectorSession (io.trino.spi.connector.ConnectorSession)40 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)26 Optional (java.util.Optional)25 ImmutableList (com.google.common.collect.ImmutableList)24 Session (io.trino.Session)23 TrinoException (io.trino.spi.TrinoException)23 Type (io.trino.spi.type.Type)23 Test (org.testng.annotations.Test)23 ImmutableMap (com.google.common.collect.ImmutableMap)21 ConnectorInsertTableHandle (io.trino.spi.connector.ConnectorInsertTableHandle)21 List (java.util.List)21 ConnectorOutputTableHandle (io.trino.spi.connector.ConnectorOutputTableHandle)20 TableHandle (io.trino.metadata.TableHandle)18 Map (java.util.Map)17 ImmutableSet (com.google.common.collect.ImmutableSet)16 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)16 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)16 Objects.requireNonNull (java.util.Objects.requireNonNull)16