11package net .sf .jsqlparser .expression ;
22
33import java .util .List ;
4+ import net .sf .jsqlparser .schema .Column ;
5+ import net .sf .jsqlparser .statement .select .OrderByElement ;
46
57/**
68 * Analytic function. The name of the function is variable but the parameters
7- * following the special analytic function path.
8- * e.g. row_number() over (order by test)
9+ * following the special analytic function path. e.g. row_number() over (order
10+ * by test)
11+ *
912 * @author tw
1013 */
1114public class AnalyticExpression implements Expression {
1215
13- private List partitionByColumns ;
14- private List orderByElements ;
16+ private List < Column > partitionByColumns ;
17+ private List < OrderByElement > orderByElements ;
1518 private String name ;
16-
19+ private Expression expression ;
20+
1721 @ Override
1822 public void accept (ExpressionVisitor expressionVisitor ) {
1923 expressionVisitor .visit (this );
2024 }
2125
22- public List getOrderByElements () {
26+ public List < OrderByElement > getOrderByElements () {
2327 return orderByElements ;
2428 }
2529
26- public void setOrderByElements (List orderByElements ) {
30+ public void setOrderByElements (List < OrderByElement > orderByElements ) {
2731 this .orderByElements = orderByElements ;
2832 }
2933
30- public List getPartitionByColumns () {
34+ public List < Column > getPartitionByColumns () {
3135 return partitionByColumns ;
3236 }
3337
34- public void setPartitionByColumns (List partitionByColumns ) {
38+ public void setPartitionByColumns (List < Column > partitionByColumns ) {
3539 this .partitionByColumns = partitionByColumns ;
3640 }
3741
@@ -42,35 +46,47 @@ public String getName() {
4246 public void setName (String name ) {
4347 this .name = name ;
4448 }
45-
49+
50+ public Expression getExpression () {
51+ return expression ;
52+ }
53+
54+ public void setExpression (Expression expression ) {
55+ this .expression = expression ;
56+ }
57+
4658 @ Override
4759 public String toString () {
4860 StringBuilder b = new StringBuilder ();
49-
50- b .append (name ).append ("() OVER (" );
51- if (partitionByColumns !=null && !partitionByColumns .isEmpty ()) {
61+
62+ b .append (name ).append ("(" );
63+ if (expression != null ) {
64+ b .append (expression .toString ());
65+ }
66+ b .append (") OVER (" );
67+ if (partitionByColumns != null && !partitionByColumns .isEmpty ()) {
5268 b .append ("PARTITION BY " );
53- for (int i = 0 ; i < partitionByColumns .size ();i ++) {
54- if (i > 0 ) {
69+ for (int i = 0 ; i < partitionByColumns .size (); i ++) {
70+ if (i > 0 ) {
5571 b .append (", " );
5672 }
5773 b .append (partitionByColumns .get (i ).toString ());
5874 }
5975 b .append (" " );
6076 }
61-
62- if (orderByElements != null && !orderByElements .isEmpty ()) {
77+
78+ if (orderByElements != null && !orderByElements .isEmpty ()) {
6379 b .append ("ORDER BY " );
64- for (int i = 0 ; i < orderByElements .size ();i ++) {
65- if (i > 0 ) {
80+ for (int i = 0 ; i < orderByElements .size (); i ++) {
81+ if (i > 0 ) {
6682 b .append (", " );
6783 }
6884 b .append (orderByElements .get (i ).toString ());
6985 }
7086 }
71-
72- b .append (")" );
73-
87+
88+ b .append (")" );
89+
7490 return b .toString ();
75- }
91+ }
7692}
0 commit comments