Search in sources :

Example 86 with ConnectorTableMetadata

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());
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) AtopColumn(io.trino.plugin.atop.AtopTable.AtopColumn) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Example 87 with ConnectorTableMetadata

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)));
}
Also used : ConnectorTableLayout(io.trino.spi.connector.ConnectorTableLayout) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 88 with ConnectorTableMetadata

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);
    }
}
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 89 with ConnectorTableMetadata

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"));
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 90 with ConnectorTableMetadata

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);
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) 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