use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class TestRaptorMetadata method testSortOrderProperty.
@Test
public void testSortOrderProperty() {
assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(ORDERING_PROPERTY, ImmutableList.of("orderdate", "custkey")));
metadata.createTable(SESSION, ordersTable, false);
ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
assertInstanceOf(tableHandle, RaptorTableHandle.class);
RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
assertEquals(raptorTableHandle.getTableId(), 1);
long tableId = raptorTableHandle.getTableId();
MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
// verify sort columns
List<TableColumn> sortColumns = metadataDao.listSortColumns(tableId);
assertTableColumnsEqual(sortColumns, ImmutableList.of(new TableColumn(DEFAULT_TEST_ORDERS, "orderdate", DATE, 4, 3, OptionalInt.empty(), OptionalInt.of(0), false), new TableColumn(DEFAULT_TEST_ORDERS, "custkey", BIGINT, 2, 1, OptionalInt.empty(), OptionalInt.of(1), false)));
// verify temporal column is not set
assertEquals(metadataDao.getTemporalColumnId(tableId), null);
metadata.dropTable(SESSION, tableHandle);
}
use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class RedisMetadata method getTableMetadata.
@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
SchemaTableName schemaTableName = ((RedisTableHandle) tableHandle).toSchemaTableName();
ConnectorTableMetadata tableMetadata = getTableMetadata(schemaTableName);
if (tableMetadata == null) {
throw new TableNotFoundException(schemaTableName);
}
return tableMetadata;
}
use of io.trino.spi.connector.ConnectorTableMetadata in project TiBigData by tidb-incubator.
the class TiDBMetadata method createTable.
@Override
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting) {
List<ColumnMetadata> columns = tableMetadata.getColumns();
SchemaTableName table = tableMetadata.getTable();
String schemaName = table.getSchemaName();
String tableName = table.getTableName();
List<String> columnNames = columns.stream().map(ColumnMetadata::getName).collect(toImmutableList());
List<String> columnTypes = columns.stream().map(column -> TypeHelpers.toSqlString(column.getType())).collect(toImmutableList());
List<String> primaryKeyColumns = Arrays.stream(tableMetadata.getProperties().get(PRIMARY_KEY).toString().split(",")).filter(s -> !s.isEmpty()).collect(Collectors.toList());
checkArgument(columnNames.containsAll(primaryKeyColumns), "invalid primary key columns: " + primaryKeyColumns);
List<String> uniqueKeyColumns = Arrays.stream(tableMetadata.getProperties().get(UNIQUE_KEY).toString().split(",")).filter(s -> !s.isEmpty()).collect(Collectors.toList());
checkArgument(columnNames.containsAll(uniqueKeyColumns), "invalid unique key columns: " + uniqueKeyColumns);
getInternal().createTable(schemaName, tableName, columnNames, columnTypes, primaryKeyColumns, uniqueKeyColumns, ignoreExisting);
}
use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class BigQueryMetadata method createTable.
private void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata) {
SchemaTableName schemaTableName = tableMetadata.getTable();
String schemaName = schemaTableName.getSchemaName();
String tableName = schemaTableName.getTableName();
List<Field> fields = tableMetadata.getColumns().stream().map(column -> toField(column.getName(), column.getType())).collect(toImmutableList());
TableId tableId = TableId.of(schemaName, tableName);
TableDefinition tableDefinition = StandardTableDefinition.of(Schema.of(fields));
TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
bigQueryClientFactory.create(session).createTable(tableInfo);
}
use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class SheetsMetadata 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.getSchema())) {
Optional<ConnectorTableMetadata> tableMetadata = getTableMetadata(tableName);
// table can disappear during listing operation
if (tableMetadata.isPresent()) {
columns.put(tableName, tableMetadata.get().getColumns());
}
}
return columns.buildOrThrow();
}
Aggregations