Search in sources :

Example 16 with ConnectorOutputTableHandle

use of com.facebook.presto.spi.ConnectorOutputTableHandle in project presto by prestodb.

the class MetadataManager method beginCreateTable.

@Override
public OutputTableHandle beginCreateTable(Session session, String catalogName, ConnectorTableMetadata tableMetadata, Optional<NewTableLayout> layout) {
    CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName);
    ConnectorId connectorId = catalogMetadata.getConnectorId();
    ConnectorMetadata metadata = catalogMetadata.getMetadata();
    ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(connectorId);
    ConnectorSession connectorSession = session.toConnectorSession(connectorId);
    ConnectorOutputTableHandle handle = metadata.beginCreateTable(connectorSession, tableMetadata, layout.map(NewTableLayout::getLayout));
    return new OutputTableHandle(connectorId, transactionHandle, handle);
}
Also used : ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 17 with ConnectorOutputTableHandle

use of com.facebook.presto.spi.ConnectorOutputTableHandle in project presto by prestodb.

the class AbstractTestHiveClient method createDummyTable.

private void createDummyTable(SchemaTableName tableName) {
    try (Transaction transaction = newTransaction()) {
        ConnectorSession session = newSession();
        ConnectorMetadata metadata = transaction.getMetadata();
        List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata("dummy", createUnboundedVarcharType()));
        ConnectorTableMetadata tableMetadata = new ConnectorTableMetadata(tableName, columns, createTableProperties(TEXTFILE));
        ConnectorOutputTableHandle handle = metadata.beginCreateTable(session, tableMetadata, Optional.empty());
        metadata.finishCreateTable(session, handle, ImmutableList.of(), ImmutableList.of());
        transaction.commit();
    }
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 18 with ConnectorOutputTableHandle

use of com.facebook.presto.spi.ConnectorOutputTableHandle in project presto by prestodb.

the class TestRaptorMetadata method testTransactionAbort.

@Test
public void testTransactionAbort() {
    // start table creation
    long transactionId = 1;
    ConnectorOutputTableHandle outputHandle = metadata.beginCreateTable(SESSION, getOrdersTable(), Optional.empty());
    // transaction is in progress
    assertTrue(transactionExists(transactionId));
    assertNull(transactionSuccessful(transactionId));
    // force transaction to abort
    shardManager.rollbackTransaction(transactionId);
    assertTrue(transactionExists(transactionId));
    assertFalse(transactionSuccessful(transactionId));
    // commit table creation
    try {
        metadata.finishCreateTable(SESSION, outputHandle, ImmutableList.of(), ImmutableList.of());
        fail("expected exception");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), TRANSACTION_CONFLICT.toErrorCode());
    }
}
Also used : ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) PrestoException(com.facebook.presto.spi.PrestoException) Test(org.testng.annotations.Test)

Aggregations

ConnectorOutputTableHandle (com.facebook.presto.spi.ConnectorOutputTableHandle)18 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)10 Test (org.testng.annotations.Test)8 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)7 SchemaTableName (com.facebook.presto.spi.SchemaTableName)7 ConnectorSession (com.facebook.presto.spi.ConnectorSession)6 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)5 ColumnHandle (com.facebook.presto.spi.ColumnHandle)4 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)4 ConnectorTableLayoutResult (com.facebook.presto.spi.ConnectorTableLayoutResult)4 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)4 Slice (io.airlift.slice.Slice)4 Table (com.facebook.presto.hive.metastore.Table)3 ConnectorPageSink (com.facebook.presto.spi.ConnectorPageSink)3 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)3 MaterializedResult (com.facebook.presto.testing.MaterializedResult)3 Path (org.apache.hadoop.fs.Path)3 Database (com.facebook.presto.hive.metastore.Database)2 PrincipalPrivileges (com.facebook.presto.hive.metastore.PrincipalPrivileges)2 Constraint (com.facebook.presto.spi.Constraint)2