Search in sources :

Example 1 with ConnectorOutputTableHandle

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

the class TestMemoryMetadata method testReadTableBeforeCreationCompleted.

@Test
public void testReadTableBeforeCreationCompleted() {
    assertNoTables();
    SchemaTableName tableName = new SchemaTableName("default", "temp_table");
    ConnectorOutputTableHandle table = metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(tableName, ImmutableList.of(), ImmutableMap.of()), Optional.empty());
    List<SchemaTableName> tableNames = metadata.listTables(SESSION, Optional.empty());
    assertTrue(tableNames.size() == 1, "Expected exactly one table");
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, tableName);
    List<ConnectorTableLayoutResult> tableLayouts = metadata.getTableLayouts(SESSION, tableHandle, Constraint.alwaysTrue(), Optional.empty());
    assertTrue(tableLayouts.size() == 1, "Expected exactly one layout.");
    ConnectorTableLayout tableLayout = tableLayouts.get(0).getTableLayout();
    ConnectorTableLayoutHandle tableLayoutHandle = tableLayout.getHandle();
    assertTrue(tableLayoutHandle instanceof MemoryTableLayoutHandle);
    assertTrue(((MemoryTableLayoutHandle) tableLayoutHandle).getDataFragments().isEmpty(), "Data fragments should be empty");
    metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());
}
Also used : ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 2 with ConnectorOutputTableHandle

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

the class TestMemoryMetadata method tableIsCreatedAfterCommits.

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

Example 3 with ConnectorOutputTableHandle

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

the class TestRaptorMetadata method testTransactionTableWrite.

@Test
public void testTransactionTableWrite() {
    // start table creation
    long transactionId = 1;
    ConnectorOutputTableHandle outputHandle = metadata.beginCreateTable(SESSION, getOrdersTable(), Optional.empty());
    // transaction is in progress
    assertTrue(transactionExists(transactionId));
    assertNull(transactionSuccessful(transactionId));
    // commit table creation
    metadata.finishCreateTable(SESSION, outputHandle, ImmutableList.of(), ImmutableList.of());
    assertTrue(transactionExists(transactionId));
    assertTrue(transactionSuccessful(transactionId));
}
Also used : ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) Test(org.testng.annotations.Test)

Example 4 with ConnectorOutputTableHandle

use of com.facebook.presto.spi.ConnectorOutputTableHandle 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 5 with ConnectorOutputTableHandle

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

the class AbstractTestHiveFileSystem method createTable.

private void createTable(MetastoreContext metastoreContext, SchemaTableName tableName, HiveStorageFormat storageFormat) throws Exception {
    List<ColumnMetadata> columns = ImmutableList.<ColumnMetadata>builder().add(new ColumnMetadata("id", BIGINT)).build();
    MaterializedResult data = MaterializedResult.resultBuilder(newSession(), BIGINT).row(1L).row(3L).row(2L).build();
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        ConnectorSession session = newSession();
        // begin creating the table
        ConnectorTableMetadata tableMetadata = new ConnectorTableMetadata(tableName, columns, createTableProperties(storageFormat));
        ConnectorOutputTableHandle outputHandle = metadata.beginCreateTable(session, tableMetadata, Optional.empty());
        // write the records
        ConnectorPageSink sink = pageSinkProvider.createPageSink(transaction.getTransactionHandle(), session, outputHandle, TEST_HIVE_PAGE_SINK_CONTEXT);
        sink.appendPage(data.toPage());
        Collection<Slice> fragments = getFutureValue(sink.finish());
        // commit the table
        metadata.finishCreateTable(session, outputHandle, fragments, ImmutableList.of());
        transaction.commit();
        // Hack to work around the metastore not being configured for S3 or other FS.
        // The metastore tries to validate the location when creating the
        // table, which fails without explicit configuration for file system.
        // We work around that by using a dummy location when creating the
        // table and update it here to the correct location.
        metastoreClient.updateTableLocation(metastoreContext, database, tableName.getTableName(), locationService.getTableWriteInfo(((HiveOutputTableHandle) outputHandle).getLocationHandle()).getTargetPath().toString());
    }
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        ConnectorSession session = newSession();
        // load the new table
        ConnectorTableHandle hiveTableHandle = getTableHandle(metadata, tableName);
        List<ColumnHandle> columnHandles = filterNonHiddenColumnHandles(metadata.getColumnHandles(session, hiveTableHandle).values());
        // verify the metadata
        ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(session, getTableHandle(metadata, tableName));
        assertEquals(filterNonHiddenColumnMetadata(tableMetadata.getColumns()), columns);
        // verify the data
        List<ConnectorTableLayoutResult> tableLayoutResults = metadata.getTableLayouts(session, hiveTableHandle, Constraint.alwaysTrue(), Optional.empty());
        HiveTableLayoutHandle layoutHandle = (HiveTableLayoutHandle) getOnlyElement(tableLayoutResults).getTableLayout().getHandle();
        assertEquals(layoutHandle.getPartitions().get().size(), 1);
        ConnectorSplitSource splitSource = splitManager.getSplits(transaction.getTransactionHandle(), session, layoutHandle, SPLIT_SCHEDULING_CONTEXT);
        ConnectorSplit split = getOnlyElement(getAllSplits(splitSource));
        TableHandle tableHandle = new TableHandle(new ConnectorId("hive"), hiveTableHandle, transaction.getTransactionHandle(), Optional.of(layoutHandle));
        try (ConnectorPageSource pageSource = pageSourceProvider.createPageSource(transaction.getTransactionHandle(), session, split, tableHandle.getLayout().get(), columnHandles, NON_CACHEABLE)) {
            MaterializedResult result = materializeSourceDataStream(session, pageSource, getTypes(columnHandles));
            assertEqualsIgnoreOrder(result.getMaterializedRows(), data.getMaterializedRows());
        }
    }
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) AbstractTestHiveClient.filterNonHiddenColumnMetadata(com.facebook.presto.hive.AbstractTestHiveClient.filterNonHiddenColumnMetadata) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) HiveTransaction(com.facebook.presto.hive.AbstractTestHiveClient.HiveTransaction) Transaction(com.facebook.presto.hive.AbstractTestHiveClient.Transaction) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) Slice(io.airlift.slice.Slice) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) TableHandle(com.facebook.presto.spi.TableHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ConnectorPageSink(com.facebook.presto.spi.ConnectorPageSink) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

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