Search in sources :

Example 16 with ConnectorTableLayout

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

the class AbstractTestHive method insertPartitionedBucketedTableLayout.

protected void insertPartitionedBucketedTableLayout(boolean transactional) throws Exception {
    SchemaTableName tableName = temporaryTable("empty_partitioned_table");
    try {
        Column partitioningColumn = new Column("column2", HIVE_LONG, Optional.empty());
        List<Column> columns = ImmutableList.of(new Column("column1", HIVE_STRING, Optional.empty()), partitioningColumn);
        HiveBucketProperty bucketProperty = new HiveBucketProperty(ImmutableList.of("column1"), BUCKETING_V1, 4, ImmutableList.of());
        createEmptyTable(tableName, ORC, columns, ImmutableList.of(partitioningColumn), Optional.of(bucketProperty), transactional);
        try (Transaction transaction = newTransaction()) {
            ConnectorMetadata metadata = transaction.getMetadata();
            ConnectorSession session = newSession();
            ConnectorTableHandle tableHandle = getTableHandle(metadata, tableName);
            Optional<ConnectorTableLayout> insertLayout = metadata.getInsertLayout(session, tableHandle);
            assertTrue(insertLayout.isPresent());
            ConnectorPartitioningHandle partitioningHandle = new HivePartitioningHandle(bucketProperty.getBucketingVersion(), bucketProperty.getBucketCount(), ImmutableList.of(HIVE_STRING), OptionalInt.empty(), true);
            assertEquals(insertLayout.get().getPartitioning(), Optional.of(partitioningHandle));
            assertEquals(insertLayout.get().getPartitionColumns(), ImmutableList.of("column1", "column2"));
            ConnectorBucketNodeMap connectorBucketNodeMap = nodePartitioningProvider.getBucketNodeMap(transaction.getTransactionHandle(), session, partitioningHandle);
            assertEquals(connectorBucketNodeMap.getBucketCount(), 32);
            assertTrue(connectorBucketNodeMap.hasFixedMapping());
            assertEquals(connectorBucketNodeMap.getFixedMapping().size(), 32);
        }
    } finally {
        dropTable(tableName);
    }
}
Also used : CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) ConnectorPartitioningHandle(io.trino.spi.connector.ConnectorPartitioningHandle) HiveColumnHandle.createBaseColumn(io.trino.plugin.hive.HiveColumnHandle.createBaseColumn) Column(io.trino.plugin.hive.metastore.Column) ViewColumn(io.trino.spi.connector.ConnectorViewDefinition.ViewColumn) SortingColumn(io.trino.plugin.hive.metastore.SortingColumn) ConnectorTableLayout(io.trino.spi.connector.ConnectorTableLayout) ConnectorBucketNodeMap(io.trino.spi.connector.ConnectorBucketNodeMap) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 17 with ConnectorTableLayout

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

the class AbstractTestHive method testCreatePartitionedBucketedTableLayout.

@Test
public void testCreatePartitionedBucketedTableLayout() {
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        ConnectorSession session = newSession();
        Optional<ConnectorTableLayout> newTableLayout = metadata.getNewTableLayout(session, new ConnectorTableMetadata(new SchemaTableName("schema", "table"), ImmutableList.of(new ColumnMetadata("column1", BIGINT), new ColumnMetadata("column2", BIGINT)), ImmutableMap.of(PARTITIONED_BY_PROPERTY, ImmutableList.of("column2"), BUCKETED_BY_PROPERTY, ImmutableList.of("column1"), BUCKET_COUNT_PROPERTY, 10, SORTED_BY_PROPERTY, ImmutableList.of())));
        assertTrue(newTableLayout.isPresent());
        ConnectorPartitioningHandle partitioningHandle = new HivePartitioningHandle(BUCKETING_V1, 10, ImmutableList.of(HIVE_LONG), OptionalInt.empty(), true);
        assertEquals(newTableLayout.get().getPartitioning(), Optional.of(partitioningHandle));
        assertEquals(newTableLayout.get().getPartitionColumns(), ImmutableList.of("column1", "column2"));
        ConnectorBucketNodeMap connectorBucketNodeMap = nodePartitioningProvider.getBucketNodeMap(transaction.getTransactionHandle(), session, partitioningHandle);
        assertEquals(connectorBucketNodeMap.getBucketCount(), 32);
        assertTrue(connectorBucketNodeMap.hasFixedMapping());
        assertEquals(connectorBucketNodeMap.getFixedMapping().size(), 32);
    }
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ConnectorPartitioningHandle(io.trino.spi.connector.ConnectorPartitioningHandle) ConnectorTableLayout(io.trino.spi.connector.ConnectorTableLayout) ConnectorBucketNodeMap(io.trino.spi.connector.ConnectorBucketNodeMap) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 18 with ConnectorTableLayout

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

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")));
    ConnectorTableLayout layout = metadata.getNewTableLayout(SESSION, ordersTable).get();
    assertEquals(layout.getPartitionColumns(), ImmutableList.of("orderkey", "custkey"));
    assertTrue(layout.getPartitioning().isPresent());
    assertInstanceOf(layout.getPartitioning().get(), RaptorPartitioningHandle.class);
    RaptorPartitioningHandle partitioning = (RaptorPartitioningHandle) layout.getPartitioning().get();
    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(io.trino.spi.connector.ConnectorOutputTableHandle) RaptorTableHandle(io.trino.plugin.raptor.legacy.RaptorTableHandle) ConnectorTableLayout(io.trino.spi.connector.ConnectorTableLayout) RaptorPartitioningHandle(io.trino.plugin.raptor.legacy.RaptorPartitioningHandle) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

ConnectorTableLayout (io.trino.spi.connector.ConnectorTableLayout)18 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)11 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)10 ConnectorSession (io.trino.spi.connector.ConnectorSession)10 SchemaTableName (io.trino.spi.connector.SchemaTableName)10 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)8 ImmutableList (com.google.common.collect.ImmutableList)7 ConnectorPartitioningHandle (io.trino.spi.connector.ConnectorPartitioningHandle)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 Column (io.trino.plugin.hive.metastore.Column)6 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)6 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)6 Test (org.testng.annotations.Test)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 HiveColumnHandle.createBaseColumn (io.trino.plugin.hive.HiveColumnHandle.createBaseColumn)5 SortingColumn (io.trino.plugin.hive.metastore.SortingColumn)5 TrinoException (io.trino.spi.TrinoException)5 ConnectorOutputTableHandle (io.trino.spi.connector.ConnectorOutputTableHandle)5 TestingConnectorSession (io.trino.testing.TestingConnectorSession)5 Verify.verify (com.google.common.base.Verify.verify)4