use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class TestTypeConversions method testConvertOneLevelRecordField.
@Test
public void testConvertOneLevelRecordField() {
Field field = Field.of("rec", LegacySQLTypeName.RECORD, Field.of("sub_s", LegacySQLTypeName.STRING), Field.of("sub_i", LegacySQLTypeName.INTEGER));
ColumnMetadata metadata = Conversions.toColumnMetadata(field);
RowType targetType = RowType.rowType(RowType.field("sub_s", VarcharType.VARCHAR), RowType.field("sub_i", BigintType.BIGINT));
assertThat(metadata.getType()).isEqualTo(targetType);
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class SheetsMetadata method getColumnHandles.
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
SheetsTableHandle sheetsTableHandle = (SheetsTableHandle) tableHandle;
Optional<SheetsTable> table = sheetsClient.getTable(sheetsTableHandle.getTableName());
if (table.isEmpty()) {
throw new TableNotFoundException(sheetsTableHandle.toSchemaTableName());
}
ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
int index = 0;
for (ColumnMetadata column : table.get().getColumnsMetadata()) {
columnHandles.put(column.getName(), new SheetsColumnHandle(column.getName(), column.getType(), index));
index++;
}
return columnHandles.buildOrThrow();
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class AbstractTestHive method testCreateTableUnsupportedType.
@Test
public void testCreateTableUnsupportedType() {
for (HiveStorageFormat storageFormat : createTableFormats) {
try (Transaction transaction = newTransaction()) {
ConnectorSession session = newSession();
ConnectorMetadata metadata = transaction.getMetadata();
List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata("dummy", HYPER_LOG_LOG));
ConnectorTableMetadata tableMetadata = new ConnectorTableMetadata(invalidTable, columns, createTableProperties(storageFormat));
metadata.beginCreateTable(session, tableMetadata, Optional.empty(), NO_RETRIES);
fail("create table with unsupported type should fail for storage format " + storageFormat);
} catch (TrinoException e) {
assertEquals(e.getErrorCode(), NOT_SUPPORTED.toErrorCode());
}
}
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class AbstractTestHive method indexColumns.
protected static ImmutableMap<String, Integer> indexColumns(ConnectorTableMetadata tableMetadata) {
ImmutableMap.Builder<String, Integer> index = ImmutableMap.builder();
int i = 0;
for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
index.put(columnMetadata.getName(), i);
i++;
}
return index.buildOrThrow();
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class AbstractTestHive method testPreferredCreateTableLayout.
@Test
public void testPreferredCreateTableLayout() {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorSession session = newSession();
Optional<ConnectorTableLayout> newTableLayout = metadata.getNewTableLayout(session, new ConnectorTableMetadata(new SchemaTableName("schema", "table"), ImmutableList.of(new ColumnMetadata("column1", BIGINT), new ColumnMetadata("column2", BIGINT)), ImmutableMap.of(PARTITIONED_BY_PROPERTY, ImmutableList.of("column2"), BUCKETED_BY_PROPERTY, ImmutableList.of(), BUCKET_COUNT_PROPERTY, 0, SORTED_BY_PROPERTY, ImmutableList.of())));
assertTrue(newTableLayout.isPresent());
assertFalse(newTableLayout.get().getPartitioning().isPresent());
assertEquals(newTableLayout.get().getPartitionColumns(), ImmutableList.of("column2"));
}
}
Aggregations