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);
}
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));
}
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));
}
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);
}
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);
}
Aggregations