Skip to content

Add more tests to TablesNamesFinderTest for SubqueryAliasesIssue1987 #2154

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

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@
/nbproject/

/.gradle

# Mac
.DS_Store
69 changes: 69 additions & 0 deletions src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,75 @@ void testSubqueryAliasesIssue1987() throws JSQLParserException {
tables = TablesNamesFinder.findTables(sqlStr);
assertThat(tables).containsExactlyInAnyOrder("a", "b");
assertThat(tables).doesNotContain("a1");

sqlStr = "select (a_alias.col1), b_alias.col2\n" +
"from b b_alias, a as a_alias, c join b on c.id = b.id\n" +
"where b_alias.id = a_alias.id and c.id = b_alias.id";
tables = TablesNamesFinder.findTables(sqlStr);
assertThat(tables).containsExactlyInAnyOrder("a", "b", "c");

sqlStr = "with\n" +
"temp1 as (( select * from b )),\n" +
"temp2 as ( select (((temp1_alias1.id))) from temp1 temp1_alias1 )\n" +
"select a_alias.col1, temp1_alias2.col2\n" +
"from temp1 temp1_alias2, a as a_alias, temp2 join c c_alias on c_alias.id = temp2.id\n"
+
"where c.id = temp1_alias2.id";
tables = TablesNamesFinder.findTables(sqlStr);
assertThat(tables).containsExactlyInAnyOrder("a", "b", "c");

sqlStr = "select a.id, (select max(val) from e) as maxval\n" +
"from a, (select * from b, (select * from c) c_alias) as bc_nested\n" +
" where a.id in ( select id from bc_nested join (select * from d) d_alias on bc_nested.id = d_alias.id ) \n"
+
" and a.max > (select max(val) from bc_nested, f) and a.desc like 'abc'";
tables = TablesNamesFinder.findTables(sqlStr);
assertThat(tables).containsExactlyInAnyOrder("a", "b", "c", "d", "e", "f");

sqlStr = " select (select max(val) from e) as maxval, id\n" +
" from (select * from b, (select * from c) c_alias) as bc_nested, a\n" +
" where a.max > (select max(val) from bc_nested, f) and \n" +
" a.id in ( select id from (select * from d) d_alias join bc_nested on bc_nested.id = d_alias.id )";
tables = TablesNamesFinder.findTables(sqlStr);
assertThat(tables).containsExactlyInAnyOrder("a", "b", "c", "d", "e", "f");

sqlStr = "select a.id, bc_nested.id\n" +
" from (select * from b, (select * from c) c_alias) as bc_nested, a\n" +
" where a.id in (((\n" +
" select id from d join \n" +
" (select * from bc_nested join \n" +
" (select * from e) e_alias on bc_nested.id = e_alias.id\n" +
" ) bc_nested_alias \n" +
" on bc_nested_alias.id = d.id\n" +
" )))";
tables = TablesNamesFinder.findTables(sqlStr);
assertThat(tables).containsExactlyInAnyOrder("a", "b", "c", "d", "e");

sqlStr = "select id\n" +
"from (select * from c, (select * from b) b_alias) as bc_nested, a\n" +
"where a.id in (\n" +
"select id from (select * from d \n" +
"join (select * from e) e_alias on d.id = e_alias.id) bc_nested_alias\n" +
"join bc_nested on bc_nested_alias.id = bc_nested.id\n" +
")";
tables = TablesNamesFinder.findTables(sqlStr);
assertThat(tables).containsExactlyInAnyOrder("a", "b", "c", "d", "e");

sqlStr = "with\n" +
" temp1 as (\n" +
" select a1.id as id, b.content as content from a a1\n" +
" join b on a1.id = b.id\n" +
" ),\n" +
" temp2 as (\n" +
" select b.id as id, b.value as value from b, c cross join temp1 where\n" +
" b.id = c.id and b.value = \"b.value\"\n" +
" )\n" +
"select temp1.id, ( select tid from d where cid = 29974 ) as tid \n" +
"from ( select tid from e, (select * from f) where cid = 29974) e_alias, temp1 cross join temp2\n"
+
"where exist ( select * from e, e_alias where e.test = dtest.test ) and temp1.max = (select max(column_1) from g)";
tables = TablesNamesFinder.findTables(sqlStr);
assertThat(tables).containsExactlyInAnyOrder("a", "b", "c", "d", "e", "f", "g");
}

@Test
Expand Down
Loading