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