Skip to content

Commit

Permalink
feat: ParenthesedSelect can have Alias
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Reichel <[email protected]>
  • Loading branch information
manticore-projects committed Feb 6, 2025
1 parent a510f13 commit b5b242a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ javadoc {
options.addBooleanOption('html5', true)
}
options.addBooleanOption("Xdoclint:none", true)
options.addStringOption('J-Xmx4g')
options.addStringOption('J-Xss2m')
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static Alias getAliasFromItem(FromItem fromItem) {
TableFunction t = (TableFunction) fromItem;
return new Alias(t.getName(), true);
} else {
return new Alias(fromItem.getAlias().getName(), true);
return fromItem.getAlias()!=null ? new Alias(fromItem.getAlias().getName(), true) : null;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.sf.jsqlparser.statement.piped;

import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.test.TestUtils;
import org.junit.jupiter.api.Test;

class AsPipeOperatorTest {

@Test
void testParseAndDeparse() throws JSQLParserException {
String sqlStr="(\n" +
" SELECT '000123' AS id, 'apples' AS item, 2 AS sales\n" +
" UNION ALL\n" +
" SELECT '000456' AS id, 'bananas' AS item, 5 AS sales\n" +
") AS sales_table\n" +
"|> AGGREGATE SUM(sales) AS total_sales GROUP BY id, item\n" +
"|> AS t1\n" +
"|> JOIN (SELECT 456 AS id, 'yellow' AS color) AS t2\n" +
" ON CAST(t1.id AS INT64) = t2.id\n" +
"|> SELECT t2.id, total_sales, color;";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
}

0 comments on commit b5b242a

Please sign in to comment.