use of io.prestosql.plugin.jdbc.JdbcColumnHandle in project hetu-core by openlookeng.
the class TestHanaClient method testRenameColumn.
/**
* testRenameColumn
*/
@Test
public void testRenameColumn() {
String schemaName = getNameByUpperCaseIdentifiers(database.getSchema());
// get actual table table_with_float_col_*
String tableName = getNameByUpperCaseIdentifiers(database.getActualTable("table_with_float_col"));
List<String> expectedColumns = Arrays.asList("col1", "col2", "col3", "col4");
List<String> actualColumns = getActualColumns(schemaName, tableName);
assertEquals(actualColumns, expectedColumns);
JdbcIdentity identity = JdbcIdentity.from(SESSION);
SchemaTableName schemaTableName = new SchemaTableName(schemaName, tableName);
JdbcTableHandle tableHandle = hanaClient.getTableHandle(identity, schemaTableName).get();
List<JdbcColumnHandle> columns = hanaClient.getColumns(SESSION, tableHandle);
JdbcColumnHandle columnHandle = null;
for (JdbcColumnHandle column : columns) {
if ("col4".equalsIgnoreCase(column.getColumnName())) {
columnHandle = column;
break;
}
}
hanaClient.renameColumn(identity, tableHandle, columnHandle, "newcol4");
expectedColumns = Arrays.asList("col1", "col2", "col3", "newcol4");
actualColumns = getActualColumns(schemaName, tableName);
assertEquals(actualColumns, expectedColumns);
}
use of io.prestosql.plugin.jdbc.JdbcColumnHandle in project hetu-core by openlookeng.
the class BasePostgreSqlClient method getColumns.
@Override
public List<JdbcColumnHandle> getColumns(ConnectorSession session, JdbcTableHandle tableHandle) {
try (Connection connection = connectionFactory.openConnection(JdbcIdentity.from(session))) {
Map<String, Integer> arrayColumnDimensions = getArrayColumnDimensions(connection, tableHandle);
try (ResultSet resultSet = optimizedGetColumns(connection, tableHandle)) {
List<JdbcColumnHandle> columns = new ArrayList<>();
while (resultSet.next()) {
String columnName = resultSet.getString("COLUMN_NAME");
JdbcTypeHandle typeHandle = new JdbcTypeHandle(resultSet.getInt("DATA_TYPE"), Optional.of(resultSet.getString("TYPE_NAME")), resultSet.getInt("COLUMN_SIZE"), resultSet.getInt("DECIMAL_DIGITS"), Optional.ofNullable(arrayColumnDimensions.get(columnName)));
Optional<ColumnMapping> columnMapping = toPrestoType(session, connection, typeHandle);
// skip unsupported column types
if (columnMapping.isPresent()) {
boolean nullable = (resultSet.getInt("NULLABLE") != columnNoNulls);
columns.add(new JdbcColumnHandle(columnName, typeHandle, columnMapping.get().getType(), nullable));
}
}
if (columns.isEmpty()) {
// In rare cases a table might have no columns.
throw new TableNotFoundException(tableHandle.getSchemaTableName());
}
return ImmutableList.copyOf(columns);
}
} catch (SQLException e) {
throw new PrestoException(JDBC_ERROR, e);
}
}
Aggregations