Search in sources :

Example 86 with ColumnMetadata

use of io.trino.spi.connector.ColumnMetadata in project TiBigData by tidb-incubator.

the class TiDBPageSinkProvider method createTiDBPageSink.

private TiDBPageSink createTiDBPageSink(ConnectorSession session, TiDBTableHandle tiDBTableHandle) {
    final String schemaName = tiDBTableHandle.getSchemaName();
    final String tableName = tiDBTableHandle.getTableName();
    final List<ColumnMetadata> columns = metadata.getTableMetadata(null, tiDBTableHandle).getColumns();
    final List<String> columnNames = columns.stream().map(ColumnMetadata::getName).collect(ImmutableList.toImmutableList());
    final List<Type> columnTypes = columns.stream().map(ColumnMetadata::getType).collect(ImmutableList.toImmutableList());
    TiDBWriteMode writeMode = fromString(session.getProperty(SESSION_WRITE_MODE, String.class));
    Connection connection;
    try {
        connection = metadata.getInternal().getJdbcConnection();
    } catch (SQLException e) {
        throw new TrinoException(JDBC_ERROR, e);
    }
    return new TiDBPageSink(schemaName, tableName, columnNames, columnTypes, writeMode, connection);
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Type(io.trino.spi.type.Type) SQLException(java.sql.SQLException) Connection(java.sql.Connection) TrinoException(io.trino.spi.TrinoException) TiDBWriteMode(io.tidb.bigdata.tidb.TiDBWriteMode) TiDBWriteMode.fromString(io.tidb.bigdata.tidb.TiDBWriteMode.fromString)

Example 87 with ColumnMetadata

use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.

the class TestTypeConversions method testConvertStringArrayColumn.

@Test
public void testConvertStringArrayColumn() {
    BigQueryColumnHandle column = new BigQueryColumnHandle("test", BigQueryType.STRING, Field.Mode.REPEATED, null, null, ImmutableList.of(), null);
    ColumnMetadata metadata = column.getColumnMetadata();
    assertThat(metadata.getType()).isEqualTo(new ArrayType(VarcharType.VARCHAR));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Test(org.testng.annotations.Test)

Example 88 with ColumnMetadata

use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.

the class TestTypeConversions method testConvertStringArrayField.

@Test
public void testConvertStringArrayField() {
    Field field = Field.newBuilder("test", LegacySQLTypeName.STRING).setMode(Field.Mode.REPEATED).build();
    ColumnMetadata metadata = Conversions.toColumnMetadata(field);
    assertThat(metadata.getType()).isEqualTo(new ArrayType(VarcharType.VARCHAR));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Field(com.google.cloud.bigquery.Field) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Test(org.testng.annotations.Test)

Example 89 with ColumnMetadata

use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.

the class TestTypeConversions method assertSimpleColumnTypeConversion.

private static void assertSimpleColumnTypeConversion(LegacySQLTypeName from, Type to) {
    ColumnMetadata metadata = createColumn(from).getColumnMetadata();
    assertThat(metadata.getType()).isEqualTo(to);
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata)

Example 90 with ColumnMetadata

use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.

the class TestTypeConversions method testConvertTwoLevelsRecordField.

@Test
public void testConvertTwoLevelsRecordField() {
    Field field = Field.of("rec", LegacySQLTypeName.RECORD, Field.of("sub_rec", LegacySQLTypeName.RECORD, Field.of("sub_sub_s", LegacySQLTypeName.STRING), Field.of("sub_sub_i", LegacySQLTypeName.INTEGER)), Field.of("sub_s", LegacySQLTypeName.STRING), Field.of("sub_i", LegacySQLTypeName.INTEGER));
    ColumnMetadata metadata = Conversions.toColumnMetadata(field);
    RowType targetType = RowType.rowType(RowType.field("sub_rec", RowType.rowType(RowType.field("sub_sub_s", VarcharType.VARCHAR), RowType.field("sub_sub_i", BigintType.BIGINT))), 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)

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