Skip to content

Commit bcac023

Browse files
feat: More lenient FromQuery allowing for Join and WithItem
- fixes starlake-ai/jsqltranspiler#73 - fixes starlake-ai/jsqltranspiler#72 Signed-off-by: Andreas Reichel <[email protected]>
1 parent 5c2a453 commit bcac023

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/test/java/net/sf/jsqlparser/statement/piped/FromQueryTest.java

+39-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void testParseAndDeparseJoin() throws JSQLParserException {
4141
}
4242

4343
@Test
44-
void testParseAndDeparseWith() throws JSQLParserException {
44+
void testParseAndDeparseWithIssue73() throws JSQLParserException {
4545
// formatter:off
4646
String sqlStr =
4747
"with client_info as (\n" +
@@ -80,4 +80,42 @@ void testParseAndDeparseWith() throws JSQLParserException {
8080
// formatter:on
8181
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
8282
}
83+
84+
@Test
85+
void testParseAndDeparseWithJoinIssue72() throws JSQLParserException {
86+
// formatter:off
87+
String sqlStr =
88+
"with client as (\n" +
89+
" select 1 as client_id\n" +
90+
" |> UNION ALL\n" +
91+
" (select 2),\n" +
92+
" (select 3)\n" +
93+
"), basket as (\n" +
94+
" select 1 as basket_id, 1 as client_id\n" +
95+
" |> UNION ALL\n" +
96+
" (select 2, 2)\n" +
97+
"), basket_item as (\n" +
98+
" select 1 as item_id, 1 as basket_id\n" +
99+
" |> UNION ALL\n" +
100+
" (select 2, 1),\n" +
101+
" (select 3, 1),\n" +
102+
" (select 4, 2)\n" +
103+
"), item as (\n" +
104+
" select 1 as item_id, 'milk' as name\n" +
105+
" |> UNION ALL\n" +
106+
" (select 2, \"chocolate\"),\n" +
107+
" (select 3, \"donut\"),\n" +
108+
" (select 4, \"croissant\")\n" +
109+
")\n" +
110+
"FROM client c\n" +
111+
" left join basket b using(client_id)\n" +
112+
" left join basket_item bi using(basket_id)\n" +
113+
" left join item i on i.item_id = bi.item_id\n" +
114+
"|> aggregate count(i.item_id) as bought_item\n" +
115+
" group by c.client_id, i.item_id, i.name\n" +
116+
"|> aggregate array_agg((select as struct item_id, name, bought_item)) as items_info\n" +
117+
" group by client_id";
118+
// formatter:on
119+
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
120+
}
83121
}

0 commit comments

Comments
 (0)