Search in sources :

Example 36 with ConnectorTransactionHandle

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))));
}
Also used : JdbcTableLayoutHandle(com.facebook.presto.plugin.jdbc.JdbcTableLayoutHandle) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) TableHandle(com.facebook.presto.spi.TableHandle) JdbcTableHandle(com.facebook.presto.plugin.jdbc.JdbcTableHandle) JdbcTableHandle(com.facebook.presto.plugin.jdbc.JdbcTableHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 37 with ConnectorTransactionHandle

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());
}
Also used : TableScanOperator(com.facebook.presto.operator.TableScanOperator) ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Driver(com.facebook.presto.operator.Driver) Duration(io.airlift.units.Duration) FixedPageSource(com.facebook.presto.spi.FixedPageSource) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PageConsumerOperator(com.facebook.presto.testing.PageConsumerOperator) Type(com.facebook.presto.common.type.Type) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) TableHandle(com.facebook.presto.spi.TableHandle) ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) Split(com.facebook.presto.metadata.Split) TaskSource(com.facebook.presto.execution.TaskSource) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Example 38 with ConnectorTransactionHandle

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);
}
Also used : Connector(com.facebook.presto.spi.connector.Connector) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) TestingConnectorContext(com.facebook.presto.testing.TestingConnectorContext)

Example 39 with ConnectorTransactionHandle

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);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) DriverFactory(com.facebook.presto.operator.DriverFactory) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Driver(com.facebook.presto.operator.Driver) Page(com.facebook.presto.common.Page) ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) Split(com.facebook.presto.metadata.Split) TaskSource(com.facebook.presto.execution.TaskSource)

Example 40 with ConnectorTransactionHandle

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));
}
Also used : ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)40 ConnectorSession (com.facebook.presto.spi.ConnectorSession)18 ColumnHandle (com.facebook.presto.spi.ColumnHandle)13 ConnectorId (com.facebook.presto.spi.ConnectorId)12 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)12 List (java.util.List)12 Objects.requireNonNull (java.util.Objects.requireNonNull)12 ImmutableList (com.google.common.collect.ImmutableList)11 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)10 Inject (javax.inject.Inject)9 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)8 Optional (java.util.Optional)8 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)7 SchemaTableName (com.facebook.presto.spi.SchemaTableName)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)6 Type (com.facebook.presto.common.type.Type)6 Map (java.util.Map)5 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)4 NodeManager (com.facebook.presto.spi.NodeManager)4