use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class AtopMetadata method getTableMetadata.
@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
AtopTableHandle atopTableHandle = (AtopTableHandle) tableHandle;
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
for (AtopColumn column : atopTableHandle.getTable().getColumns()) {
columns.add(new ColumnMetadata(column.getName(), typeManager.getType(column.getType())));
}
SchemaTableName schemaTableName = new SchemaTableName(atopTableHandle.getSchema(), atopTableHandle.getTable().getName());
return new ConnectorTableMetadata(schemaTableName, columns.build());
}
use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class TestDeltaLakeMetadata method testGetInsertLayout.
@Test
public void testGetInsertLayout() {
DeltaLakeMetadata deltaLakeMetadata = deltaLakeMetadataFactory.create(SESSION.getIdentity());
ConnectorTableMetadata tableMetadata = newTableMetadata(ImmutableList.of(BIGINT_COLUMN_1, BIGINT_COLUMN_2), ImmutableList.of(BIGINT_COLUMN_1));
deltaLakeMetadata.createTable(SESSION, tableMetadata, false);
Optional<ConnectorTableLayout> insertLayout = deltaLakeMetadata.getInsertLayout(SESSION, deltaLakeMetadata.getTableHandle(SESSION, tableMetadata.getTable()));
assertThat(insertLayout).isPresent();
assertThat(insertLayout.get().getPartitioning()).isNotPresent();
assertThat(insertLayout.get().getPartitionColumns()).isEqualTo(getPartitionColumnNames(ImmutableList.of(BIGINT_COLUMN_1)));
}
use of io.trino.spi.connector.ConnectorTableMetadata 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);
}
}
use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class TestDefaultJdbcMetadata method getTableMetadata.
@Test
public void getTableMetadata() {
// known table
ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(SESSION, tableHandle);
assertEquals(tableMetadata.getTable(), new SchemaTableName("example", "numbers"));
assertEquals(tableMetadata.getColumns(), ImmutableList.of(// primary key is not null in H2
new ColumnMetadata("text", VARCHAR, false, null, null, false, emptyMap()), new ColumnMetadata("text_short", createVarcharType(32)), new ColumnMetadata("value", BIGINT)));
// escaping name patterns
JdbcTableHandle specialTableHandle = metadata.getTableHandle(SESSION, new SchemaTableName("exa_ple", "num_ers"));
ConnectorTableMetadata specialTableMetadata = metadata.getTableMetadata(SESSION, specialTableHandle);
assertEquals(specialTableMetadata.getTable(), new SchemaTableName("exa_ple", "num_ers"));
assertEquals(specialTableMetadata.getColumns(), ImmutableList.of(// primary key is not null in H2
new ColumnMetadata("te_t", VARCHAR, false, null, null, false, emptyMap()), new ColumnMetadata("va%ue", BIGINT)));
// unknown tables should produce null
unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("u", "numbers"), null, "unknown", "unknown"));
unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("example", "numbers"), null, "example", "unknown"));
unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("example", "numbers"), null, "unknown", "numbers"));
}
use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class TestJdbcClient method testRenameTable.
@Test
public void testRenameTable() {
String schemaName = "test_schema";
SchemaTableName oldTable = new SchemaTableName(schemaName, "foo");
SchemaTableName newTable = new SchemaTableName(schemaName, "bar");
ConnectorTableMetadata tableMetadata = new ConnectorTableMetadata(oldTable, ImmutableList.of(new ColumnMetadata("text", VARCHAR)));
jdbcClient.createSchema(session, schemaName);
jdbcClient.createTable(session, tableMetadata);
jdbcClient.renameTable(session, jdbcClient.getTableHandle(session, oldTable).get(), newTable);
jdbcClient.dropTable(session, jdbcClient.getTableHandle(session, newTable).get());
jdbcClient.dropSchema(session, schemaName);
assertThat(jdbcClient.getTableNames(session, Optional.empty())).doesNotContain(oldTable).doesNotContain(newTable);
assertThat(jdbcClient.getSchemaNames(session)).doesNotContain(schemaName);
}
Aggregations