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)));
});
}
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());
}
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()));
}
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);
}
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()));
}
Aggregations