use of io.prestosql.spi.connector.ConnectorSession in project hetu-core by openlookeng.
the class MetadataManager method schemaExists.
@Override
public boolean schemaExists(Session session, CatalogSchemaName schema) {
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, schema.getCatalogName());
if (!catalog.isPresent()) {
return false;
}
CatalogMetadata catalogMetadata = catalog.get();
ConnectorSession connectorSession = session.toConnectorSession(catalogMetadata.getCatalogName());
return catalogMetadata.listConnectorIds().stream().map(catalogMetadata::getMetadataFor).anyMatch(metadata -> metadata.schemaExists(connectorSession, schema.getSchemaName()));
}
use of io.prestosql.spi.connector.ConnectorSession in project hetu-core by openlookeng.
the class MetadataManager method getViews.
@Override
public Map<QualifiedObjectName, ConnectorViewDefinition> getViews(Session session, QualifiedTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
Map<QualifiedObjectName, ConnectorViewDefinition> views = new LinkedHashMap<>();
if (catalog.isPresent()) {
CatalogMetadata catalogMetadata = catalog.get();
SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
for (CatalogName catalogName : catalogMetadata.listConnectorIds()) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(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, entry.getValue());
}
}
}
return ImmutableMap.copyOf(views);
}
use of io.prestosql.spi.connector.ConnectorSession in project hetu-core by openlookeng.
the class MetadataManager method listSchemaNames.
@Override
public List<String> listSchemaNames(Session session, String catalogName) {
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, catalogName);
ImmutableSet.Builder<String> schemaNames = ImmutableSet.builder();
if (catalog.isPresent()) {
CatalogMetadata catalogMetadata = catalog.get();
ConnectorSession connectorSession = session.toConnectorSession(catalogMetadata.getCatalogName());
for (CatalogName connectorId : catalogMetadata.listConnectorIds()) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
metadata.listSchemaNames(connectorSession).stream().map(schema -> schema.toLowerCase(Locale.ENGLISH)).forEach(schemaNames::add);
}
}
return ImmutableList.copyOf(schemaNames.build());
}
use of io.prestosql.spi.connector.ConnectorSession in project hetu-core by openlookeng.
the class MetadataManager method listTablePrivileges.
@Override
public List<GrantInfo> listTablePrivileges(Session session, QualifiedTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
ImmutableSet.Builder<GrantInfo> grantInfos = ImmutableSet.builder();
if (catalog.isPresent()) {
CatalogMetadata catalogMetadata = catalog.get();
ConnectorSession connectorSession = session.toConnectorSession(catalogMetadata.getCatalogName());
List<CatalogName> connectorIds = prefix.asQualifiedObjectName().map(qualifiedTableName -> singletonList(catalogMetadata.getConnectorId(session, qualifiedTableName))).orElseGet(catalogMetadata::listConnectorIds);
for (CatalogName catalogName : connectorIds) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(catalogName);
grantInfos.addAll(metadata.listTablePrivileges(connectorSession, prefix.asSchemaTablePrefix()));
}
}
return ImmutableList.copyOf(grantInfos.build());
}
use of io.prestosql.spi.connector.ConnectorSession in project hetu-core by openlookeng.
the class MetadataManager method executeDelete.
@Override
public OptionalLong executeDelete(Session session, TableHandle table) {
CatalogName catalogName = table.getCatalogName();
ConnectorMetadata metadata = getMetadataForWrite(session, catalogName);
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
if (metadata.usesLegacyTableLayouts()) {
checkArgument(table.getLayout().isPresent(), "table layout is missing");
return metadata.metadataDelete(session.toConnectorSession(catalogName), table.getConnectorHandle(), table.getLayout().get());
}
checkArgument(!table.getLayout().isPresent(), "table layout should not be present");
return metadata.executeDelete(connectorSession, table.getConnectorHandle());
}
Aggregations