Search in sources :

Example 6 with TemporaryHiveTable

use of io.trino.tests.product.hive.util.TemporaryHiveTable in project trino by trinodb.

the class TestHivePartitionSchemaEvolution method createTable.

private TemporaryHiveTable createTable(String format) {
    String tableName = "schema_evolution_" + randomTableSuffix();
    tryExecuteOnHive(format("CREATE TABLE %s (" + "  int_column int," + "  float_column float," + "  varchar_column varchar(20)" + ") " + "PARTITIONED BY (partition_column bigint) " + "STORED AS %s " + (createTablesAsAcid ? "TBLPROPERTIES ('transactional_properties' = 'none', 'transactional' = 'false')" : ""), tableName, format));
    TemporaryHiveTable temporaryHiveTable = temporaryHiveTable(tableName);
    try {
        onTrino().executeQuery(format("INSERT INTO %s VALUES (1, 1.1, 'jeden', 1)", tableName));
    } catch (Exception e) {
        temporaryHiveTable.closeQuietly(e);
        throw e;
    }
    return temporaryHiveTable;
}
Also used : TemporaryHiveTable(io.trino.tests.product.hive.util.TemporaryHiveTable) QueryExecutionException(io.trino.tempto.query.QueryExecutionException) SQLException(java.sql.SQLException)

Example 7 with TemporaryHiveTable

use of io.trino.tests.product.hive.util.TemporaryHiveTable in project trino by trinodb.

the class TestHivePartitionSchemaEvolution method test.

private void test(Supplier<TemporaryHiveTable> temporaryHiveTableSupplier) {
    try (TemporaryHiveTable table = temporaryHiveTableSupplier.get()) {
        // dropping column on table, simulates creating a column on partition
        // adding column on table, simulates dropping a column on partition
        // partition is adding a column at the start
        testEvolution(table, "ALTER TABLE %s REPLACE COLUMNS (float_column float, varchar_column varchar(20))", row(1.1, "jeden", 1));
        // partition is adding a column in the middle
        testEvolution(table, "ALTER TABLE %s REPLACE COLUMNS (int_column int, varchar_column varchar(20))", row(1, "jeden", 1));
        // partition is adding a column at the end
        testEvolution(table, "ALTER TABLE %s REPLACE COLUMNS (int_column int, float_column float)", row(1, 1.1, 1));
        // partition is dropping a column at the start
        testEvolution(table, "ALTER TABLE %s REPLACE COLUMNS (tiny_column tinyint, int_column int, float_column float, varchar_column varchar(20))", row(null, 1, 1.1, "jeden", 1));
        // partition is dropping a column in the middle
        testEvolution(table, "ALTER TABLE %s REPLACE COLUMNS (int_column int, tiny_column tinyint, float_column float, varchar_column varchar(20))", row(1, null, 1.1, "jeden", 1));
        // partition is dropping a column at the end
        testEvolution(table, "ALTER TABLE %s REPLACE COLUMNS (int_column int, float_column float, varchar_column varchar(20), tiny_column tinyint)", row(1, 1.1, "jeden", null, 1));
        // partition is dropping and adding column in the middle
        testEvolution(table, "ALTER TABLE %s REPLACE COLUMNS (int_column int, tiny_column tinyint, varchar_column varchar(20))", row(1, null, "jeden", 1));
        // partition is adding coercions
        testEvolution(table, "ALTER TABLE %s REPLACE COLUMNS (int_column bigint, float_column double, varchar_column varchar(20))", row(1, 1.1, "jeden", 1));
        // partition is swapping columns with coercions
        testEvolution(table, "ALTER TABLE %s REPLACE COLUMNS (varchar_column varchar(20), float_column double, int_column bigint)", row("jeden", 1.1, 1, 1));
        // partition is swapping columns and partition with coercions and is adding a column
        testEvolution(table, "ALTER TABLE %s REPLACE COLUMNS (float_column double, int_column bigint)", row(1.1, 1, 1));
        // partition is swapping columns and partition with coercions and is removing a column
        testEvolution(table, "ALTER TABLE %s REPLACE COLUMNS (varchar_column varchar(20), tiny_column tinyint, float_column double, int_column bigint)", row("jeden", null, 1.1, 1, 1));
    }
}
Also used : TemporaryHiveTable(io.trino.tests.product.hive.util.TemporaryHiveTable)

Aggregations

TemporaryHiveTable (io.trino.tests.product.hive.util.TemporaryHiveTable)7 SkipException (org.testng.SkipException)4 Test (org.testng.annotations.Test)3 Duration (io.airlift.units.Duration)2 QueryExecutionException (io.trino.tempto.query.QueryExecutionException)1 QueryResult (io.trino.tempto.query.QueryResult)1 Flaky (io.trino.testng.services.Flaky)1 SQLException (java.sql.SQLException)1