use of io.trino.tests.QueryTemplate in project trino by trinodb.
the class AbstractTestJoinQueries method testOuterJoinWithComplexCorrelatedSubquery.
@Test
public void testOuterJoinWithComplexCorrelatedSubquery() {
QueryTemplate.Parameter type = parameter("type");
QueryTemplate.Parameter condition = parameter("condition");
QueryTemplate queryTemplate = queryTemplate("SELECT * FROM (VALUES 1,2,3,4) t(x) %type% JOIN (VALUES 1,2,3,5) t2(y) ON %condition%", type, condition);
queryTemplate.replaceAll(query -> assertQueryFails(query, "line .*: Reference to column 'x' from outer scope not allowed in this context"), ImmutableList.of(type.of("left"), type.of("right"), type.of("full")), ImmutableList.of(condition.of("EXISTS(SELECT 1 WHERE x = y)"), condition.of("(SELECT x = y)"), condition.of("true IN (SELECT x = y)")));
}
use of io.trino.tests.QueryTemplate in project trino by trinodb.
the class AbstractTestJoinQueries method testJoinWithScalarSubqueryToBeExecutedAsPostJoinFilterWithEmptyInnerTable.
@Test
public void testJoinWithScalarSubqueryToBeExecutedAsPostJoinFilterWithEmptyInnerTable() {
String noOutputQuery = "SELECT 1 WHERE false";
QueryTemplate.Parameter type = parameter("type").of("");
QueryTemplate.Parameter condition = parameter("condition");
QueryTemplate queryTemplate = queryTemplate("SELECT * FROM (" + noOutputQuery + ") t(x) %type% JOIN (VALUES 1) t2(y) ON %condition%", type);
QueryTemplate.Parameter xPlusYEqualsSubqueryJoinCondition = condition.of("(x+y = (SELECT 4))");
assertQuery(queryTemplate.replace(xPlusYEqualsSubqueryJoinCondition), noOutputQuery);
assertQuery(queryTemplate.replace(condition.of("(x+y = (VALUES 4)) AND (x*y = (VALUES 4))")), noOutputQuery);
// non inner joins
assertQuery(queryTemplate.replace(xPlusYEqualsSubqueryJoinCondition, type.of("left")), noOutputQuery);
assertQuery(queryTemplate.replace(xPlusYEqualsSubqueryJoinCondition, type.of("right")), "VALUES (null,1)");
assertQuery(queryTemplate.replace(xPlusYEqualsSubqueryJoinCondition, type.of("full")), "VALUES (null,1)");
}
Aggregations