Skip to content

Commit 565cb6a

Browse files
committed
[CALCITE-7440] Add correlated-project regression coverage
1 parent 574216d commit 565cb6a

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11891,8 +11891,42 @@ public Sql schema(CalciteAssert.SchemaSpec schemaSpec) {
1189111891
* <a href="https://issues.apache.org/jira/browse/CALCITE-7440">[CALCITE-7440]
1189211892
* RelToSqlConverter throws NPE when correlation scope is missing after
1189311893
* semi-join rewrites.</a>. */
11894+
@Test void testPostgresqlRoundTripCorrelatedProject() {
11895+
final String query = correlatedProjectQuery7440();
11896+
final RuleSet rules = RuleSets.ofList();
11897+
final String generated = sql(query).withPostgresql().optimize(rules, null).exec();
11898+
try {
11899+
sql(generated).withPostgresql().exec();
11900+
} catch (Exception e) {
11901+
throw new AssertionError(
11902+
"Generated SQL failed PostgreSQL round-trip validation:\n"
11903+
+ generated,
11904+
e);
11905+
}
11906+
}
11907+
1189411908
@Test void testPostgresqlRoundTripCorrelatedProjectWithSemiJoinRules() {
11895-
final String query = "WITH product_keys AS (\n"
11909+
final String query = correlatedProjectQuery7440();
11910+
11911+
final RuleSet rules =
11912+
RuleSets.ofList(CoreRules.FILTER_SUB_QUERY_TO_MARK_CORRELATE,
11913+
CoreRules.PROJECT_SUB_QUERY_TO_MARK_CORRELATE,
11914+
CoreRules.MARK_TO_SEMI_OR_ANTI_JOIN_RULE,
11915+
CoreRules.SEMI_JOIN_JOIN_TRANSPOSE);
11916+
11917+
final String generated = sql(query).withPostgresql().optimize(rules, null).exec();
11918+
try {
11919+
sql(generated).withPostgresql().exec();
11920+
} catch (Exception e) {
11921+
throw new AssertionError(
11922+
"Generated SQL failed PostgreSQL round-trip validation:\n"
11923+
+ generated,
11924+
e);
11925+
}
11926+
}
11927+
11928+
private static String correlatedProjectQuery7440() {
11929+
return "WITH product_keys AS (\n"
1189611930
+ " SELECT p.\"product_id\",\n"
1189711931
+ " (SELECT MAX(p3.\"product_id\")\n"
1189811932
+ " FROM \"foodmart\".\"product\" p3\n"
@@ -11906,18 +11940,6 @@ public Sql schema(CalciteAssert.SchemaSpec schemaSpec) {
1190611940
+ " SELECT p4.\"product_id\"\n"
1190711941
+ " FROM \"foodmart\".\"product\" p4\n"
1190811942
+ ")";
11909-
11910-
final RuleSet rules = RuleSets.ofList();
11911-
11912-
final String generated = sql(query).withPostgresql().optimize(rules, null).exec();
11913-
try {
11914-
sql(generated).withPostgresql().exec();
11915-
} catch (Exception e) {
11916-
throw new AssertionError(
11917-
"Generated SQL failed PostgreSQL round-trip validation:\n"
11918-
+ generated,
11919-
e);
11920-
}
1192111943
}
1192211944

1192311945
@Test void testNotBetween() {

0 commit comments

Comments
 (0)