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