use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.
the class MetadataManager method getViews.
@Override
public Map<QualifiedObjectName, ViewInfo> getViews(Session session, QualifiedTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
Map<QualifiedObjectName, ViewInfo> views = new LinkedHashMap<>();
if (catalog.isPresent()) {
CatalogMetadata catalogMetadata = catalog.get();
SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
for (CatalogName catalogName : catalogMetadata.listConnectorIds()) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
Map<SchemaTableName, ConnectorViewDefinition> viewMap;
if (tablePrefix.getTable().isPresent()) {
viewMap = metadata.getView(connectorSession, tablePrefix.toSchemaTableName()).map(view -> ImmutableMap.of(tablePrefix.toSchemaTableName(), view)).orElse(ImmutableMap.of());
} else {
viewMap = metadata.getViews(connectorSession, tablePrefix.getSchema());
}
for (Entry<SchemaTableName, ConnectorViewDefinition> entry : viewMap.entrySet()) {
QualifiedObjectName viewName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
views.put(viewName, new ViewInfo(entry.getValue()));
}
}
}
return ImmutableMap.copyOf(views);
}
use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.
the class MetadataManager method listRoles.
@Override
public Set<String> listRoles(Session session, Optional<String> catalog) {
if (catalog.isPresent()) {
Optional<CatalogMetadata> catalogMetadata = getOptionalCatalogMetadata(session, catalog.get());
if (catalogMetadata.isEmpty()) {
return ImmutableSet.of();
}
// instead of returning nothing, so information schema role tables will work properly
if (catalogMetadata.get().getSecurityManagement() == SecurityManagement.CONNECTOR) {
CatalogName catalogName = catalogMetadata.get().getCatalogName();
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
ConnectorMetadata metadata = catalogMetadata.get().getMetadataFor(session, catalogName);
return metadata.listRoles(connectorSession).stream().map(role -> role.toLowerCase(ENGLISH)).collect(toImmutableSet());
}
}
return systemSecurityMetadata.listRoles(session);
}
use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.
the class MetadataManager method applyLimit.
@Override
public Optional<LimitApplicationResult<TableHandle>> applyLimit(Session session, TableHandle table, long limit) {
CatalogName catalogName = table.getCatalogName();
ConnectorMetadata metadata = getMetadata(session, catalogName);
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
return metadata.applyLimit(connectorSession, table.getConnectorHandle(), limit).map(result -> new LimitApplicationResult<>(new TableHandle(catalogName, result.getHandle(), table.getTransaction()), result.isLimitGuaranteed(), result.isPrecalculateStatistics()));
}
use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.
the class MetadataManager method applyFilter.
@Override
public Optional<ConstraintApplicationResult<TableHandle>> applyFilter(Session session, TableHandle table, Constraint constraint) {
CatalogName catalogName = table.getCatalogName();
ConnectorMetadata metadata = getMetadata(session, catalogName);
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
return metadata.applyFilter(connectorSession, table.getConnectorHandle(), constraint).map(result -> result.transform(handle -> new TableHandle(catalogName, handle, table.getTransaction())));
}
use of io.trino.spi.connector.ConnectorSession 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)));
});
}
Aggregations