Search in sources :

Example 46 with ConnectorTableMetadata

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

the class TpcdsMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> tableColumns = ImmutableMap.builder();
    for (String schemaName : getSchemaNames(session, prefix.getSchema())) {
        for (Table tpcdsTable : Table.getBaseTables()) {
            if (prefix.getTable().map(tpcdsTable.getName()::equals).orElse(true)) {
                ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpcdsTable);
                tableColumns.put(new SchemaTableName(schemaName, tpcdsTable.getName()), tableMetadata.getColumns());
            }
        }
    }
    return tableColumns.buildOrThrow();
}
Also used : Table(io.trino.tpcds.Table) 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 47 with ConnectorTableMetadata

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

the class TpchMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> tableColumns = ImmutableMap.builder();
    for (String schemaName : getSchemaNames(session, prefix.getSchema())) {
        for (TpchTable<?> tpchTable : TpchTable.getTables()) {
            if (prefix.getTable().map(tpchTable.getTableName()::equals).orElse(true)) {
                ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpchTable, columnNaming);
                tableColumns.put(new SchemaTableName(schemaName, tpchTable.getTableName()), tableMetadata.getColumns());
            }
        }
    }
    return tableColumns.buildOrThrow();
}
Also used : Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) SchemaTableName(io.trino.spi.connector.SchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Example 48 with ConnectorTableMetadata

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

the class TpchMetadata method getColumnMetadata.

@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle) {
    ConnectorTableMetadata tableMetadata = getTableMetadata(session, tableHandle);
    String columnName = ((TpchColumnHandle) 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 49 with ConnectorTableMetadata

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

the class TpchMetadata method getTableMetadata.

private ConnectorTableMetadata getTableMetadata(String schemaName, TpchTable<?> tpchTable, ColumnNaming columnNaming) {
    ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
    columns.add(ColumnMetadata.builder().setName(ROW_NUMBER_COLUMN_NAME).setType(BIGINT).setHidden(true).build());
    for (TpchColumn<? extends TpchEntity> column : tpchTable.getColumns()) {
        columns.add(ColumnMetadata.builder().setName(columnNaming.getName(column)).setType(getTrinoType(column, decimalTypeMapping)).setNullable(false).build());
    }
    SchemaTableName tableName = new SchemaTableName(schemaName, tpchTable.getTableName());
    return new ConnectorTableMetadata(tableName, columns.build());
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(io.trino.spi.connector.SchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Example 50 with ConnectorTableMetadata

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

the class TestTpchMetadata method testGetTableMetadata.

private void testGetTableMetadata(String schema, TpchTable<?> table) {
    TpchTableHandle tableHandle = tpchMetadata.getTableHandle(session, new SchemaTableName(schema, table.getTableName()));
    ConnectorTableMetadata tableMetadata = tpchMetadata.getTableMetadata(session, tableHandle);
    assertEquals(tableMetadata.getTableSchema().getTable().getTableName(), table.getTableName());
    assertEquals(tableMetadata.getTableSchema().getTable().getSchemaName(), schema);
}
Also used : 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