Search in sources :

Example 41 with ConnectorTableMetadata

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

the class PrometheusMetadata 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();
    for (SchemaTableName tableName : listTables(session, prefix)) {
        ConnectorTableMetadata tableMetadata = getTableMetadata(tableName);
        // table can disappear during listing operation
        if (tableMetadata != null) {
            columns.put(tableName, tableMetadata.getColumns());
        }
    }
    return columns.buildOrThrow();
}
Also used : ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(io.trino.spi.connector.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Example 42 with ConnectorTableMetadata

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

the class TestRaptorConnector method createTable.

private long createTable(String name) {
    ConnectorTransactionHandle transaction = beginTransaction();
    connector.getMetadata(SESSION, transaction).createTable(SESSION, new ConnectorTableMetadata(new SchemaTableName("test", name), ImmutableList.of(new ColumnMetadata("id", BIGINT))), false);
    connector.commit(transaction);
    transaction = beginTransaction();
    ConnectorTableHandle tableHandle = getTableHandle(connector.getMetadata(SESSION, transaction), name);
    connector.commit(transaction);
    return ((RaptorTableHandle) tableHandle).getTableId();
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle)

Example 43 with ConnectorTableMetadata

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

the class TestRaptorConnector method assertSplitShard.

private void assertSplitShard(Type temporalType, String min, String max, int expectedSplits) throws Exception {
    ConnectorSession session = TestingConnectorSession.builder().setPropertyMetadata(new RaptorSessionProperties(new StorageManagerConfig()).getSessionProperties()).build();
    ConnectorTransactionHandle transaction = beginTransaction();
    connector.getMetadata(SESSION, transaction).createTable(SESSION, new ConnectorTableMetadata(new SchemaTableName("test", "test"), ImmutableList.of(new ColumnMetadata("id", BIGINT), new ColumnMetadata("time", temporalType)), ImmutableMap.of(TEMPORAL_COLUMN_PROPERTY, "time")), false);
    connector.commit(transaction);
    ConnectorTransactionHandle txn1 = beginTransaction();
    ConnectorTableHandle handle1 = getTableHandle(connector.getMetadata(SESSION, txn1), "test");
    ConnectorInsertTableHandle insertTableHandle = connector.getMetadata(SESSION, txn1).beginInsert(session, handle1);
    ConnectorPageSink raptorPageSink = connector.getPageSinkProvider().createPageSink(txn1, session, insertTableHandle);
    Object timestamp1 = null;
    Object timestamp2 = null;
    if (temporalType.equals(TIMESTAMP_MILLIS)) {
        timestamp1 = SqlTimestamp.newInstance(3, castToShortTimestamp(TIMESTAMP_MILLIS.getPrecision(), min), 0);
        timestamp2 = SqlTimestamp.newInstance(3, castToShortTimestamp(TIMESTAMP_MILLIS.getPrecision(), max), 0);
    } else if (temporalType.equals(DATE)) {
        timestamp1 = new SqlDate(parseDate(min));
        timestamp2 = new SqlDate(parseDate(max));
    }
    Page inputPage = MaterializedResult.resultBuilder(session, ImmutableList.of(BIGINT, temporalType)).row(1L, timestamp1).row(2L, timestamp2).build().toPage();
    raptorPageSink.appendPage(inputPage);
    Collection<Slice> shards = raptorPageSink.finish().get();
    assertEquals(shards.size(), expectedSplits);
    connector.getMetadata(session, txn1).dropTable(session, handle1);
    connector.commit(txn1);
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ConnectorInsertTableHandle(io.trino.spi.connector.ConnectorInsertTableHandle) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) Page(io.trino.spi.Page) SchemaTableName(io.trino.spi.connector.SchemaTableName) StorageManagerConfig(io.trino.plugin.raptor.legacy.storage.StorageManagerConfig) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Slice(io.airlift.slice.Slice) SqlDate(io.trino.spi.type.SqlDate) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) ConnectorPageSink(io.trino.spi.connector.ConnectorPageSink) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Example 44 with ConnectorTableMetadata

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

the class TpcdsMetadata method getColumnMetadata.

@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle) {
    ConnectorTableMetadata tableMetadata = getTableMetadata(session, tableHandle);
    String columnName = ((TpcdsColumnHandle) columnHandle).getColumnName();
    for (ColumnMetadata column : tableMetadata.getColumns()) {
        if (column.getName().equals(columnName)) {
            return column;
        }
    }
    throw new IllegalArgumentException(format("Table '%s' does not have column '%s'", tableMetadata.getTable(), columnName));
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Example 45 with ConnectorTableMetadata

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

the class TpcdsMetadata method getTableMetadata.

private static ConnectorTableMetadata getTableMetadata(String schemaName, Table tpcdsTable) {
    ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
    for (Column column : tpcdsTable.getColumns()) {
        columns.add(new ColumnMetadata(column.getName(), getTrinoType(column.getType())));
    }
    SchemaTableName tableName = new SchemaTableName(schemaName, tpcdsTable.getName());
    return new ConnectorTableMetadata(tableName, columns.build());
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Column(io.trino.tpcds.column.Column) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

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