2121 */
2222package net .sf .jsqlparser .expression ;
2323
24- import net .sf .jsqlparser .schema .Column ;
2524import net .sf .jsqlparser .statement .select .OrderByElement ;
2625
2726import java .util .List ;
3837 */
3938public class AnalyticExpression implements Expression {
4039
41- //private List<Column> partitionByColumns;
40+ //private List<Column> partitionByColumns;
4241 private ExpressionList partitionExpressionList ;
43- private List <OrderByElement > orderByElements ;
44- private String name ;
45- private Expression expression ;
42+ private List <OrderByElement > orderByElements ;
43+ private String name ;
44+ private Expression expression ;
4645 private Expression offset ;
4746 private Expression defaultValue ;
48- private boolean allColumns = false ;
47+ private boolean allColumns = false ;
4948 private WindowElement windowElement ;
49+ private KeepExpression keep = null ;
5050
51- @ Override
52- public void accept (ExpressionVisitor expressionVisitor ) {
53- expressionVisitor .visit (this );
54- }
51+ @ Override
52+ public void accept (ExpressionVisitor expressionVisitor ) {
53+ expressionVisitor .visit (this );
54+ }
5555
56- public List <OrderByElement > getOrderByElements () {
57- return orderByElements ;
58- }
56+ public List <OrderByElement > getOrderByElements () {
57+ return orderByElements ;
58+ }
5959
60- public void setOrderByElements (List <OrderByElement > orderByElements ) {
61- this .orderByElements = orderByElements ;
62- }
60+ public void setOrderByElements (List <OrderByElement > orderByElements ) {
61+ this .orderByElements = orderByElements ;
62+ }
6363
64- // public List<Column> getPartitionByColumns () {
65- // return partitionByColumns ;
66- // }
67- //
68- // public void setPartitionByColumns(List<Column> partitionByColumns ) {
69- // this.partitionByColumns = partitionByColumns ;
70- // }
64+ public KeepExpression getKeep () {
65+ return keep ;
66+ }
67+
68+ public void setKeep ( KeepExpression keep ) {
69+ this .keep = keep ;
70+ }
7171
7272 public ExpressionList getPartitionExpressionList () {
7373 return partitionExpressionList ;
@@ -76,24 +76,22 @@ public ExpressionList getPartitionExpressionList() {
7676 public void setPartitionExpressionList (ExpressionList partitionExpressionList ) {
7777 this .partitionExpressionList = partitionExpressionList ;
7878 }
79-
80-
8179
82- public String getName () {
83- return name ;
84- }
80+ public String getName () {
81+ return name ;
82+ }
8583
86- public void setName (String name ) {
87- this .name = name ;
88- }
84+ public void setName (String name ) {
85+ this .name = name ;
86+ }
8987
90- public Expression getExpression () {
91- return expression ;
92- }
88+ public Expression getExpression () {
89+ return expression ;
90+ }
9391
94- public void setExpression (Expression expression ) {
95- this .expression = expression ;
96- }
92+ public void setExpression (Expression expression ) {
93+ this .expression = expression ;
94+ }
9795
9896 public Expression getOffset () {
9997 return offset ;
@@ -120,61 +118,65 @@ public void setWindowElement(WindowElement windowElement) {
120118 }
121119
122120 @ Override
123- public String toString () {
124- StringBuilder b = new StringBuilder ();
121+ public String toString () {
122+ StringBuilder b = new StringBuilder ();
125123
126- b .append (name ).append ("(" );
127- if (expression != null ) {
128- b .append (expression .toString ());
124+ b .append (name ).append ("(" );
125+ if (expression != null ) {
126+ b .append (expression .toString ());
129127 if (offset != null ) {
130128 b .append (", " ).append (offset .toString ());
131129 if (defaultValue != null ) {
132130 b .append (", " ).append (defaultValue .toString ());
133131 }
134132 }
135- } else if (isAllColumns ()) {
136- b .append ("*" );
137- }
138- b .append (") OVER (" );
139-
140- toStringPartitionBy (b );
141- toStringOrderByElements (b );
142-
143- b .append (")" );
144-
145- return b .toString ();
146- }
147-
148- public boolean isAllColumns () {
149- return allColumns ;
150- }
151-
152- public void setAllColumns (boolean allColumns ) {
153- this .allColumns = allColumns ;
154- }
155-
156- private void toStringPartitionBy (StringBuilder b ) {
157- if (partitionExpressionList != null && !partitionExpressionList .getExpressions ().isEmpty ()) {
158- b .append ("PARTITION BY " );
159- b .append (PlainSelect .getStringList (partitionExpressionList .getExpressions (), true , false ));
160- b .append (" " );
161- }
162- }
163-
164- private void toStringOrderByElements (StringBuilder b ) {
165- if (orderByElements != null && !orderByElements .isEmpty ()) {
166- b .append ("ORDER BY " );
167- for (int i = 0 ; i < orderByElements .size (); i ++) {
168- if (i > 0 ) {
169- b .append (", " );
170- }
171- b .append (orderByElements .get (i ).toString ());
172- }
173-
174- if (windowElement != null ){
133+ } else if (isAllColumns ()) {
134+ b .append ("*" );
135+ }
136+ b .append (") " );
137+ if (keep != null ) {
138+ b .append (keep .toString ()).append (" " );
139+ }
140+ b .append ("OVER (" );
141+
142+ toStringPartitionBy (b );
143+ toStringOrderByElements (b );
144+
145+ b .append (")" );
146+
147+ return b .toString ();
148+ }
149+
150+ public boolean isAllColumns () {
151+ return allColumns ;
152+ }
153+
154+ public void setAllColumns (boolean allColumns ) {
155+ this .allColumns = allColumns ;
156+ }
157+
158+ private void toStringPartitionBy (StringBuilder b ) {
159+ if (partitionExpressionList != null && !partitionExpressionList .getExpressions ().isEmpty ()) {
160+ b .append ("PARTITION BY " );
161+ b .append (PlainSelect .getStringList (partitionExpressionList .getExpressions (), true , false ));
162+ b .append (" " );
163+ }
164+ }
165+
166+ private void toStringOrderByElements (StringBuilder b ) {
167+ if (orderByElements != null && !orderByElements .isEmpty ()) {
168+ b .append ("ORDER BY " );
169+ for (int i = 0 ; i < orderByElements .size (); i ++) {
170+ if (i > 0 ) {
171+ b .append (", " );
172+ }
173+ b .append (orderByElements .get (i ).toString ());
174+ }
175+
176+ if (windowElement != null ) {
175177 b .append (' ' );
176178 b .append (windowElement );
177179 }
178- }
179- }
180+ }
181+ }
180182}
0 commit comments