-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-7440] Preserve correlated scope mapping in RelToSqlConverter #4828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11887,6 +11887,61 @@ public Sql schema(CalciteAssert.SchemaSpec schemaSpec) { | |
| sql(sql).schema(CalciteAssert.SchemaSpec.JDBC_SCOTT).ok(expected); | ||
| } | ||
|
|
||
| /** Test case for | ||
| * <a href="https://issues.apache.org/jira/browse/CALCITE-7440">[CALCITE-7440] | ||
| * RelToSqlConverter throws NPE when correlation scope is missing after | ||
| * semi-join rewrites.</a>. */ | ||
| @Test void testPostgresqlRoundTripCorrelatedProject() { | ||
| final String query = correlatedProjectQuery7440(); | ||
| final RuleSet rules = RuleSets.ofList(); | ||
| final String generated = sql(query).withPostgresql().optimize(rules, null).exec(); | ||
| try { | ||
| sql(generated).withPostgresql().exec(); | ||
| } catch (Exception e) { | ||
| throw new AssertionError( | ||
| "Generated SQL failed PostgreSQL round-trip validation:\n" | ||
| + generated, | ||
| e); | ||
| } | ||
| } | ||
|
|
||
| @Test void testPostgresqlRoundTripCorrelatedProjectWithSemiJoinRules() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran this test on the main branch, and strangely it passed. Could you check if your case can reproduce the problem you mentioned?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please take a look at my description; you may not have solved my problem. |
||
| final String query = correlatedProjectQuery7440(); | ||
|
|
||
| final RuleSet rules = | ||
| RuleSets.ofList(CoreRules.FILTER_SUB_QUERY_TO_MARK_CORRELATE, | ||
| CoreRules.PROJECT_SUB_QUERY_TO_MARK_CORRELATE, | ||
| CoreRules.MARK_TO_SEMI_OR_ANTI_JOIN_RULE, | ||
| CoreRules.SEMI_JOIN_JOIN_TRANSPOSE); | ||
|
|
||
| final String generated = sql(query).withPostgresql().optimize(rules, null).exec(); | ||
| try { | ||
| sql(generated).withPostgresql().exec(); | ||
| } catch (Exception e) { | ||
| throw new AssertionError( | ||
| "Generated SQL failed PostgreSQL round-trip validation:\n" | ||
| + generated, | ||
| e); | ||
| } | ||
| } | ||
|
|
||
| private static String correlatedProjectQuery7440() { | ||
| return "WITH product_keys AS (\n" | ||
| + " SELECT p.\"product_id\",\n" | ||
| + " (SELECT MAX(p3.\"product_id\")\n" | ||
| + " FROM \"foodmart\".\"product\" p3\n" | ||
| + " WHERE p3.\"product_id\" = p.\"product_id\") AS \"mx\"\n" | ||
| + " FROM \"foodmart\".\"product\" p\n" | ||
| + ")\n" | ||
| + "SELECT DISTINCT pk.\"product_id\"\n" | ||
| + "FROM product_keys pk\n" | ||
| + "LEFT JOIN \"foodmart\".\"product\" p2 USING (\"product_id\")\n" | ||
| + "WHERE pk.\"product_id\" IN (\n" | ||
| + " SELECT p4.\"product_id\"\n" | ||
| + " FROM \"foodmart\".\"product\" p4\n" | ||
| + ")"; | ||
| } | ||
|
|
||
| @Test void testNotBetween() { | ||
| Sql f = fixture().withConvertletTable(new SqlRexConvertletTable() { | ||
| @Override public @Nullable SqlRexConvertlet get(SqlCall call) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.