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);
}
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();
}
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));
}
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");
}
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);
}
Aggregations