2626
2727import java .util .List ;
2828import net .sf .jsqlparser .expression .operators .relational .ExpressionList ;
29- import net .sf .jsqlparser .statement .select .PlainSelect ;
3029
3130/**
3231 * Analytic function. The name of the function is variable but the parameters following the special
3837 */
3938public class AnalyticExpression extends ASTNodeAccessImpl implements Expression {
4039
41- private ExpressionList partitionExpressionList ;
42- private List < OrderByElement > orderByElements ;
40+ private final OrderByClause orderBy = new OrderByClause () ;
41+ private final PartitionByClause partitionBy = new PartitionByClause () ;
4342 private String name ;
4443 private Expression expression ;
4544 private Expression offset ;
4645 private Expression defaultValue ;
4746 private boolean allColumns = false ;
48- private WindowElement windowElement ;
4947 private KeepExpression keep = null ;
5048 private AnalyticType type = AnalyticType .OVER ;
5149 private boolean distinct = false ;
@@ -56,11 +54,11 @@ public void accept(ExpressionVisitor expressionVisitor) {
5654 }
5755
5856 public List <OrderByElement > getOrderByElements () {
59- return orderByElements ;
57+ return orderBy . getOrderByElements () ;
6058 }
6159
6260 public void setOrderByElements (List <OrderByElement > orderByElements ) {
63- this . orderByElements = orderByElements ;
61+ orderBy . setOrderByElements ( orderByElements ) ;
6462 }
6563
6664 public KeepExpression getKeep () {
@@ -72,11 +70,11 @@ public void setKeep(KeepExpression keep) {
7270 }
7371
7472 public ExpressionList getPartitionExpressionList () {
75- return partitionExpressionList ;
73+ return partitionBy . getPartitionExpressionList () ;
7674 }
7775
7876 public void setPartitionExpressionList (ExpressionList partitionExpressionList ) {
79- this . partitionExpressionList = partitionExpressionList ;
77+ partitionBy . setPartitionExpressionList ( partitionExpressionList ) ;
8078 }
8179
8280 public String getName () {
@@ -112,11 +110,11 @@ public void setDefaultValue(Expression defaultValue) {
112110 }
113111
114112 public WindowElement getWindowElement () {
115- return windowElement ;
113+ return orderBy . getWindowElement () ;
116114 }
117115
118116 public void setWindowElement (WindowElement windowElement ) {
119- this . windowElement = windowElement ;
117+ orderBy . setWindowElement ( windowElement ) ;
120118 }
121119
122120 public AnalyticType getType () {
@@ -168,8 +166,8 @@ public String toString() {
168166 }
169167 b .append (" (" );
170168
171- toStringPartitionBy (b );
172- toStringOrderByElements (b );
169+ partitionBy . toStringPartitionBy (b );
170+ orderBy . toStringOrderByElements (b );
173171
174172 b .append (")" );
175173
@@ -184,29 +182,4 @@ public void setAllColumns(boolean allColumns) {
184182 this .allColumns = allColumns ;
185183 }
186184
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- }
212185}
0 commit comments