Skip to content

Commit b5b242a

Browse files
feat: ParenthesedSelect can have Alias
Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
1 parent a510f13 commit b5b242a

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ javadoc {
132132
options.addBooleanOption('html5', true)
133133
}
134134
options.addBooleanOption("Xdoclint:none", true)
135+
options.addStringOption('J-Xmx4g')
136+
options.addStringOption('J-Xss2m')
135137
}
136138

137139
jar {

src/main/java/net/sf/jsqlparser/statement/select/ParenthesedSelect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private static Alias getAliasFromItem(FromItem fromItem) {
7979
TableFunction t = (TableFunction) fromItem;
8080
return new Alias(t.getName(), true);
8181
} else {
82-
return new Alias(fromItem.getAlias().getName(), true);
82+
return fromItem.getAlias()!=null ? new Alias(fromItem.getAlias().getName(), true) : null;
8383
}
8484
}
8585

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package net.sf.jsqlparser.statement.piped;
2+
3+
import net.sf.jsqlparser.JSQLParserException;
4+
import net.sf.jsqlparser.test.TestUtils;
5+
import org.junit.jupiter.api.Test;
6+
7+
class AsPipeOperatorTest {
8+
9+
@Test
10+
void testParseAndDeparse() throws JSQLParserException {
11+
String sqlStr="(\n" +
12+
" SELECT '000123' AS id, 'apples' AS item, 2 AS sales\n" +
13+
" UNION ALL\n" +
14+
" SELECT '000456' AS id, 'bananas' AS item, 5 AS sales\n" +
15+
") AS sales_table\n" +
16+
"|> AGGREGATE SUM(sales) AS total_sales GROUP BY id, item\n" +
17+
"|> AS t1\n" +
18+
"|> JOIN (SELECT 456 AS id, 'yellow' AS color) AS t2\n" +
19+
" ON CAST(t1.id AS INT64) = t2.id\n" +
20+
"|> SELECT t2.id, total_sales, color;";
21+
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
22+
}
23+
}

0 commit comments

Comments
 (0)