Search in sources :

Example 1 with JdbcIdentity

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);
}
Also used : JdbcColumnHandle(io.prestosql.plugin.jdbc.JdbcColumnHandle) JdbcTableHandle(io.prestosql.plugin.jdbc.JdbcTableHandle) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) JdbcIdentity(io.prestosql.plugin.jdbc.JdbcIdentity) Test(org.testng.annotations.Test)

Example 2 with JdbcIdentity

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);
}
Also used : SchemaTableName(io.prestosql.spi.connector.SchemaTableName) JdbcIdentity(io.prestosql.plugin.jdbc.JdbcIdentity) Test(org.testng.annotations.Test)

Example 3 with JdbcIdentity

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);
}
Also used : Field(java.lang.reflect.Field) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) JdbcTableHandle(io.prestosql.plugin.jdbc.JdbcTableHandle) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) JdbcIdentity(io.prestosql.plugin.jdbc.JdbcIdentity) Test(org.testng.annotations.Test)

Example 4 with JdbcIdentity

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);
}
Also used : Field(java.lang.reflect.Field) JdbcColumnHandle(io.prestosql.plugin.jdbc.JdbcColumnHandle) JdbcTableHandle(io.prestosql.plugin.jdbc.JdbcTableHandle) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) JdbcIdentity(io.prestosql.plugin.jdbc.JdbcIdentity) Test(org.testng.annotations.Test)

Example 5 with JdbcIdentity

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);
}
Also used : SchemaTableName(io.prestosql.spi.connector.SchemaTableName) JdbcIdentity(io.prestosql.plugin.jdbc.JdbcIdentity) Test(org.testng.annotations.Test)

Aggregations

JdbcIdentity (io.prestosql.plugin.jdbc.JdbcIdentity)12 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)10 JdbcTableHandle (io.prestosql.plugin.jdbc.JdbcTableHandle)9 Test (org.testng.annotations.Test)9 JdbcColumnHandle (io.prestosql.plugin.jdbc.JdbcColumnHandle)4 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)4 PrestoException (io.prestosql.spi.PrestoException)3 Field (java.lang.reflect.Field)3 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 Type (io.prestosql.spi.type.Type)2 PreparedStatement (java.sql.PreparedStatement)2 ImmutableList (com.google.common.collect.ImmutableList)1 JdbcOutputTableHandle (io.prestosql.plugin.jdbc.JdbcOutputTableHandle)1 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)1 CharType (io.prestosql.spi.type.CharType)1 DecimalType (io.prestosql.spi.type.DecimalType)1 IntegerType (io.prestosql.spi.type.IntegerType)1 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)1 Varchars.isVarcharType (io.prestosql.spi.type.Varchars.isVarcharType)1