use of io.trino.testing.sql.TestView in project trino by trinodb.
the class BaseJdbcConnectorTest method testCancellation.
@Test(timeOut = 60_000)
public void testCancellation() throws Exception {
if (!hasBehavior(SUPPORTS_CANCELLATION)) {
throw new SkipException("Cancellation is not supported by given connector");
}
try (TestView sleepingView = createSleepingView(new Duration(1, MINUTES))) {
String query = "SELECT * FROM " + sleepingView.getName();
Future<?> future = executor.submit(() -> assertQueryFails(query, "Query killed. Message: Killed by test"));
QueryId queryId = getQueryId(query);
assertEventually(() -> assertRemoteQueryStatus(sleepingView.getName(), RUNNING));
assertUpdate(format("CALL system.runtime.kill_query(query_id => '%s', message => '%s')", queryId, "Killed by test"));
future.get();
assertEventually(() -> assertRemoteQueryStatus(sleepingView.getName(), CANCELLED));
}
}
use of io.trino.testing.sql.TestView in project trino by trinodb.
the class TestBigQueryConnectorTest method testRepeatCountAggregationView.
/**
* regression test for https://github.com/trinodb/trino/issues/6696
*/
@Test
public void testRepeatCountAggregationView() {
try (TestView view = new TestView(bigQuerySqlExecutor, "test.repeat_count_aggregation_view", "SELECT 1 AS col1")) {
assertQuery("SELECT count(*) FROM " + view.getName(), "VALUES (1)");
assertQuery("SELECT count(*) FROM " + view.getName(), "VALUES (1)");
}
}
use of io.trino.testing.sql.TestView in project trino by trinodb.
the class TestBigQueryCaseInsensitiveMapping method testNonLowerCaseViewName.
@Test
public void testNonLowerCaseViewName() throws Exception {
String bigQuerySchema = "SomeSchema_" + randomTableSuffix();
String trinoSchema = bigQuerySchema.toLowerCase(ENGLISH);
String namePrefix = format("%s.Test_Case", bigQuerySchema);
try (AutoCloseable schema = withSchema(bigQuerySchema);
TestView view = new TestView(bigQuerySqlExecutor, namePrefix, "SELECT 'a' AS lower_case_name, 'b' AS Mixed_Case_Name, 'c' AS UPPER_CASE_NAME")) {
String viewName = view.getName().substring(bigQuerySchema.length() + 1).toLowerCase(ENGLISH);
assertThat(computeActual("SHOW TABLES FROM " + trinoSchema).getOnlyColumn()).contains(viewName);
assertEquals(computeActual("SHOW COLUMNS FROM " + trinoSchema + "." + viewName).getMaterializedRows().stream().map(row -> row.getField(0)).collect(toImmutableSet()), ImmutableSet.of("lower_case_name", "mixed_case_name", "upper_case_name"));
assertQuery(format("SELECT table_name FROM information_schema.tables WHERE table_schema = '%s'", trinoSchema), format("VALUES '%s'", viewName));
assertQuery(format("SELECT column_name FROM information_schema.columns WHERE table_schema = '%s' AND table_name = '%s'", trinoSchema, viewName), "VALUES 'lower_case_name', 'mixed_case_name', 'upper_case_name'");
// Note: until https://github.com/trinodb/trino/issues/17 is resolved, this is *the* way to access the tables.
assertQuery("SELECT lower_case_name FROM " + view.getName(), "VALUES 'a'");
assertQuery("SELECT mixed_case_name FROM " + view.getName(), "VALUES 'b'");
assertQuery("SELECT upper_case_name FROM " + view.getName(), "VALUES 'c'");
assertQuery("SELECT upper_case_name FROM " + view.getName().toLowerCase(ENGLISH), "VALUES 'c'");
// TODO: test with INSERT and CTAS https://github.com/trinodb/trino/issues/6868, https://github.com/trinodb/trino/issues/6869
}
}
use of io.trino.testing.sql.TestView in project trino by trinodb.
the class TestBigQueryConnectorTest method testCountAggregationView.
@Test(description = "regression test for https://github.com/trinodb/trino/issues/5635")
public void testCountAggregationView() {
try (TestTable table = new TestTable(bigQuerySqlExecutor, "test.count_aggregation_table", "(a INT64, b INT64, c INT64)", List.of("1, 2, 3", "4, 5, 6"));
TestView view = new TestView(bigQuerySqlExecutor, "test.count_aggregation_view", "SELECT * FROM " + table.getName())) {
assertQuery("SELECT count(*) FROM " + view.getName(), "VALUES (2)");
assertQuery("SELECT count(*) FROM " + view.getName() + " WHERE a = 1", "VALUES (1)");
assertQuery("SELECT count(a) FROM " + view.getName() + " WHERE b = 2", "VALUES (1)");
}
}
Aggregations