use of com.facebook.presto.metadata.Catalog in project presto by prestodb.
the class TestAnalyzer method createTestingCatalog.
private Catalog createTestingCatalog(String catalogName, ConnectorId connectorId) {
ConnectorId systemId = createSystemTablesConnectorId(connectorId);
Connector connector = createTestingConnector();
InternalNodeManager nodeManager = new InMemoryNodeManager();
return new Catalog(catalogName, connectorId, connector, createInformationSchemaConnectorId(connectorId), new InformationSchemaConnector(catalogName, nodeManager, metadata, accessControl), systemId, new SystemConnector(systemId, nodeManager, connector.getSystemTables(), transactionId -> transactionManager.getConnectorTransaction(transactionId, connectorId)));
}
use of com.facebook.presto.metadata.Catalog in project presto by prestodb.
the class TestAccessControlManager method registerBogusConnector.
private static ConnectorId registerBogusConnector(CatalogManager catalogManager, TransactionManager transactionManager, AccessControl accessControl, String catalogName) {
ConnectorId connectorId = new ConnectorId(catalogName);
Connector connector = new TpchConnectorFactory().create(catalogName, ImmutableMap.of(), new TestingConnectorContext());
InMemoryNodeManager nodeManager = new InMemoryNodeManager();
MetadataManager metadata = MetadataManager.createTestMetadataManager(catalogManager);
ConnectorId systemId = createSystemTablesConnectorId(connectorId);
catalogManager.registerCatalog(new Catalog(catalogName, connectorId, connector, createInformationSchemaConnectorId(connectorId), new InformationSchemaConnector(catalogName, nodeManager, metadata, accessControl, ImmutableList.of()), systemId, new SystemConnector(systemId, nodeManager, connector.getSystemTables(), transactionId -> transactionManager.getConnectorTransaction(transactionId, connectorId))));
return connectorId;
}
use of com.facebook.presto.metadata.Catalog in project presto by prestodb.
the class TestPrestoDriver method testGetSchemas.
@Test
public void testGetSchemas() throws Exception {
List<List<String>> system = new ArrayList<>();
system.add(list("system", "information_schema"));
system.add(list("system", "jdbc"));
system.add(list("system", "metadata"));
system.add(list("system", "runtime"));
List<List<String>> blackhole = new ArrayList<>();
blackhole.add(list("blackhole", "information_schema"));
blackhole.add(list("blackhole", "default"));
blackhole.add(list("blackhole", "blackhole"));
List<List<String>> test = new ArrayList<>();
test.add(list(TEST_CATALOG, "information_schema"));
for (String schema : TpchMetadata.SCHEMA_NAMES) {
test.add(list(TEST_CATALOG, schema));
}
List<List<String>> all = new ArrayList<>();
all.addAll(system);
all.addAll(test);
all.addAll(blackhole);
try (Connection connection = createConnection()) {
try (ResultSet rs = connection.getMetaData().getSchemas()) {
assertGetSchemasResult(rs, all);
}
try (ResultSet rs = connection.getMetaData().getSchemas(null, null)) {
assertGetSchemasResult(rs, all);
}
try (ResultSet rs = connection.getMetaData().getSchemas(TEST_CATALOG, null)) {
assertGetSchemasResult(rs, test);
}
try (ResultSet rs = connection.getMetaData().getSchemas("", null)) {
// all schemas in presto have a catalog name
assertGetSchemasResult(rs, list());
}
try (ResultSet rs = connection.getMetaData().getSchemas(TEST_CATALOG, "information_schema")) {
assertGetSchemasResult(rs, list(list(TEST_CATALOG, "information_schema")));
}
try (ResultSet rs = connection.getMetaData().getSchemas(null, "information_schema")) {
assertGetSchemasResult(rs, list(list(TEST_CATALOG, "information_schema"), list("blackhole", "information_schema"), list("system", "information_schema")));
}
try (ResultSet rs = connection.getMetaData().getSchemas(null, "sf_")) {
assertGetSchemasResult(rs, list(list(TEST_CATALOG, "sf1")));
}
try (ResultSet rs = connection.getMetaData().getSchemas(null, "sf%")) {
List<List<String>> expected = test.stream().filter(item -> item.get(1).startsWith("sf")).collect(toList());
assertGetSchemasResult(rs, expected);
}
try (ResultSet rs = connection.getMetaData().getSchemas("unknown", null)) {
assertGetSchemasResult(rs, list());
}
try (ResultSet rs = connection.getMetaData().getSchemas(null, "unknown")) {
assertGetSchemasResult(rs, list());
}
try (ResultSet rs = connection.getMetaData().getSchemas(TEST_CATALOG, "unknown")) {
assertGetSchemasResult(rs, list());
}
try (ResultSet rs = connection.getMetaData().getSchemas("unknown", "unknown")) {
assertGetSchemasResult(rs, list());
}
}
}
use of com.facebook.presto.metadata.Catalog in project presto by prestodb.
the class ConnectorManager method addCatalogConnector.
private synchronized void addCatalogConnector(String catalogName, ConnectorId connectorId, ConnectorFactory factory, Map<String, String> properties) {
// create all connectors before adding, so a broken connector does not leave the system half updated
MaterializedConnector connector = new MaterializedConnector(connectorId, createConnector(connectorId, factory, properties));
MaterializedConnector informationSchemaConnector = new MaterializedConnector(createInformationSchemaConnectorId(connectorId), new InformationSchemaConnector(catalogName, nodeManager, metadataManager, accessControlManager, connector.getSessionProperties()));
ConnectorId systemId = createSystemTablesConnectorId(connectorId);
SystemTablesProvider systemTablesProvider;
if (nodeManager.getCurrentNode().isCoordinator()) {
systemTablesProvider = new DelegatingSystemTablesProvider(new StaticSystemTablesProvider(connector.getSystemTables()), new MetadataBasedSystemTablesProvider(metadataManager, catalogName));
} else {
systemTablesProvider = new StaticSystemTablesProvider(connector.getSystemTables());
}
MaterializedConnector systemConnector = new MaterializedConnector(systemId, new SystemConnector(systemId, nodeManager, systemTablesProvider, transactionId -> transactionManager.getConnectorTransaction(transactionId, connectorId), connector.getSessionProperties()));
Catalog catalog = new Catalog(catalogName, connector.getConnectorId(), connector.getConnector(), informationSchemaConnector.getConnectorId(), informationSchemaConnector.getConnector(), systemConnector.getConnectorId(), systemConnector.getConnector());
try {
addConnectorInternal(connector);
addConnectorInternal(informationSchemaConnector);
addConnectorInternal(systemConnector);
catalogManager.registerCatalog(catalog);
} catch (Throwable e) {
catalogManager.removeCatalog(catalog.getCatalogName());
removeConnectorInternal(systemConnector.getConnectorId());
removeConnectorInternal(informationSchemaConnector.getConnectorId());
removeConnectorInternal(connector.getConnectorId());
throw e;
}
}
use of com.facebook.presto.metadata.Catalog in project presto by prestodb.
the class TestPrestoDriver method setup.
@BeforeClass
public void setup() throws Exception {
Logging.initialize();
server = new TestingPrestoServer();
server.installPlugin(new TpchPlugin());
server.createCatalog(TEST_CATALOG, "tpch");
server.installPlugin(new BlackHolePlugin());
server.createCatalog("blackhole", "blackhole");
Catalog bogusTestingCatalog = createBogusTestingCatalog(TESTING_CATALOG);
server.getCatalogManager().registerCatalog(bogusTestingCatalog);
SessionPropertyManager sessionPropertyManager = server.getMetadata().getSessionPropertyManager();
sessionPropertyManager.addConnectorSessionProperties(bogusTestingCatalog.getConnectorId(), TEST_CATALOG_PROPERTIES);
waitForNodeRefresh(server);
setupTestTables();
executorService = newCachedThreadPool(daemonThreadsNamed("test-%s"));
}
Aggregations