use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class AccumuloMetadata 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 TestExampleMetadata method getTableMetadata.
@Test
public void getTableMetadata() {
// known table
ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(SESSION, NUMBERS_TABLE_HANDLE);
assertEquals(tableMetadata.getTable(), new SchemaTableName("example", "numbers"));
assertEquals(tableMetadata.getColumns(), ImmutableList.of(new ColumnMetadata("text", createUnboundedVarcharType()), new ColumnMetadata("value", BIGINT)));
// unknown tables should produce null
assertNull(metadata.getTableMetadata(SESSION, new ExampleTableHandle("unknown", "unknown")));
assertNull(metadata.getTableMetadata(SESSION, new ExampleTableHandle("example", "unknown")));
assertNull(metadata.getTableMetadata(SESSION, new ExampleTableHandle("unknown", "numbers")));
}
use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class HiveMetadata method validateColumns.
private static void validateColumns(ConnectorTableMetadata tableMetadata) {
// Validate the name and the type of each column
for (ColumnMetadata column : tableMetadata.getColumns()) {
String columnName = column.getName();
if (columnName.startsWith(" ")) {
throw new TrinoException(NOT_SUPPORTED, format("Hive column names must not start with a space: '%s'", columnName));
}
if (columnName.endsWith(" ")) {
throw new TrinoException(NOT_SUPPORTED, format("Hive column names must not end with a space: '%s'", columnName));
}
if (columnName.contains(",")) {
throw new TrinoException(NOT_SUPPORTED, format("Hive column names must not contain commas: '%s'", columnName));
}
// validate type is supported
toHiveType(column.getType());
}
if (getHiveStorageFormat(tableMetadata.getProperties()) != HiveStorageFormat.CSV) {
return;
}
Set<String> partitionedBy = ImmutableSet.copyOf(getPartitionedBy(tableMetadata.getProperties()));
List<ColumnMetadata> unsupportedColumns = tableMetadata.getColumns().stream().filter(columnMetadata -> !partitionedBy.contains(columnMetadata.getName())).filter(columnMetadata -> !columnMetadata.getType().equals(createUnboundedVarcharType())).collect(toImmutableList());
if (!unsupportedColumns.isEmpty()) {
String joinedUnsupportedColumns = unsupportedColumns.stream().map(columnMetadata -> format("%s %s", columnMetadata.getName(), columnMetadata.getType())).collect(joining(", "));
throw new TrinoException(NOT_SUPPORTED, "Hive CSV storage format only supports VARCHAR (unbounded). Unsupported columns: " + joinedUnsupportedColumns);
}
}
use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class HiveMetadata method getTableMetadata.
@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle;
ConnectorTableMetadata tableMetadata = getTableMetadata(session, hiveTableHandle.getSchemaTableName());
return hiveTableHandle.getAnalyzeColumnNames().map(columnNames -> new ConnectorTableMetadata(tableMetadata.getTable(), tableMetadata.getColumns(), ImmutableMap.<String, Object>builder().putAll(tableMetadata.getProperties()).put(ANALYZE_COLUMNS_PROPERTY, columnNames).buildOrThrow(), tableMetadata.getComment())).orElse(tableMetadata);
}
use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.
the class TestKinesisTableDescriptionSupplier method testRelatedObjects.
@Test
public void testRelatedObjects() {
KinesisMetadata metadata = (KinesisMetadata) connector.getMetadata(SESSION, new ConnectorTransactionHandle() {
});
assertNotNull(metadata);
SchemaTableName tblName = new SchemaTableName("prod", "test_table");
List<String> schemas = metadata.listSchemaNames(null);
assertEquals(schemas.size(), 1);
assertEquals(schemas.get(0), "prod");
KinesisTableHandle tblHandle = metadata.getTableHandle(null, tblName);
assertNotNull(tblHandle);
assertEquals(tblHandle.getSchemaName(), "prod");
assertEquals(tblHandle.getTableName(), "test_table");
assertEquals(tblHandle.getStreamName(), "test_kinesis_stream");
assertEquals(tblHandle.getMessageDataFormat(), "json");
ConnectorTableMetadata tblMeta = metadata.getTableMetadata(null, tblHandle);
assertNotNull(tblMeta);
assertEquals(tblMeta.getTable().getSchemaName(), "prod");
assertEquals(tblMeta.getTable().getTableName(), "test_table");
List<ColumnMetadata> columnList = tblMeta.getColumns();
assertNotNull(columnList);
boolean foundServiceType = false;
boolean foundPartitionKey = false;
for (ColumnMetadata column : columnList) {
if (column.getName().equals("service_type")) {
foundServiceType = true;
assertEquals(column.getType().getDisplayName(), "varchar(20)");
}
if (column.getName().equals("_partition_key")) {
foundPartitionKey = true;
assertEquals(column.getType().getDisplayName(), "varchar");
}
}
assertTrue(foundServiceType);
assertTrue(foundPartitionKey);
}
Aggregations