Search in sources :

Example 1 with ThriftHiveMetastoreClient

use of io.trino.plugin.hive.metastore.thrift.ThriftHiveMetastoreClient in project trino by trinodb.

the class TestHiveTransactionalTable method testFilesForAbortedTransactionsIgnored.

@Test(groups = HIVE_TRANSACTIONAL)
@Flaky(issue = "https://github.com/trinodb/trino/issues/5463", match = "Expected row count to be <4>, but was <6>")
public void testFilesForAbortedTransactionsIgnored() throws Exception {
    if (getHiveVersionMajor() < 3) {
        throw new SkipException("Hive transactional tables are supported with Hive version 3 or above");
    }
    String tableName = "test_aborted_transaction_table";
    onHive().executeQuery("" + "CREATE TABLE " + tableName + " (col INT) " + "STORED AS ORC " + "TBLPROPERTIES ('transactional'='true')");
    ThriftHiveMetastoreClient client = testHiveMetastoreClientFactory.createMetastoreClient();
    try {
        String selectFromOnePartitionsSql = "SELECT col FROM " + tableName + " ORDER BY COL";
        // Create `delta-A` file
        onHive().executeQuery("INSERT INTO TABLE " + tableName + " VALUES (1),(2)");
        QueryResult onePartitionQueryResult = onTrino().executeQuery(selectFromOnePartitionsSql);
        assertThat(onePartitionQueryResult).containsExactlyInOrder(row(1), row(2));
        String tableLocation = getTablePath(tableName);
        // Insert data to create a valid delta, which creates `delta-B`
        onHive().executeQuery("INSERT INTO TABLE " + tableName + " SELECT 3");
        // Simulate aborted transaction in Hive which has left behind a write directory and file (`delta-C` i.e `delta_0000003_0000003_0000`)
        long transaction = client.openTransaction("test");
        client.allocateTableWriteIds("default", tableName, Collections.singletonList(transaction)).get(0).getWriteId();
        client.abortTransaction(transaction);
        String deltaA = tableLocation + "/delta_0000001_0000001_0000";
        String deltaB = tableLocation + "/delta_0000002_0000002_0000";
        String deltaC = tableLocation + "/delta_0000003_0000003_0000";
        // Delete original `delta-B`, `delta-C`
        hdfsDeleteAll(deltaB);
        hdfsDeleteAll(deltaC);
        // Copy content of `delta-A` to `delta-B`
        hdfsCopyAll(deltaA, deltaB);
        // Verify that data from delta-A and delta-B is visible
        onePartitionQueryResult = onTrino().executeQuery(selectFromOnePartitionsSql);
        assertThat(onePartitionQueryResult).containsOnly(row(1), row(1), row(2), row(2));
        // Copy content of `delta-A` to `delta-C` (which is an aborted transaction)
        hdfsCopyAll(deltaA, deltaC);
        // Verify that delta, corresponding to aborted transaction, is not getting read
        onePartitionQueryResult = onTrino().executeQuery(selectFromOnePartitionsSql);
        assertThat(onePartitionQueryResult).containsOnly(row(1), row(1), row(2), row(2));
    } finally {
        client.close();
        onHive().executeQuery("DROP TABLE " + tableName);
    }
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) ThriftHiveMetastoreClient(io.trino.plugin.hive.metastore.thrift.ThriftHiveMetastoreClient) SkipException(org.testng.SkipException) Test(org.testng.annotations.Test) Flaky(io.trino.testng.services.Flaky)

Aggregations

ThriftHiveMetastoreClient (io.trino.plugin.hive.metastore.thrift.ThriftHiveMetastoreClient)1 QueryResult (io.trino.tempto.query.QueryResult)1 Flaky (io.trino.testng.services.Flaky)1 SkipException (org.testng.SkipException)1 Test (org.testng.annotations.Test)1