Search in sources :

Example 11 with ConnectorOutputTableHandle

use of io.trino.spi.connector.ConnectorOutputTableHandle in project trino by trinodb.

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
    assertTrinoExceptionThrownBy(() -> metadata.finishCreateTable(SESSION, outputHandle, ImmutableList.of(), ImmutableList.of())).hasErrorCode(TRANSACTION_CONFLICT).hasMessage("Transaction commit failed. Please retry the operation.");
}
Also used : ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) Test(org.testng.annotations.Test)

Example 12 with ConnectorOutputTableHandle

use of io.trino.spi.connector.ConnectorOutputTableHandle in project trino by trinodb.

the class BlackHoleMetadata method createTable.

@Override
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting) {
    ConnectorOutputTableHandle outputTableHandle = beginCreateTable(session, tableMetadata, Optional.empty());
    finishCreateTable(session, outputTableHandle, ImmutableList.of(), ImmutableList.of());
}
Also used : ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle)

Example 13 with ConnectorOutputTableHandle

use of io.trino.spi.connector.ConnectorOutputTableHandle in project trino by trinodb.

the class TestBlackHoleMetadata method tableIsCreatedAfterCommits.

@Test
public void tableIsCreatedAfterCommits() {
    assertThatNoTableIsCreated();
    SchemaTableName schemaTableName = new SchemaTableName("default", "temp_table");
    ConnectorOutputTableHandle table = metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(schemaTableName, ImmutableList.of(), tableProperties), Optional.empty());
    assertThatNoTableIsCreated();
    metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());
    List<SchemaTableName> tables = metadata.listTables(SESSION, Optional.empty());
    assertEquals(tables.size(), 1, "Expected only one table.");
    assertEquals(tables.get(0).getTableName(), "temp_table", "Expected table with name 'temp_table'");
}
Also used : ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 14 with ConnectorOutputTableHandle

use of io.trino.spi.connector.ConnectorOutputTableHandle in project trino by trinodb.

the class TestTableWriterOperator method createTableWriterOperator.

private Operator createTableWriterOperator(PageSinkManager pageSinkManager, OperatorFactory statisticsAggregation, List<Type> outputTypes, Session session, DriverContext driverContext) {
    List<String> notNullColumnNames = new ArrayList<>(1);
    notNullColumnNames.add(null);
    TableWriterOperatorFactory factory = new TableWriterOperatorFactory(0, new PlanNodeId("test"), pageSinkManager, new CreateTarget(new OutputTableHandle(CONNECTOR_ID, new ConnectorTransactionHandle() {
    }, new ConnectorOutputTableHandle() {
    }), new SchemaTableName("testSchema", "testTable")), ImmutableList.of(0), notNullColumnNames, session, statisticsAggregation, outputTypes);
    return factory.createOperator(driverContext);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TableWriterOperatorFactory(io.trino.operator.TableWriterOperator.TableWriterOperatorFactory) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) OutputTableHandle(io.trino.metadata.OutputTableHandle) CreateTarget(io.trino.sql.planner.plan.TableWriterNode.CreateTarget) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) ArrayList(java.util.ArrayList) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 15 with ConnectorOutputTableHandle

use of io.trino.spi.connector.ConnectorOutputTableHandle in project trino by trinodb.

the class MetadataManager method beginCreateTable.

@Override
public OutputTableHandle beginCreateTable(Session session, String catalogName, ConnectorTableMetadata tableMetadata, Optional<TableLayout> layout) {
    CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName);
    CatalogName catalog = catalogMetadata.getCatalogName();
    ConnectorMetadata metadata = catalogMetadata.getMetadata(session);
    ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(catalog);
    ConnectorSession connectorSession = session.toConnectorSession(catalog);
    ConnectorOutputTableHandle handle = metadata.beginCreateTable(connectorSession, tableMetadata, layout.map(TableLayout::getLayout), getRetryPolicy(session).getRetryMode());
    // TODO this should happen after finish but there is no way to get table name in finish step
    if (catalogMetadata.getSecurityManagement() == SecurityManagement.SYSTEM) {
        systemSecurityMetadata.tableCreated(session, new CatalogSchemaTableName(catalogName, tableMetadata.getTable()));
    }
    return new OutputTableHandle(catalog, transactionHandle, handle);
}
Also used : ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName)

Aggregations

ConnectorOutputTableHandle (io.trino.spi.connector.ConnectorOutputTableHandle)19 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)13 Test (org.testng.annotations.Test)10 ConnectorSession (io.trino.spi.connector.ConnectorSession)9 SchemaTableName (io.trino.spi.connector.SchemaTableName)9 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)7 Slice (io.airlift.slice.Slice)6 ConnectorPageSink (io.trino.spi.connector.ConnectorPageSink)6 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)6 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)5 MaterializedResult (io.trino.testing.MaterializedResult)5 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)4 HdfsContext (io.trino.plugin.hive.HdfsEnvironment.HdfsContext)4 TestingConnectorSession (io.trino.testing.TestingConnectorSession)4 HiveSessionProperties.getTemporaryStagingDirectoryPath (io.trino.plugin.hive.HiveSessionProperties.getTemporaryStagingDirectoryPath)3 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)3 ColumnHandle (io.trino.spi.connector.ColumnHandle)3 Path (org.apache.hadoop.fs.Path)3 HiveColumnHandle.bucketColumnHandle (io.trino.plugin.hive.HiveColumnHandle.bucketColumnHandle)2 ConnectorPageSource (io.trino.spi.connector.ConnectorPageSource)2