@@ -505,6 +505,75 @@ void testSubqueryAliasesIssue1987() throws JSQLParserException {
505
505
tables = TablesNamesFinder .findTables (sqlStr );
506
506
assertThat (tables ).containsExactlyInAnyOrder ("a" , "b" );
507
507
assertThat (tables ).doesNotContain ("a1" );
508
+
509
+ sqlStr = "select (a_alias.col1), b_alias.col2\n " +
510
+ "from b b_alias, a as a_alias, c join b on c.id = b.id\n " +
511
+ "where b_alias.id = a_alias.id and c.id = b_alias.id" ;
512
+ tables = TablesNamesFinder .findTables (sqlStr );
513
+ assertThat (tables ).containsExactlyInAnyOrder ("a" , "b" , "c" );
514
+
515
+ sqlStr = "with\n " +
516
+ "temp1 as (( select * from b )),\n " +
517
+ "temp2 as ( select (((temp1_alias1.id))) from temp1 temp1_alias1 )\n " +
518
+ "select a_alias.col1, temp1_alias2.col2\n " +
519
+ "from temp1 temp1_alias2, a as a_alias, temp2 join c c_alias on c_alias.id = temp2.id\n "
520
+ +
521
+ "where c.id = temp1_alias2.id" ;
522
+ tables = TablesNamesFinder .findTables (sqlStr );
523
+ assertThat (tables ).containsExactlyInAnyOrder ("a" , "b" , "c" );
524
+
525
+ sqlStr = "select a.id, (select max(val) from e) as maxval\n " +
526
+ "from a, (select * from b, (select * from c) c_alias) as bc_nested\n " +
527
+ " where a.id in ( select id from bc_nested join (select * from d) d_alias on bc_nested.id = d_alias.id ) \n "
528
+ +
529
+ " and a.max > (select max(val) from bc_nested, f) and a.desc like 'abc'" ;
530
+ tables = TablesNamesFinder .findTables (sqlStr );
531
+ assertThat (tables ).containsExactlyInAnyOrder ("a" , "b" , "c" , "d" , "e" , "f" );
532
+
533
+ sqlStr = " select (select max(val) from e) as maxval, id\n " +
534
+ " from (select * from b, (select * from c) c_alias) as bc_nested, a\n " +
535
+ " where a.max > (select max(val) from bc_nested, f) and \n " +
536
+ " a.id in ( select id from (select * from d) d_alias join bc_nested on bc_nested.id = d_alias.id )" ;
537
+ tables = TablesNamesFinder .findTables (sqlStr );
538
+ assertThat (tables ).containsExactlyInAnyOrder ("a" , "b" , "c" , "d" , "e" , "f" );
539
+
540
+ sqlStr = "select a.id, bc_nested.id\n " +
541
+ " from (select * from b, (select * from c) c_alias) as bc_nested, a\n " +
542
+ " where a.id in (((\n " +
543
+ " select id from d join \n " +
544
+ " (select * from bc_nested join \n " +
545
+ " (select * from e) e_alias on bc_nested.id = e_alias.id\n " +
546
+ " ) bc_nested_alias \n " +
547
+ " on bc_nested_alias.id = d.id\n " +
548
+ " )))" ;
549
+ tables = TablesNamesFinder .findTables (sqlStr );
550
+ assertThat (tables ).containsExactlyInAnyOrder ("a" , "b" , "c" , "d" , "e" );
551
+
552
+ sqlStr = "select id\n " +
553
+ "from (select * from c, (select * from b) b_alias) as bc_nested, a\n " +
554
+ "where a.id in (\n " +
555
+ "select id from (select * from d \n " +
556
+ "join (select * from e) e_alias on d.id = e_alias.id) bc_nested_alias\n " +
557
+ "join bc_nested on bc_nested_alias.id = bc_nested.id\n " +
558
+ ")" ;
559
+ tables = TablesNamesFinder .findTables (sqlStr );
560
+ assertThat (tables ).containsExactlyInAnyOrder ("a" , "b" , "c" , "d" , "e" );
561
+
562
+ sqlStr = "with\n " +
563
+ " temp1 as (\n " +
564
+ " select a1.id as id, b.content as content from a a1\n " +
565
+ " join b on a1.id = b.id\n " +
566
+ " ),\n " +
567
+ " temp2 as (\n " +
568
+ " select b.id as id, b.value as value from b, c cross join temp1 where\n " +
569
+ " b.id = c.id and b.value = \" b.value\" \n " +
570
+ " )\n " +
571
+ "select temp1.id, ( select tid from d where cid = 29974 ) as tid \n " +
572
+ "from ( select tid from e, (select * from f) where cid = 29974) e_alias, temp1 cross join temp2\n "
573
+ +
574
+ "where exist ( select * from e, e_alias where e.test = dtest.test ) and temp1.max = (select max(column_1) from g)" ;
575
+ tables = TablesNamesFinder .findTables (sqlStr );
576
+ assertThat (tables ).containsExactlyInAnyOrder ("a" , "b" , "c" , "d" , "e" , "f" , "g" );
508
577
}
509
578
510
579
@ Test
0 commit comments