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);
}
}
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);
}
}
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));
}
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);
}
}
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"));
}
Aggregations