Search in sources :

Example 16 with ConnectorTableHandle

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

the class TestRaptorMetadata method testRenameTable.

@Test
public void testRenameTable() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    metadata.createTable(SESSION, getOrdersTable(), false);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    SchemaTableName renamedTable = new SchemaTableName(raptorTableHandle.getSchemaName(), "orders_renamed");
    metadata.renameTable(SESSION, raptorTableHandle, renamedTable);
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableHandle renamedTableHandle = metadata.getTableHandle(SESSION, renamedTable);
    assertNotNull(renamedTableHandle);
    assertEquals(((RaptorTableHandle) renamedTableHandle).getTableName(), renamedTable.getTableName());
}
Also used : RaptorTableHandle(com.facebook.presto.raptor.RaptorTableHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 17 with ConnectorTableHandle

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

the class TestRaptorMetadata method testRenameColumn.

@Test
public void testRenameColumn() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    metadata.createTable(SESSION, getOrdersTable(), false);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    ColumnHandle columnHandle = metadata.getColumnHandles(SESSION, tableHandle).get("orderkey");
    metadata.renameColumn(SESSION, raptorTableHandle, columnHandle, "orderkey_renamed");
    assertNull(metadata.getColumnHandles(SESSION, tableHandle).get("orderkey"));
    assertNotNull(metadata.getColumnHandles(SESSION, tableHandle).get("orderkey_renamed"));
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) RaptorTableHandle(com.facebook.presto.raptor.RaptorTableHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 18 with ConnectorTableHandle

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

the class TestRaptorMetadata method testTransactionDelete.

@Test
public void testTransactionDelete() {
    // creating a table allocates a transaction
    long transactionId = 1;
    metadata.createTable(SESSION, getOrdersTable(), false);
    assertTrue(transactionSuccessful(transactionId));
    // start delete
    transactionId++;
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    tableHandle = metadata.beginDelete(SESSION, tableHandle);
    // verify transaction is assigned for deletion handle
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    assertEquals(raptorTableHandle.getTableId(), 1);
    assertEquals(raptorTableHandle.getTransactionId(), OptionalLong.of(transactionId));
    // transaction is in progress
    assertTrue(transactionExists(transactionId));
    assertNull(transactionSuccessful(transactionId));
    // rollback delete
    metadata.rollback();
    assertTrue(transactionExists(transactionId));
    assertFalse(transactionSuccessful(transactionId));
    // start another delete
    transactionId++;
    tableHandle = metadata.beginDelete(SESSION, tableHandle);
    // transaction is in progress
    assertTrue(transactionExists(transactionId));
    assertNull(transactionSuccessful(transactionId));
    // commit delete
    metadata.finishDelete(SESSION, tableHandle, ImmutableList.of());
    assertTrue(transactionExists(transactionId));
    assertTrue(transactionSuccessful(transactionId));
}
Also used : RaptorTableHandle(com.facebook.presto.raptor.RaptorTableHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 19 with ConnectorTableHandle

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

the class TestRaptorMetadata method testCreateBucketedTableAsSelect.

@Test
public void testCreateBucketedTableAsSelect() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(BUCKET_COUNT_PROPERTY, 32, BUCKETED_ON_PROPERTY, ImmutableList.of("orderkey", "custkey"), TABLE_SUPPORTS_DELTA_DELETE, false));
    ConnectorNewTableLayout layout = metadata.getNewTableLayout(SESSION, ordersTable).get();
    assertEquals(layout.getPartitionColumns(), ImmutableList.of("orderkey", "custkey"));
    assertInstanceOf(layout.getPartitioning(), RaptorPartitioningHandle.class);
    RaptorPartitioningHandle partitioning = (RaptorPartitioningHandle) layout.getPartitioning();
    assertEquals(partitioning.getDistributionId(), 1);
    ConnectorOutputTableHandle outputHandle = metadata.beginCreateTable(SESSION, ordersTable, Optional.of(layout));
    metadata.finishCreateTable(SESSION, outputHandle, ImmutableList.of(), ImmutableList.of());
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    assertEquals(raptorTableHandle.getTableId(), 1);
    long tableId = raptorTableHandle.getTableId();
    MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
    assertTableColumnsEqual(metadataDao.listBucketColumns(tableId), ImmutableList.of(new TableColumn(DEFAULT_TEST_ORDERS, "orderkey", BIGINT, 1, 0, OptionalInt.of(0), OptionalInt.empty(), false), new TableColumn(DEFAULT_TEST_ORDERS, "custkey", BIGINT, 2, 1, OptionalInt.of(1), OptionalInt.empty(), false)));
    assertEquals(raptorTableHandle.getBucketCount(), OptionalInt.of(32));
    assertEquals(getTableDistributionId(tableId), Long.valueOf(1));
    metadata.dropTable(SESSION, tableHandle);
}
Also used : ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) RaptorTableHandle(com.facebook.presto.raptor.RaptorTableHandle) RaptorPartitioningHandle(com.facebook.presto.raptor.RaptorPartitioningHandle) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 20 with ConnectorTableHandle

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

the class TestRaptorMetadata method testTransactionInsert.

@Test
public void testTransactionInsert() {
    // creating a table allocates a transaction
    long transactionId = 1;
    metadata.createTable(SESSION, getOrdersTable(), false);
    assertTrue(transactionSuccessful(transactionId));
    // start insert
    transactionId++;
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    ConnectorInsertTableHandle insertHandle = metadata.beginInsert(SESSION, tableHandle);
    // transaction is in progress
    assertTrue(transactionExists(transactionId));
    assertNull(transactionSuccessful(transactionId));
    // commit insert
    metadata.finishInsert(SESSION, insertHandle, ImmutableList.of(), ImmutableList.of());
    assertTrue(transactionExists(transactionId));
    assertTrue(transactionSuccessful(transactionId));
}
Also used : ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)117 Test (org.testng.annotations.Test)68 ColumnHandle (com.facebook.presto.spi.ColumnHandle)64 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)64 ConnectorSession (com.facebook.presto.spi.ConnectorSession)61 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)49 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)45 SchemaTableName (com.facebook.presto.spi.SchemaTableName)42 Constraint (com.facebook.presto.spi.Constraint)35 ConnectorOutputTableHandle (com.facebook.presto.spi.ConnectorOutputTableHandle)31 MaterializedResult (com.facebook.presto.testing.MaterializedResult)31 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)30 Slice (io.airlift.slice.Slice)30 PrestoException (com.facebook.presto.spi.PrestoException)29 ConnectorInsertTableHandle (com.facebook.presto.spi.ConnectorInsertTableHandle)28 ConnectorTableLayout (com.facebook.presto.spi.ConnectorTableLayout)28 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)27 ImmutableList (com.google.common.collect.ImmutableList)27 Map (java.util.Map)27 Optional (java.util.Optional)27