use of io.prestosql.spi.connector.ConnectorMetadata 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.spi.connector.ConnectorMetadata 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.spi.connector.ConnectorMetadata in project hetu-core by openlookeng.
the class TestHiveView method tesHiveView.
@Test(enabled = false)
public void tesHiveView() {
SchemaTableName temporaryCreateView = temporaryTable("hive_view");
String viewData = "test hive view";
String expectedvViewData = "{\n" + " \"originalSql\" : \"test hive view\",\n" + " \"catalog\" : \"hive\",\n" + " \"columns\" : [ {\n" + " \"name\" : \"dummy\",\n" + " \"type\" : \"varchar\"\n" + " } ],\n" + " \"owner\" : \"test\",\n" + " \"runAsInvoker\" : false\n" + "}";
String owner = "test";
ConnectorSession session = newSession();
HiveIdentity identity = new HiveIdentity(session);
metastoreClient.createTable(identity, buildHiveView(temporaryCreateView, owner, viewData), buildInitialPrivilegeSet(owner));
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
Optional<ConnectorViewDefinition> views = metadata.getView(newSession(), temporaryCreateView);
assertEquals(views.get().getOriginalSql(), expectedvViewData);
assertTrue(metadata.listViews(newSession(), Optional.of(temporaryCreateView.getSchemaName())).contains(temporaryCreateView));
} finally {
metastoreClient.dropTable(identity, temporaryCreateView.getSchemaName(), temporaryCreateView.getTableName(), true);
}
}
use of io.prestosql.spi.connector.ConnectorMetadata in project hetu-core by openlookeng.
the class MetadataManager method getTableProperties.
@Override
public TableProperties getTableProperties(Session session, TableHandle handle) {
CatalogName catalogName = handle.getCatalogName();
CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogName);
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(catalogName);
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
TableProperties tableProperties;
ConcurrentHashMap<ConnectorTableHandle, TableProperties> tablePropertiesMap;
String queryId = session.getQueryId().getId();
if (metadata.usesLegacyTableLayouts()) {
return handle.getLayout().map(layout -> new TableProperties(catalogName, handle.getTransaction(), new ConnectorTableProperties(metadata.getTableLayout(connectorSession, layout)))).orElseGet(() -> getLayout(session, handle, Constraint.alwaysTrue(), Optional.empty()).get().getTableProperties());
}
if (!handle.getConnectorHandle().isTablePropertiesCacheSupported()) {
return new TableProperties(catalogName, handle.getTransaction(), metadata.getTableProperties(connectorSession, handle.getConnectorHandle()));
}
if (tablePropertiesQueryCache.get(queryId) != null && tablePropertiesQueryCache.get(queryId).get(handle.getConnectorHandle()) != null) {
return tablePropertiesQueryCache.get(queryId).get(handle.getConnectorHandle());
} else {
tableProperties = new TableProperties(catalogName, handle.getTransaction(), metadata.getTableProperties(connectorSession, handle.getConnectorHandle()));
if (tablePropertiesQueryCache.containsKey(queryId)) {
tablePropertiesMap = tablePropertiesQueryCache.get(queryId);
} else {
tablePropertiesMap = new ConcurrentHashMap<>();
}
tablePropertiesMap.put(handle.getConnectorHandle(), tableProperties);
tablePropertiesQueryCache.put(queryId, tablePropertiesMap);
}
return tableProperties;
}
use of io.prestosql.spi.connector.ConnectorMetadata in project hetu-core by openlookeng.
the class MetadataManager method applyFilter.
@Override
public Optional<ConstraintApplicationResult<TableHandle>> applyFilter(Session session, TableHandle table, Constraint constraint, List<Constraint> disjunctConstraints, Set<ColumnHandle> allColumnHandles, boolean pushPartitionsOnly) {
CatalogName catalogName = table.getCatalogName();
ConnectorMetadata metadata = getMetadata(session, catalogName);
if (metadata.usesLegacyTableLayouts()) {
return Optional.empty();
}
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
return metadata.applyFilter(connectorSession, table.getConnectorHandle(), constraint, disjunctConstraints, allColumnHandles, pushPartitionsOnly).map(result -> new ConstraintApplicationResult<>(new TableHandle(catalogName, result.getHandle(), table.getTransaction(), Optional.empty()), result.getRemainingFilter()));
}
Aggregations