use of io.prestosql.metadata.CatalogManager in project hetu-core by openlookeng.
the class TestTransactionManager method testExpiration.
@Test
public void testExpiration() throws Exception {
try (IdleCheckExecutor executor = new IdleCheckExecutor()) {
TransactionManager transactionManager = InMemoryTransactionManager.create(new TransactionManagerConfig().setIdleTimeout(new Duration(1, TimeUnit.MILLISECONDS)).setIdleCheckInterval(new Duration(5, TimeUnit.MILLISECONDS)), executor.getExecutor(), new CatalogManager(), finishingExecutor);
TransactionId transactionId = transactionManager.beginTransaction(false);
assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
TransactionInfo transactionInfo = transactionManager.getTransactionInfo(transactionId);
assertFalse(transactionInfo.isAutoCommitContext());
assertTrue(transactionInfo.getCatalogNames().isEmpty());
assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
transactionManager.trySetInactive(transactionId);
TimeUnit.MILLISECONDS.sleep(100);
assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
}
use of io.prestosql.metadata.CatalogManager in project hetu-core by openlookeng.
the class TestTransactionManager method testAbortedTransactionWorkflow.
@Test
public void testAbortedTransactionWorkflow() {
try (IdleCheckExecutor executor = new IdleCheckExecutor()) {
CatalogManager catalogManager = new CatalogManager();
TransactionManager transactionManager = InMemoryTransactionManager.create(new TransactionManagerConfig(), executor.getExecutor(), catalogManager, finishingExecutor);
Connector c1 = new TpchConnectorFactory().create(CATALOG, ImmutableMap.of(), new TestingConnectorContext());
registerConnector(catalogManager, transactionManager, CATALOG, CATALOG_NAME, c1);
TransactionId transactionId = transactionManager.beginTransaction(false);
assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
TransactionInfo transactionInfo = transactionManager.getTransactionInfo(transactionId);
assertFalse(transactionInfo.isAutoCommitContext());
assertTrue(transactionInfo.getCatalogNames().isEmpty());
assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
ConnectorMetadata metadata = transactionManager.getOptionalCatalogMetadata(transactionId, CATALOG).get().getMetadata();
metadata.listSchemaNames(TEST_SESSION.toConnectorSession(CATALOG_NAME));
transactionInfo = transactionManager.getTransactionInfo(transactionId);
assertEquals(transactionInfo.getCatalogNames(), ImmutableList.of(CATALOG_NAME, INFORMATION_SCHEMA_ID, SYSTEM_TABLES_ID));
assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
getFutureValue(transactionManager.asyncAbort(transactionId));
assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
}
use of io.prestosql.metadata.CatalogManager in project hetu-core by openlookeng.
the class TestCarbonAutoVacuum method testAutoVacuum.
@Test
public void testAutoVacuum() throws SQLException {
hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable1");
hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable2");
hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable3");
hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable4");
hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable1(a int, b int)");
hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable1 VALUES (10, 11)");
hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable2(a int, b int)");
hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (10, 11)");
hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (20, 11)");
hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (30, 11)");
hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (30, 11)");
hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable3 as select a, b from carbontestdb1.autovacuumtable2 ");
hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable4(a int, b int)");
hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable4 VALUES (10, 11)");
hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable4 VALUES (20, 11)");
hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable4 VALUES (30, 12)");
hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable4 VALUES (40, 13)");
CatalogManager catalogManager = hetuServer.getCatalog();
List<Catalog> catalogs = catalogManager.getCatalogs();
Catalog catalog = null;
for (Catalog catalog1 : catalogs) {
if (catalog1.getConnectorCatalogName().getCatalogName().equals("carbondata")) {
catalog = catalog1;
break;
}
}
Connector connector;
ConnectorMetadata connectorMetadata = null;
List<ConnectorVacuumTableInfo> tables;
List<String> tablesNames = new ArrayList<>();
try {
CarbondataAutoVacuumThread.enableTracingVacuumTask(true);
assertNotNull(catalog);
connector = catalog.getConnector(catalog.getConnectorCatalogName());
connectorMetadata = connector.getConnectorMetadata();
connectorMetadata.getTablesForVacuum();
} catch (Exception e) {
logger.debug(e.getMessage());
}
CarbondataAutoVacuumThread.waitForSubmittedVacuumTasksFinish();
CarbondataAutoVacuumThread.enableTracingVacuumTask(false);
tables = connectorMetadata.getTablesForVacuum();
if (tables != null && 0 != tables.size()) {
for (ConnectorVacuumTableInfo vacuumTable : tables) {
tablesNames.add(vacuumTable.getSchemaTableName());
}
}
assertTrue(tablesNames.contains("carbontestdb1.autovacuumtable4"));
assertTrue(tablesNames.contains("carbontestdb1.autovacuumtable2"));
hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable1");
hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable2");
hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable3");
hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable4");
}
use of io.prestosql.metadata.CatalogManager in project hetu-core by openlookeng.
the class TestAccessControlManager method testDenyCatalogAccessControl.
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Access Denied: Cannot select from columns \\[column\\] in table or view schema.table")
public void testDenyCatalogAccessControl() {
CatalogManager catalogManager = new CatalogManager();
TransactionManager transactionManager = createTestTransactionManager(catalogManager);
AccessControlManager accessControlManager = new AccessControlManager(transactionManager);
TestSystemAccessControlFactory accessControlFactory = new TestSystemAccessControlFactory("test");
accessControlManager.addSystemAccessControlFactory(accessControlFactory);
accessControlManager.setSystemAccessControl("test", ImmutableMap.of());
CatalogName catalogName = registerBogusConnector(catalogManager, transactionManager, accessControlManager, "catalog");
accessControlManager.addCatalogAccessControl(catalogName, new DenyConnectorAccessControl());
transaction(transactionManager, accessControlManager).execute(transactionId -> {
accessControlManager.checkCanSelectFromColumns(transactionId, new Identity(USER_NAME, Optional.of(PRINCIPAL)), new QualifiedObjectName("catalog", "schema", "table"), ImmutableSet.of("column"));
});
}
use of io.prestosql.metadata.CatalogManager in project hetu-core by openlookeng.
the class TestAccessControlManager method testColumnMaskOrdering.
@Test
public void testColumnMaskOrdering() {
CatalogManager catalogManager = new CatalogManager();
TransactionManager transactionManager = createTestTransactionManager(catalogManager);
AccessControlManager accessControlManager = new AccessControlManager(transactionManager);
accessControlManager.addSystemAccessControlFactory(new SystemAccessControlFactory() {
@Override
public String getName() {
return "test";
}
@Override
public SystemAccessControl create(Map<String, String> config) {
return new SystemAccessControl() {
@Override
public void checkCanSetUser(Optional<Principal> principal, String userName) {
}
@Override
public void checkCanImpersonateUser(Identity identity, String propertyName) {
}
@Override
public void checkCanSetSystemSessionProperty(Identity identity, String propertyName) {
}
@Override
public Optional<ViewExpression> getColumnMask(Identity identity, CatalogSchemaTableName tableName, String columnName, Type type) {
return Optional.of(new ViewExpression("user", Optional.empty(), Optional.empty(), "system mask"));
}
};
}
});
accessControlManager.setSystemAccessControl("test", ImmutableMap.of());
CatalogName catalogName = registerBogusConnector(catalogManager, transactionManager, accessControlManager, "catalog");
accessControlManager.addCatalogAccessControl(catalogName, new ConnectorAccessControl() {
@Override
public Optional<ViewExpression> getColumnMask(ConnectorTransactionHandle transactionHandle, Identity identity, SchemaTableName tableName, String columnName, Type type) {
return Optional.of(new ViewExpression("user", Optional.empty(), Optional.empty(), "connector mask"));
}
});
transaction(transactionManager, accessControlManager).execute(transactionId -> {
List<ViewExpression> masks = accessControlManager.getColumnMasks(transactionId, new Identity(USER_NAME, Optional.of(PRINCIPAL)), new QualifiedObjectName("catalog", "schema", "table"), "column", BIGINT);
assertEquals(masks.get(0).getExpression(), "connector mask");
assertEquals(masks.get(1).getExpression(), "system mask");
});
}
Aggregations