Search in sources :

Example 71 with QueryResult

use of io.trino.tempto.query.QueryResult 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)

Example 72 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestJdbc method shouldExecuteQueryWithSelectedCatalogAndSchema.

@Test(groups = JDBC)
@Requires(ImmutableNationTable.class)
public void shouldExecuteQueryWithSelectedCatalogAndSchema() throws SQLException {
    connection().setCatalog("hive");
    connection().setSchema("default");
    try (Statement statement = connection().createStatement()) {
        QueryResult result = queryResult(statement, "select * from nation");
        assertThat(result).matches(PRESTO_NATION_RESULT);
    }
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest) Requires(io.trino.tempto.Requires)

Example 73 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestJdbc method shouldGetTables.

@Test(groups = JDBC)
@Requires(ImmutableNationTable.class)
public void shouldGetTables() throws SQLException {
    QueryResult result = QueryResult.forResultSet(metaData().getTables("hive", null, null, null));
    assertThat(result).contains(row("hive", "default", "nation", "TABLE", null, null, null, null, null, null));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest) Requires(io.trino.tempto.Requires)

Example 74 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestJdbc method shouldExecuteQuery.

@Test(groups = JDBC)
@Requires(ImmutableNationTable.class)
public void shouldExecuteQuery() throws SQLException {
    try (Statement statement = connection().createStatement()) {
        QueryResult result = queryResult(statement, "select * from hive.default.nation");
        assertThat(result).matches(PRESTO_NATION_RESULT);
    }
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest) Requires(io.trino.tempto.Requires)

Example 75 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestJdbc method shouldGetTableTypes.

@Test(groups = JDBC)
@Requires(ImmutableNationTable.class)
public void shouldGetTableTypes() throws SQLException {
    QueryResult result = QueryResult.forResultSet(metaData().getTableTypes());
    assertThat(result).contains(row("TABLE"), row("VIEW"));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest) Requires(io.trino.tempto.Requires)

Aggregations

QueryResult (io.trino.tempto.query.QueryResult)84 Test (org.testng.annotations.Test)75 ProductTest (io.trino.tempto.ProductTest)61 Requires (io.trino.tempto.Requires)16 Row (io.trino.tempto.assertions.QueryAssert.Row)8 BigDecimal (java.math.BigDecimal)8 Duration (io.airlift.units.Duration)7 Flaky (io.trino.testng.services.Flaky)6 Statement (java.sql.Statement)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 QueryExecutionException (io.trino.tempto.query.QueryExecutionException)4 PreparedStatement (java.sql.PreparedStatement)4 ImmutableList (com.google.common.collect.ImmutableList)3 Row.row (io.trino.tempto.assertions.QueryAssert.Row.row)3 QueryAssert.assertThat (io.trino.tempto.assertions.QueryAssert.assertThat)3 List (java.util.List)3 Inject (com.google.inject.Inject)2 HiveTimestampPrecision (io.trino.plugin.hive.HiveTimestampPrecision)2 HMS_ONLY (io.trino.tests.product.TestGroups.HMS_ONLY)2 STORAGE_FORMATS (io.trino.tests.product.TestGroups.STORAGE_FORMATS)2