Search in sources :

Example 96 with ConnectorTableMetadata

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

the class TestShardMetadataRecordCursor method setup.

@BeforeMethod
public void setup() {
    dbi = createTestingJdbi();
    this.dummyHandle = dbi.open();
    createTablesWithRetry(dbi);
    this.metadata = new RaptorMetadata(dbi, createShardManager(dbi));
    // Create table
    ConnectorTableMetadata table = tableMetadataBuilder(DEFAULT_TEST_ORDERS).column("orderkey", BIGINT).column("orderdate", DATE).property("temporal_column", "orderdate").build();
    createTable(table);
}
Also used : RaptorMetadata(io.trino.plugin.raptor.legacy.RaptorMetadata) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 97 with ConnectorTableMetadata

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

the class RedisMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    List<SchemaTableName> tableNames;
    if (prefix.getTable().isEmpty()) {
        tableNames = listTables(session, prefix.getSchema());
    } else {
        tableNames = ImmutableList.of(prefix.toSchemaTableName());
    }
    for (SchemaTableName tableName : tableNames) {
        ConnectorTableMetadata tableMetadata = getTableMetadata(tableName);
        // table can disappear during listing operation
        if (tableMetadata != null) {
            columns.put(tableName, tableMetadata.getColumns());
        }
    }
    return columns.buildOrThrow();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SchemaTableName(io.trino.spi.connector.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Example 98 with ConnectorTableMetadata

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

the class TestRaptorMetadata method testCreateBucketedTable.

@Test
public void testCreateBucketedTable() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(BUCKET_COUNT_PROPERTY, 16, BUCKETED_ON_PROPERTY, ImmutableList.of("custkey", "orderkey")));
    metadata.createTable(SESSION, ordersTable, false);
    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, "custkey", BIGINT, 2, 1, OptionalInt.of(0), OptionalInt.empty(), false), new TableColumn(DEFAULT_TEST_ORDERS, "orderkey", BIGINT, 1, 0, OptionalInt.of(1), OptionalInt.empty(), false)));
    assertEquals(raptorTableHandle.getBucketCount(), OptionalInt.of(16));
    assertEquals(getTableDistributionId(tableId), Long.valueOf(1));
    metadata.dropTable(SESSION, tableHandle);
    // create a new table and verify it has a different distribution
    metadata.createTable(SESSION, ordersTable, false);
    tableId = ((RaptorTableHandle) metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS)).getTableId();
    assertEquals(tableId, 2);
    assertEquals(getTableDistributionId(tableId), Long.valueOf(2));
}
Also used : RaptorTableHandle(io.trino.plugin.raptor.legacy.RaptorTableHandle) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 99 with ConnectorTableMetadata

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

the class TestRaptorMetadata method testDropColumnDisallowed.

@Test
public void testDropColumnDisallowed() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    Map<String, Object> properties = ImmutableMap.of(BUCKET_COUNT_PROPERTY, 16, BUCKETED_ON_PROPERTY, ImmutableList.of("orderkey"), ORDERING_PROPERTY, ImmutableList.of("totalprice"), TEMPORAL_COLUMN_PROPERTY, "orderdate");
    ConnectorTableMetadata ordersTable = buildTable(properties, tableMetadataBuilder(DEFAULT_TEST_ORDERS).column("orderkey", BIGINT).column("totalprice", DOUBLE).column("orderdate", DATE).column("highestid", BIGINT));
    metadata.createTable(SESSION, ordersTable, false);
    ConnectorTableHandle ordersTableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(ordersTableHandle, RaptorTableHandle.class);
    RaptorTableHandle ordersRaptorTableHandle = (RaptorTableHandle) ordersTableHandle;
    assertEquals(ordersRaptorTableHandle.getTableId(), 1);
    assertInstanceOf(ordersRaptorTableHandle, RaptorTableHandle.class);
    // disallow dropping bucket, sort, temporal and highest-id columns
    ColumnHandle bucketColumn = metadata.getColumnHandles(SESSION, ordersRaptorTableHandle).get("orderkey");
    assertThatThrownBy(() -> metadata.dropColumn(SESSION, ordersTableHandle, bucketColumn)).isInstanceOf(TrinoException.class).hasMessage("Cannot drop bucket columns");
    ColumnHandle sortColumn = metadata.getColumnHandles(SESSION, ordersRaptorTableHandle).get("totalprice");
    assertThatThrownBy(() -> metadata.dropColumn(SESSION, ordersTableHandle, sortColumn)).isInstanceOf(TrinoException.class).hasMessage("Cannot drop sort columns");
    ColumnHandle temporalColumn = metadata.getColumnHandles(SESSION, ordersRaptorTableHandle).get("orderdate");
    assertThatThrownBy(() -> metadata.dropColumn(SESSION, ordersTableHandle, temporalColumn)).isInstanceOf(TrinoException.class).hasMessage("Cannot drop the temporal column");
    ColumnHandle highestColumn = metadata.getColumnHandles(SESSION, ordersRaptorTableHandle).get("highestid");
    assertThatThrownBy(() -> metadata.dropColumn(SESSION, ordersTableHandle, highestColumn)).isInstanceOf(TrinoException.class).hasMessage("Cannot drop the column which has the largest column ID in the table");
}
Also used : RaptorColumnHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) RaptorTableHandle(io.trino.plugin.raptor.legacy.RaptorTableHandle) TrinoException(io.trino.spi.TrinoException) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 100 with ConnectorTableMetadata

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

the class TestRaptorMetadata method testTemporalColumn.

@Test
public void testTemporalColumn() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(TEMPORAL_COLUMN_PROPERTY, "orderdate"));
    metadata.createTable(SESSION, ordersTable, false);
    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);
    // verify sort columns are not set
    List<TableColumn> sortColumns = metadataDao.listSortColumns(tableId);
    assertEquals(sortColumns.size(), 0);
    assertEquals(sortColumns, ImmutableList.of());
    // verify temporal column is set
    assertEquals(metadataDao.getTemporalColumnId(tableId), Long.valueOf(4));
    metadata.dropTable(SESSION, tableHandle);
}
Also used : RaptorTableHandle(io.trino.plugin.raptor.legacy.RaptorTableHandle) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)113 SchemaTableName (io.trino.spi.connector.SchemaTableName)69 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)62 Test (org.testng.annotations.Test)48 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)39 ConnectorSession (io.trino.spi.connector.ConnectorSession)35 ImmutableList (com.google.common.collect.ImmutableList)34 List (java.util.List)32 ImmutableMap (com.google.common.collect.ImmutableMap)31 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)30 ColumnHandle (io.trino.spi.connector.ColumnHandle)25 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)24 ConnectorOutputTableHandle (io.trino.spi.connector.ConnectorOutputTableHandle)20 Optional (java.util.Optional)20 TrinoException (io.trino.spi.TrinoException)19 Map (java.util.Map)19 Type (io.trino.spi.type.Type)18 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)17 Constraint (io.trino.spi.connector.Constraint)17 ImmutableSet (com.google.common.collect.ImmutableSet)16