use of com.facebook.presto.spi.connector.ConnectorTransactionHandle in project presto by prestodb.
the class TestJdbcComputePushdown method jdbcTableScan.
private TableScanNode jdbcTableScan(String schema, String table, Type type, String... columnNames) {
JdbcTableHandle jdbcTableHandle = new JdbcTableHandle(CONNECTOR_ID, new SchemaTableName(schema, table), CATALOG_NAME, schema, table);
JdbcTableLayoutHandle jdbcTableLayoutHandle = new JdbcTableLayoutHandle(TEST_SESSION.getSqlFunctionProperties(), jdbcTableHandle, TupleDomain.none(), Optional.empty());
TableHandle tableHandle = new TableHandle(new ConnectorId(CATALOG_NAME), jdbcTableHandle, new ConnectorTransactionHandle() {
}, Optional.of(jdbcTableLayoutHandle));
return PLAN_BUILDER.tableScan(tableHandle, Arrays.stream(columnNames).map(column -> newVariable(column, type)).collect(toImmutableList()), Arrays.stream(columnNames).map(column -> newVariable(column, type)).collect(toMap(identity(), entry -> getColumnHandleForVariable(entry.getName(), type))));
}
use of com.facebook.presto.spi.connector.ConnectorTransactionHandle in project presto by prestodb.
the class TestSystemMemoryBlocking method testTableScanSystemMemoryBlocking.
@Test
public void testTableScanSystemMemoryBlocking() {
PlanNodeId sourceId = new PlanNodeId("source");
final List<Type> types = ImmutableList.of(VARCHAR);
TableScanOperator source = new TableScanOperator(driverContext.addOperatorContext(1, new PlanNodeId("test"), "values"), sourceId, (session, split, table, columns) -> new FixedPageSource(rowPagesBuilder(types).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).build()), new TableHandle(new ConnectorId("test"), new ConnectorTableHandle() {
}, new ConnectorTransactionHandle() {
}, Optional.empty()), ImmutableList.of());
PageConsumerOperator sink = createSinkOperator(types);
Driver driver = Driver.createDriver(driverContext, source, sink);
assertSame(driver.getDriverContext(), driverContext);
assertFalse(driver.isFinished());
Split testSplit = new Split(new ConnectorId("test"), TestingTransactionHandle.create(), new TestSplit());
driver.updateSource(new TaskSource(sourceId, ImmutableSet.of(new ScheduledSplit(0, sourceId, testSplit)), true));
ListenableFuture<?> blocked = driver.processFor(new Duration(1, NANOSECONDS));
// the driver shouldn't block in the first call as it will be able to move a page between source and the sink operator
// but the operator should be blocked
assertTrue(blocked.isDone());
assertFalse(source.getOperatorContext().isWaitingForMemory().isDone());
// and they should stay blocked until more memory becomes available
for (int i = 0; i < 10; i++) {
blocked = driver.processFor(new Duration(1, NANOSECONDS));
assertFalse(blocked.isDone());
assertFalse(source.getOperatorContext().isWaitingForMemory().isDone());
}
// free up some memory
memoryPool.free(QUERY_ID, "test", memoryPool.getReservedBytes());
// the operator should be unblocked
assertTrue(source.getOperatorContext().isWaitingForMemory().isDone());
// the driver shouldn't be blocked
blocked = driver.processFor(new Duration(1, NANOSECONDS));
assertTrue(blocked.isDone());
}
use of com.facebook.presto.spi.connector.ConnectorTransactionHandle in project presto by prestodb.
the class TestHiveConnectorFactory method assertCreateConnector.
private static void assertCreateConnector(String metastoreUri) {
HiveConnectorFactory connectorFactory = new HiveConnectorFactory("hive-test", HiveConnector.class.getClassLoader(), Optional.empty());
Map<String, String> config = ImmutableMap.<String, String>builder().put("hive.metastore.uri", metastoreUri).build();
Connector connector = connectorFactory.create("hive-test", config, new TestingConnectorContext());
ConnectorTransactionHandle transaction = connector.beginTransaction(READ_UNCOMMITTED, true);
assertInstanceOf(connector.getMetadata(transaction), ClassLoaderSafeConnectorMetadata.class);
assertInstanceOf(connector.getSplitManager(), ClassLoaderSafeConnectorSplitManager.class);
assertInstanceOf(connector.getPageSourceProvider(), ConnectorPageSourceProvider.class);
connector.commit(transaction);
}
use of com.facebook.presto.spi.connector.ConnectorTransactionHandle in project presto by prestodb.
the class IndexLoader method streamIndexDataForSingleKey.
public IndexedData streamIndexDataForSingleKey(UpdateRequest updateRequest) {
Page indexKeyTuple = updateRequest.getPage().getRegion(0, 1);
PageBuffer pageBuffer = new PageBuffer(100);
DriverFactory driverFactory = indexBuildDriverFactoryProvider.createStreaming(pageBuffer, indexKeyTuple);
Driver driver = driverFactory.createDriver(pipelineContext.addDriverContext());
PageRecordSet pageRecordSet = new PageRecordSet(keyTypes, indexKeyTuple);
PlanNodeId planNodeId = driverFactory.getSourceId().get();
ScheduledSplit split = new ScheduledSplit(0, planNodeId, new Split(INDEX_CONNECTOR_ID, new ConnectorTransactionHandle() {
}, new IndexSplit(pageRecordSet)));
driver.updateSource(new TaskSource(planNodeId, ImmutableSet.of(split), true));
return new StreamingIndexedData(outputTypes, keyTypes, indexKeyTuple, pageBuffer, driver);
}
use of com.facebook.presto.spi.connector.ConnectorTransactionHandle in project presto by prestodb.
the class TestRaptorConnector method testMaintenanceBlocked.
@Test
public void testMaintenanceBlocked() {
long tableId1 = createTable("test1");
long tableId2 = createTable("test2");
assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId1));
assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId2));
// begin delete for table1
ConnectorTransactionHandle txn1 = connector.beginTransaction(READ_COMMITTED, false);
ConnectorTableHandle handle1 = getTableHandle(connector.getMetadata(txn1), "test1");
connector.getMetadata(txn1).beginDelete(SESSION, handle1);
assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId1));
assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId2));
// begin delete for table2
ConnectorTransactionHandle txn2 = connector.beginTransaction(READ_COMMITTED, false);
ConnectorTableHandle handle2 = getTableHandle(connector.getMetadata(txn2), "test2");
connector.getMetadata(txn2).beginDelete(SESSION, handle2);
assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId1));
assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId2));
// begin another delete for table1
ConnectorTransactionHandle txn3 = connector.beginTransaction(READ_COMMITTED, false);
ConnectorTableHandle handle3 = getTableHandle(connector.getMetadata(txn3), "test1");
connector.getMetadata(txn3).beginDelete(SESSION, handle3);
assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId1));
assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId2));
// commit first delete for table1
connector.commit(txn1);
assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId1));
assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId2));
// rollback second delete for table1
connector.rollback(txn3);
assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId1));
assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId2));
// commit delete for table2
connector.commit(txn2);
assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId1));
assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId2));
}
Aggregations