Skip to content

Commit 17371ae

Browse files
author
tfedkiv
committed
TableFunction extends FunctionItem
1 parent 88eddaf commit 17371ae

File tree

3 files changed

+21
-81
lines changed

3 files changed

+21
-81
lines changed

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

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,56 +21,13 @@
2121
*/
2222
package net.sf.jsqlparser.statement.select;
2323

24-
import net.sf.jsqlparser.expression.Alias;
25-
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
26-
27-
public class TableFunction implements FromItem {
28-
29-
private String name;
30-
private ExpressionList parameters;
31-
private Alias alias;
32-
33-
/**
34-
* The name of he procedure, i.e. "UNWIND_TOP"
35-
*
36-
* @return the name of he procedure
37-
*/
38-
public String getName() {
39-
return name;
40-
}
41-
42-
public void setName(String string) {
43-
name = string;
44-
}
45-
46-
/**
47-
* The list of parameters of the tableFunction (if any, else null)
48-
*
49-
* @return the list of parameters of the tableFunction (if any, else null)
50-
*/
51-
public ExpressionList getParameters() {
52-
return parameters;
53-
}
54-
55-
public void setParameters(ExpressionList list) {
56-
parameters = list;
57-
}
24+
public class TableFunction extends FunctionItem implements FromItem {
5825

5926
@Override
6027
public void accept(FromItemVisitor fromItemVisitor) {
6128
fromItemVisitor.visit(this);
6229
}
6330

64-
@Override
65-
public Alias getAlias() {
66-
return alias;
67-
}
68-
69-
@Override
70-
public void setAlias(Alias alias) {
71-
this.alias = alias;
72-
}
73-
7431
@Override
7532
public Pivot getPivot() {
7633
return null;
@@ -79,22 +36,4 @@ public Pivot getPivot() {
7936
@Override
8037
public void setPivot(Pivot pivot) {
8138
}
82-
83-
@Override
84-
public String toString() {
85-
String params;
86-
87-
if (parameters != null) {
88-
params = parameters.toString();
89-
}else {
90-
params = "()";
91-
}
92-
93-
String string = name + "" + params + "";
94-
if (alias != null) {
95-
string += alias.toString();
96-
}
97-
return string;
98-
}
99-
100-
}
39+
}

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,19 +2419,14 @@ MySQLGroupConcat MySQLGroupConcat():{
24192419

24202420
TableFunction TableFunction():
24212421
{
2422-
TableFunction retval = new TableFunction();
2423-
String procName = null;
2424-
ExpressionList expressionList = null;
2422+
Alias alias = null;
2423+
Function function;
2424+
TableFunction functionItem;
24252425
}
24262426
{
2427-
procName=RelObjectNameExt()
2428-
"(" [ expressionList=SimpleExpressionList() ] ")"
2429-
2430-
{
2431-
retval.setParameters(expressionList);
2432-
retval.setName(procName);
2433-
return retval;
2434-
}
2427+
function=Function() { functionItem = new TableFunction(); functionItem.setFunction(function); }
2428+
[alias=Alias() { functionItem.setAlias(alias); }]
2429+
{ return functionItem; }
24352430
}
24362431

24372432
SubSelect SubSelect():

src/test/java/net/sf/jsqlparser/test/select/SelectTest.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,8 +2013,10 @@ public void testTableFunctionWithNoParams() throws Exception {
20132013

20142014
assertTrue(plainSelect.getFromItem() instanceof TableFunction);
20152015
TableFunction fromItem = (TableFunction) plainSelect.getFromItem();
2016-
assertEquals("SOME_FUNCTION", fromItem.getName());
2017-
assertNull(fromItem.getParameters());
2016+
Function function = fromItem.getFunction();
2017+
assertNotNull(function);
2018+
assertEquals("SOME_FUNCTION", function.getName());
2019+
assertNull(function.getParameters());
20182020
assertNull(fromItem.getAlias());
20192021
assertStatementCanBeDeparsedAs(select, statement);
20202022
}
@@ -2026,11 +2028,13 @@ public void testTableFunctionWithParams() throws Exception {
20262028

20272029
assertTrue(plainSelect.getFromItem() instanceof TableFunction);
20282030
TableFunction fromItem = (TableFunction) plainSelect.getFromItem();
2029-
assertEquals("SOME_FUNCTION", fromItem.getName());
2031+
Function function = fromItem.getFunction();
2032+
assertNotNull(function);
2033+
assertEquals("SOME_FUNCTION", function.getName());
20302034

20312035
// verify params
2032-
assertNotNull(fromItem.getParameters());
2033-
List<Expression> expressions = fromItem.getParameters().getExpressions();
2036+
assertNotNull(function.getParameters());
2037+
List<Expression> expressions = function.getParameters().getExpressions();
20342038
assertEquals(2, expressions.size());
20352039

20362040
Expression firstParam = expressions.get(0);
@@ -2054,9 +2058,11 @@ public void testTableFunctionWithAlias() throws Exception {
20542058

20552059
assertTrue(plainSelect.getFromItem() instanceof TableFunction);
20562060
TableFunction fromItem = (TableFunction) plainSelect.getFromItem();
2061+
Function function = fromItem.getFunction();
2062+
assertNotNull(function);
20572063

2058-
assertEquals("SOME_FUNCTION", fromItem.getName());
2059-
assertNull(fromItem.getParameters());
2064+
assertEquals("SOME_FUNCTION", function.getName());
2065+
assertNull(function.getParameters());
20602066
assertNotNull(fromItem.getAlias());
20612067
assertEquals("z", fromItem.getAlias().getName());
20622068
assertStatementCanBeDeparsedAs(select, statement);

0 commit comments

Comments
 (0)