use of io.trino.tempto.assertions.QueryAssert.Row in project trino by trinodb.
the class TestCsv method assertSelect.
private static void assertSelect(String query, String tableName) {
QueryResult expected = onTrino().executeQuery(format(query, "tpch.tiny.nation"));
List<Row> expectedRows = expected.rows().stream().map(columns -> row(columns.toArray())).collect(toImmutableList());
QueryResult actual = onTrino().executeQuery(format(query, tableName));
assertThat(actual).hasColumns(expected.getColumnTypes()).containsOnly(expectedRows);
}
use of io.trino.tempto.assertions.QueryAssert.Row in project trino by trinodb.
the class TestHiveCaching method testReadFromTable.
private void testReadFromTable(String tableNameSuffix) {
String cachedTableName = "hive.default.test_cache_read" + tableNameSuffix;
String nonCachedTableName = "hivenoncached.default.test_cache_read" + tableNameSuffix;
Row[] tableData = createTestTable(nonCachedTableName);
CacheStats beforeCacheStats = getCacheStats();
long initialRemoteReads = beforeCacheStats.getRemoteReads();
long initialCachedReads = beforeCacheStats.getCachedReads();
long initialNonLocalReads = beforeCacheStats.getNonLocalReads();
long initialAsyncDownloadedMb = beforeCacheStats.getAsyncDownloadedMb();
assertThat(onTrino().executeQuery("SELECT * FROM " + cachedTableName)).containsExactlyInOrder(tableData);
assertEventually(new Duration(20, SECONDS), () -> {
// first query via caching catalog should fetch remote data
CacheStats afterQueryCacheStats = getCacheStats();
assertGreaterThanOrEqual(afterQueryCacheStats.getAsyncDownloadedMb(), initialAsyncDownloadedMb + 5);
assertGreaterThan(afterQueryCacheStats.getRemoteReads(), initialRemoteReads);
assertEquals(afterQueryCacheStats.getCachedReads(), initialCachedReads);
assertEquals(afterQueryCacheStats.getNonLocalReads(), initialNonLocalReads);
});
assertEventually(new Duration(10, SECONDS), () -> {
CacheStats beforeQueryCacheStats = getCacheStats();
long beforeQueryCachedReads = beforeQueryCacheStats.getCachedReads();
long beforeQueryRemoteReads = beforeQueryCacheStats.getRemoteReads();
long beforeQueryNonLocalReads = beforeQueryCacheStats.getNonLocalReads();
assertThat(onTrino().executeQuery("SELECT * FROM " + cachedTableName)).containsExactlyInOrder(tableData);
// query via caching catalog should read exclusively from cache
CacheStats afterQueryCacheStats = getCacheStats();
assertGreaterThan(afterQueryCacheStats.getCachedReads(), beforeQueryCachedReads);
assertEquals(afterQueryCacheStats.getRemoteReads(), beforeQueryRemoteReads);
// all reads should be local as Trino would schedule splits on nodes with cached data
assertEquals(afterQueryCacheStats.getNonLocalReads(), beforeQueryNonLocalReads);
});
onTrino().executeQuery("DROP TABLE " + nonCachedTableName);
}
use of io.trino.tempto.assertions.QueryAssert.Row in project trino by trinodb.
the class TestHiveCaching method createTestTable.
/**
* Creates table with 5 text files that are larger than 1MB
*/
private Row[] createTestTable(String tableName) {
StringBuilder randomDataBuilder = new StringBuilder();
Random random = new Random();
for (int i = 0; i < 500_000; ++i) {
randomDataBuilder.append(random.nextInt(10));
}
String randomData = randomDataBuilder.toString();
onTrino().executeQuery("DROP TABLE IF EXISTS " + tableName);
onTrino().executeQuery("CREATE TABLE " + tableName + " (col varchar) WITH (format='TEXTFILE')");
for (int i = 0; i < NUMBER_OF_FILES; ++i) {
// use `format` to overcome SQL query length limit
onTrino().executeQuery("INSERT INTO " + tableName + " SELECT format('%1$s%1$s%1$s%1$s%1$s', '" + randomData + "')");
}
Row row = row(randomData.repeat(5));
return Collections.nCopies(NUMBER_OF_FILES, row).toArray(new Row[0]);
}
use of io.trino.tempto.assertions.QueryAssert.Row in project trino by trinodb.
the class TestHivePropertiesTable method testTrinoViewPropertiesTable.
@Test
public void testTrinoViewPropertiesTable() throws Exception {
onTrino().executeQuery("DROP TABLE IF EXISTS test_trino_view_properties_base");
onTrino().executeQuery("DROP VIEW IF EXISTS test_trino_view_properties");
onTrino().executeQuery("CREATE TABLE test_trino_view_properties_base (col INT)");
onTrino().executeQuery("CREATE VIEW test_trino_view_properties AS SELECT * FROM test_trino_view_properties_base");
assertThat(onTrino().executeQuery("SHOW COLUMNS FROM \"test_trino_view_properties$properties\"")).containsExactlyInOrder(row("comment", "varchar", "", ""), row("presto_query_id", "varchar", "", ""), row("presto_version", "varchar", "", ""), row("presto_view", "varchar", "", ""), row("transient_lastddltime", "varchar", "", ""), row("trino_created_by", "varchar", "", ""));
assertThat(onTrino().executeQuery("SELECT * FROM \"test_trino_view_properties$properties\"")).hasRowsCount(1).containsExactlyInOrder(new Row(getTablePropertiesOnHive("test_trino_view_properties")));
onTrino().executeQuery("DROP VIEW IF EXISTS test_trino_view_properties");
onTrino().executeQuery("DROP TABLE IF EXISTS test_trino_view_properties_base");
}
use of io.trino.tempto.assertions.QueryAssert.Row in project trino by trinodb.
the class TestHivePropertiesTable method testHiveViewPropertiesTable.
@Test(groups = HIVE_VIEWS)
public void testHiveViewPropertiesTable() throws Exception {
onTrino().executeQuery("DROP TABLE IF EXISTS test_hive_view_properties_base");
onTrino().executeQuery("DROP VIEW IF EXISTS test_hive_view_properties");
onTrino().executeQuery("CREATE TABLE test_hive_view_properties_base (col INT)");
onHive().executeQuery("CREATE VIEW test_hive_view_properties AS SELECT * FROM test_hive_view_properties_base");
// Use "contains" method because the table properties for Hive views aren't identical among testing environments
assertThat(onTrino().executeQuery("SHOW COLUMNS FROM \"test_hive_view_properties$properties\"")).contains(row("transient_lastddltime", "varchar", "", ""));
assertThat(onTrino().executeQuery("SELECT * FROM \"test_hive_view_properties$properties\"")).hasRowsCount(1).containsExactlyInOrder(new Row(getTablePropertiesOnHive("test_hive_view_properties")));
onTrino().executeQuery("DROP VIEW IF EXISTS test_hive_view_properties");
onTrino().executeQuery("DROP TABLE IF EXISTS test_hive_view_properties_base");
}
Aggregations