99 */
1010package net .sf .jsqlparser .expression ;
1111
12- import net .sf .jsqlparser .parser .ASTNodeAccessImpl ;
13- import net .sf .jsqlparser .statement .select .OrderByElement ;
14-
1512import java .util .List ;
1613import net .sf .jsqlparser .expression .operators .relational .ExpressionList ;
14+ import net .sf .jsqlparser .parser .ASTNodeAccessImpl ;
15+ import net .sf .jsqlparser .statement .select .OrderByElement ;
1716
1817/**
1918 * Analytic function. The name of the function is variable but the parameters following the special
@@ -37,6 +36,32 @@ public class AnalyticExpression extends ASTNodeAccessImpl implements Expression
3736 private boolean distinct = false ;
3837 private boolean ignoreNulls = false ;
3938
39+ public AnalyticExpression () {
40+ }
41+
42+ public AnalyticExpression (Function function ) {
43+ name = function .getName ();
44+ allColumns = function .isAllColumns ();
45+ distinct = function .isDistinct ();
46+
47+ ExpressionList list = function .getParameters ();
48+ if (list != null ) {
49+ if (list .getExpressions ().size () > 3 ) {
50+ throw new IllegalArgumentException ("function object not valid to initialize analytic expression" );
51+ }
52+
53+ expression = list .getExpressions ().get (0 );
54+ if (list .getExpressions ().size () > 1 ) {
55+ offset = list .getExpressions ().get (1 );
56+ }
57+ if (list .getExpressions ().size () > 2 ) {
58+ defaultValue = list .getExpressions ().get (2 );
59+ }
60+ }
61+ ignoreNulls = function .isIgnoreNulls ();
62+ keep = function .getKeep ();
63+ }
64+
4065 @ Override
4166 public void accept (ExpressionVisitor expressionVisitor ) {
4267 expressionVisitor .visit (this );
0 commit comments