Skip to content

Commit

Permalink
feat: More lenient FromQuery allowing for Join and WithItem
Browse files Browse the repository at this point in the history
- fixes starlake-ai/jsqltranspiler#73
- fixes starlake-ai/jsqltranspiler#72

Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
  • Loading branch information
manticore-projects committed Feb 13, 2025
1 parent 5c2a453 commit bcac023
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void testParseAndDeparseJoin() throws JSQLParserException {
}

@Test
void testParseAndDeparseWith() throws JSQLParserException {
void testParseAndDeparseWithIssue73() throws JSQLParserException {
// formatter:off
String sqlStr =
"with client_info as (\n" +
Expand Down Expand Up @@ -80,4 +80,42 @@ void testParseAndDeparseWith() throws JSQLParserException {
// formatter:on
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}

@Test
void testParseAndDeparseWithJoinIssue72() throws JSQLParserException {
// formatter:off
String sqlStr =
"with client as (\n" +
" select 1 as client_id\n" +
" |> UNION ALL\n" +
" (select 2),\n" +
" (select 3)\n" +
"), basket as (\n" +
" select 1 as basket_id, 1 as client_id\n" +
" |> UNION ALL\n" +
" (select 2, 2)\n" +
"), basket_item as (\n" +
" select 1 as item_id, 1 as basket_id\n" +
" |> UNION ALL\n" +
" (select 2, 1),\n" +
" (select 3, 1),\n" +
" (select 4, 2)\n" +
"), item as (\n" +
" select 1 as item_id, 'milk' as name\n" +
" |> UNION ALL\n" +
" (select 2, \"chocolate\"),\n" +
" (select 3, \"donut\"),\n" +
" (select 4, \"croissant\")\n" +
")\n" +
"FROM client c\n" +
" left join basket b using(client_id)\n" +
" left join basket_item bi using(basket_id)\n" +
" left join item i on i.item_id = bi.item_id\n" +
"|> aggregate count(i.item_id) as bought_item\n" +
" group by c.client_id, i.item_id, i.name\n" +
"|> aggregate array_agg((select as struct item_id, name, bought_item)) as items_info\n" +
" group by client_id";
// formatter:on
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
}

0 comments on commit bcac023

Please sign in to comment.