Search in sources :

Example 91 with ColumnMetadata

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);
}
Also used : Field(com.google.cloud.bigquery.Field) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) RowType(io.trino.spi.type.RowType) Test(org.testng.annotations.Test)

Example 92 with ColumnMetadata

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();
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) ColumnHandle(io.trino.spi.connector.ColumnHandle) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 93 with ColumnMetadata

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());
        }
    }
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) StorageFormat.fromHiveStorageFormat(io.trino.plugin.hive.metastore.StorageFormat.fromHiveStorageFormat) TrinoException(io.trino.spi.TrinoException) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 94 with ColumnMetadata

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();
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) Constraint(io.trino.spi.connector.Constraint)

Example 95 with ColumnMetadata

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"));
    }
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ConnectorTableLayout(io.trino.spi.connector.ConnectorTableLayout) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Aggregations

ColumnMetadata (io.trino.spi.connector.ColumnMetadata)154 SchemaTableName (io.trino.spi.connector.SchemaTableName)75 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)73 Test (org.testng.annotations.Test)64 ImmutableList (com.google.common.collect.ImmutableList)63 ImmutableMap (com.google.common.collect.ImmutableMap)55 List (java.util.List)45 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)43 Optional (java.util.Optional)43 ConnectorSession (io.trino.spi.connector.ConnectorSession)41 TrinoException (io.trino.spi.TrinoException)38 ColumnHandle (io.trino.spi.connector.ColumnHandle)38 Map (java.util.Map)38 Type (io.trino.spi.type.Type)35 Constraint (io.trino.spi.connector.Constraint)32 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)31 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)30 BIGINT (io.trino.spi.type.BigintType.BIGINT)30 HashMap (java.util.HashMap)27 Set (java.util.Set)27