use of io.prestosql.plugin.jdbc.JdbcIdentity in project hetu-core by openlookeng.
the class TestHanaClient method testDropColumn.
/**
* testDropColumn
*/
@Test
public void testDropColumn() {
String schemaName = getNameByUpperCaseIdentifiers(database.getSchema());
// get actual table example_*
String tableName = getNameByUpperCaseIdentifiers(database.getActualTable("example"));
List<String> expectedColumns = Arrays.asList("text", "text_short", "value");
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 ("value".equalsIgnoreCase(column.getColumnName())) {
columnHandle = column;
break;
}
}
hanaClient.dropColumn(identity, tableHandle, columnHandle);
expectedColumns = Arrays.asList("text", "text_short");
actualColumns = getActualColumns(schemaName, tableName);
assertEquals(actualColumns, expectedColumns);
}
use of io.prestosql.plugin.jdbc.JdbcIdentity in project hetu-core by openlookeng.
the class TestHanaClient method testRenameTable.
/**
* testRenameTable
*/
@Test
public void testRenameTable() {
String schemaName = getNameByUpperCaseIdentifiers(database.getSchema());
List<String> expectedTables = database.getTables();
List<String> allTables = getAllTables(schemaName);
List<String> actualTables = getActualTables(allTables, expectedTables);
assertEquals(actualTables, expectedTables);
// get actual table number_*
String actualTable = database.getActualTable("number");
String tableNumber = getNameByUpperCaseIdentifiers(actualTable);
String tableNewNumber = getNameByUpperCaseIdentifiers(actualTable.replace("number", "new_number"));
/* rename table number_* to new_number_* */
JdbcIdentity identity = JdbcIdentity.from(SESSION);
SchemaTableName newTableName = new SchemaTableName(schemaName, tableNewNumber);
hanaClient.renameTable(identity, catalogName, schemaName, tableNumber, newTableName);
// remove table "number_*"
expectedTables.remove(3);
// add table "new_number_*"
expectedTables.add(actualTable.replace("number", "new_number"));
allTables = getAllTables(schemaName);
actualTables = getActualTables(allTables, expectedTables);
assertEquals(actualTables, expectedTables);
/* rename table new_number_* to number_* */
newTableName = new SchemaTableName(schemaName, tableNumber);
hanaClient.renameTable(identity, catalogName, schemaName, tableNewNumber, newTableName);
// remove table "new_number"
expectedTables.remove(3);
// add table "number"
expectedTables.add(actualTable);
allTables = getAllTables(schemaName);
actualTables = getActualTables(allTables, expectedTables);
assertEquals(actualTables, expectedTables);
}
use of io.prestosql.plugin.jdbc.JdbcIdentity in project hetu-core by openlookeng.
the class ClickHouseClientTest method testAddColumn.
/**
* testAddColumn
*/
@Test
public void testAddColumn() throws NoSuchFieldException, IllegalAccessException {
String schemaName = getNameByUpperCaseIdentifiers(database.getSchema());
// get actual table student_*
String tableName = getNameByUpperCaseIdentifiers(database.getActualTable("student"));
List<String> expectedColumns = Arrays.asList("id");
List<String> actualColumns = getActualColumns(schemaName, tableName);
assertEquals(actualColumns, expectedColumns);
JdbcIdentity identity = JdbcIdentity.from(SESSION);
SchemaTableName schemaTableName = new SchemaTableName(schemaName, tableName);
JdbcTableHandle tableHandle = clickHouseClient.getTableHandle(identity, schemaTableName).get();
ColumnMetadata columnMetadata = new ColumnMetadata("name", VARCHAR);
Field field = JdbcTableHandle.class.getDeclaredField("catalogName");
field.setAccessible(true);
field.set(tableHandle, null);
clickHouseClient.addColumn(SESSION, tableHandle, columnMetadata);
expectedColumns = Arrays.asList("id", "name");
actualColumns = getActualColumns(schemaName, tableName);
assertEquals(actualColumns, expectedColumns);
}
use of io.prestosql.plugin.jdbc.JdbcIdentity in project hetu-core by openlookeng.
the class ClickHouseClientTest method testRenameColumn.
/**
* testRenameColumn
*/
@Test
public void testRenameColumn() throws NoSuchFieldException, IllegalAccessException {
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 = clickHouseClient.getTableHandle(identity, schemaTableName).get();
List<JdbcColumnHandle> columns = clickHouseClient.getColumns(SESSION, tableHandle);
JdbcColumnHandle columnHandle = null;
for (JdbcColumnHandle column : columns) {
if ("col4".equalsIgnoreCase(column.getColumnName())) {
columnHandle = column;
break;
}
}
Field field = JdbcTableHandle.class.getDeclaredField("catalogName");
field.setAccessible(true);
field.set(tableHandle, null);
clickHouseClient.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.JdbcIdentity in project hetu-core by openlookeng.
the class ClickHouseClientTest method testRenameTable.
@Test
public void testRenameTable() {
String schemaName = getNameByUpperCaseIdentifiers(database.getSchema());
List<String> expectedTables = database.getTables();
List<String> allTables = getAllTables(schemaName);
List<String> actualTables = getActualTables(allTables, expectedTables);
assertEquals(actualTables, expectedTables);
// get actual table number_*
String actualTable = database.getActualTable("number");
String tableNumber = getNameByUpperCaseIdentifiers(actualTable);
String tableNewNumber = getNameByUpperCaseIdentifiers(actualTable.replace("number", "new_number"));
/* rename table number_* to new_number_* */
JdbcIdentity identity = JdbcIdentity.from(SESSION);
SchemaTableName newTableName = new SchemaTableName(schemaName, tableNewNumber);
clickHouseClient.renameTable(identity, null, schemaName, tableNumber, newTableName);
// remove table "number_*"
expectedTables.remove(3);
// add table "new_number_*"
expectedTables.add(actualTable.replace("number", "new_number"));
allTables = getAllTables(schemaName);
actualTables = getActualTables(allTables, expectedTables);
assertEquals(actualTables, expectedTables);
/* rename table new_number_* to number_* */
newTableName = new SchemaTableName(schemaName, tableNumber);
clickHouseClient.renameTable(identity, null, schemaName, tableNewNumber, newTableName);
// remove table "new_number"
expectedTables.remove(3);
// add table "number"
expectedTables.add(actualTable);
allTables = getAllTables(schemaName);
actualTables = getActualTables(allTables, expectedTables);
assertEquals(actualTables, expectedTables);
}
Aggregations