26
26
27
27
import java .util .List ;
28
28
import net .sf .jsqlparser .expression .operators .relational .ExpressionList ;
29
- import net .sf .jsqlparser .statement .select .PlainSelect ;
30
29
31
30
/**
32
31
* Analytic function. The name of the function is variable but the parameters following the special
38
37
*/
39
38
public class AnalyticExpression extends ASTNodeAccessImpl implements Expression {
40
39
41
- private ExpressionList partitionExpressionList ;
42
- private List < OrderByElement > orderByElements ;
40
+ private final OrderByClause orderBy = new OrderByClause () ;
41
+ private final PartitionByClause partitionBy = new PartitionByClause () ;
43
42
private String name ;
44
43
private Expression expression ;
45
44
private Expression offset ;
46
45
private Expression defaultValue ;
47
46
private boolean allColumns = false ;
48
- private WindowElement windowElement ;
49
47
private KeepExpression keep = null ;
50
48
private AnalyticType type = AnalyticType .OVER ;
51
49
private boolean distinct = false ;
@@ -56,11 +54,11 @@ public void accept(ExpressionVisitor expressionVisitor) {
56
54
}
57
55
58
56
public List <OrderByElement > getOrderByElements () {
59
- return orderByElements ;
57
+ return orderBy . getOrderByElements () ;
60
58
}
61
59
62
60
public void setOrderByElements (List <OrderByElement > orderByElements ) {
63
- this . orderByElements = orderByElements ;
61
+ orderBy . setOrderByElements ( orderByElements ) ;
64
62
}
65
63
66
64
public KeepExpression getKeep () {
@@ -72,11 +70,11 @@ public void setKeep(KeepExpression keep) {
72
70
}
73
71
74
72
public ExpressionList getPartitionExpressionList () {
75
- return partitionExpressionList ;
73
+ return partitionBy . getPartitionExpressionList () ;
76
74
}
77
75
78
76
public void setPartitionExpressionList (ExpressionList partitionExpressionList ) {
79
- this . partitionExpressionList = partitionExpressionList ;
77
+ partitionBy . setPartitionExpressionList ( partitionExpressionList ) ;
80
78
}
81
79
82
80
public String getName () {
@@ -112,11 +110,11 @@ public void setDefaultValue(Expression defaultValue) {
112
110
}
113
111
114
112
public WindowElement getWindowElement () {
115
- return windowElement ;
113
+ return orderBy . getWindowElement () ;
116
114
}
117
115
118
116
public void setWindowElement (WindowElement windowElement ) {
119
- this . windowElement = windowElement ;
117
+ orderBy . setWindowElement ( windowElement ) ;
120
118
}
121
119
122
120
public AnalyticType getType () {
@@ -168,8 +166,8 @@ public String toString() {
168
166
}
169
167
b .append (" (" );
170
168
171
- toStringPartitionBy (b );
172
- toStringOrderByElements (b );
169
+ partitionBy . toStringPartitionBy (b );
170
+ orderBy . toStringOrderByElements (b );
173
171
174
172
b .append (")" );
175
173
@@ -184,29 +182,4 @@ public void setAllColumns(boolean allColumns) {
184
182
this .allColumns = allColumns ;
185
183
}
186
184
187
- private void toStringPartitionBy (StringBuilder b ) {
188
- if (partitionExpressionList != null && !partitionExpressionList .getExpressions ().isEmpty ()) {
189
- b .append ("PARTITION BY " );
190
- b .append (PlainSelect .
191
- getStringList (partitionExpressionList .getExpressions (), true , false ));
192
- b .append (" " );
193
- }
194
- }
195
-
196
- private void toStringOrderByElements (StringBuilder b ) {
197
- if (orderByElements != null && !orderByElements .isEmpty ()) {
198
- b .append ("ORDER BY " );
199
- for (int i = 0 ; i < orderByElements .size (); i ++) {
200
- if (i > 0 ) {
201
- b .append (", " );
202
- }
203
- b .append (orderByElements .get (i ).toString ());
204
- }
205
-
206
- if (windowElement != null ) {
207
- b .append (' ' );
208
- b .append (windowElement );
209
- }
210
- }
211
- }
212
185
}
0 commit comments