99 */
1010package net .sf .jsqlparser .statement .select ;
1111
12+ import java .util .List ;
1213import net .sf .jsqlparser .expression .Alias ;
1314import net .sf .jsqlparser .expression .Expression ;
1415import net .sf .jsqlparser .expression .Function ;
16+ import net .sf .jsqlparser .expression .operators .relational .ParenthesedExpressionList ;
1517
1618@ SuppressWarnings ({"PMD.UncommentedEmptyMethodBody" })
1719public class TableFunction extends Function implements FromItem {
@@ -20,6 +22,7 @@ public class TableFunction extends Function implements FromItem {
2022 private Pivot pivot = null ;
2123 private UnPivot unPivot = null ;
2224 private Function function ;
25+ private ParenthesedExpressionList <Function > rowsFromFunctions ;
2326 private String withClause = null ;
2427
2528 public TableFunction (Function function ) {
@@ -42,6 +45,27 @@ public TableFunction(String prefix, Function function, String withClause) {
4245 this .withClause = withClause ;
4346 }
4447
48+ public TableFunction (ParenthesedExpressionList <Function > rowsFromFunctions ) {
49+ this .rowsFromFunctions = rowsFromFunctions ;
50+ }
51+
52+ public TableFunction (String prefix , ParenthesedExpressionList <Function > rowsFromFunctions ) {
53+ this .prefix = prefix ;
54+ this .rowsFromFunctions = rowsFromFunctions ;
55+ }
56+
57+ public TableFunction (ParenthesedExpressionList <Function > rowsFromFunctions , String withClause ) {
58+ this .rowsFromFunctions = rowsFromFunctions ;
59+ this .withClause = withClause ;
60+ }
61+
62+ public TableFunction (String prefix , ParenthesedExpressionList <Function > rowsFromFunctions ,
63+ String withClause ) {
64+ this .prefix = prefix ;
65+ this .rowsFromFunctions = rowsFromFunctions ;
66+ this .withClause = withClause ;
67+ }
68+
4569 public TableFunction (String prefix , String name , Expression ... parameters ) {
4670 this .prefix = prefix ;
4771 this .function = new Function (name , parameters );
@@ -57,9 +81,32 @@ public Function getFunction() {
5781
5882 public TableFunction setFunction (Function function ) {
5983 this .function = function ;
84+ this .rowsFromFunctions = null ;
6085 return this ;
6186 }
6287
88+ public ParenthesedExpressionList <Function > getRowsFromFunctions () {
89+ return rowsFromFunctions ;
90+ }
91+
92+ public TableFunction setRowsFromFunctions (
93+ ParenthesedExpressionList <Function > rowsFromFunctions ) {
94+ this .rowsFromFunctions = rowsFromFunctions ;
95+ this .function = null ;
96+ return this ;
97+ }
98+
99+ public boolean isRowsFrom () {
100+ return rowsFromFunctions != null ;
101+ }
102+
103+ public List <Function > getFunctions () {
104+ if (rowsFromFunctions != null ) {
105+ return rowsFromFunctions ;
106+ }
107+ return function != null ? List .of (function ) : null ;
108+ }
109+
63110 @ Deprecated
64111 public Function getExpression () {
65112 return getFunction ();
@@ -151,7 +198,11 @@ public StringBuilder appendTo(StringBuilder builder) {
151198 if (prefix != null ) {
152199 builder .append (prefix ).append (" " );
153200 }
154- builder .append (function .toString ());
201+ if (rowsFromFunctions != null ) {
202+ builder .append ("ROWS FROM " ).append (rowsFromFunctions );
203+ } else {
204+ builder .append (function );
205+ }
155206
156207 if (withClause != null ) {
157208 builder .append (" WITH " ).append (withClause );
0 commit comments