|
12 | 12 | import java.util.ArrayList; |
13 | 13 | import java.util.Arrays; |
14 | 14 | import java.util.Collection; |
| 15 | +import java.util.List; |
15 | 16 | import java.util.Map; |
16 | | -import java.util.Optional; |
17 | 17 | import net.sf.jsqlparser.expression.operators.arithmetic.Addition; |
18 | 18 | import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd; |
19 | 19 | import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseLeftShift; |
@@ -119,11 +119,9 @@ public <S> T visit(Function function, S context) { |
119 | 119 | if (function.getKeep() != null) { |
120 | 120 | subExpressions.add(function.getKeep()); |
121 | 121 | } |
122 | | - if (function.getOrderByElements() != null) { |
123 | | - for (OrderByElement orderByElement : function.getOrderByElements()) { |
124 | | - subExpressions.add(orderByElement.getExpression()); |
125 | | - } |
126 | | - } |
| 122 | + addOrderByExpressions(subExpressions, function.getOrderByElements()); |
| 123 | + addFunctionModifiers(subExpressions, function.getHavingClause(), |
| 124 | + function.getKeywordArguments(), function.getLimit()); |
127 | 125 | return visitExpressions(function, context, subExpressions); |
128 | 126 | } |
129 | 127 |
|
@@ -419,29 +417,41 @@ public <S> T visit(AnalyticExpression analyticExpression, S context) { |
419 | 417 | if (analyticExpression.getKeep() != null) { |
420 | 418 | subExpressions.add(analyticExpression.getKeep()); |
421 | 419 | } |
422 | | - if (analyticExpression.getFuncOrderBy() != null) { |
423 | | - for (OrderByElement element : analyticExpression.getOrderByElements()) { |
424 | | - subExpressions.add(element.getExpression()); |
| 420 | + subExpressions.add(analyticExpression.getFilterExpression()); |
| 421 | + addOrderByExpressions(subExpressions, analyticExpression.getFuncOrderBy()); |
| 422 | + addFunctionModifiers(subExpressions, analyticExpression.getHavingClause(), |
| 423 | + analyticExpression.getKeywordArguments(), analyticExpression.getLimit()); |
| 424 | + if (analyticExpression.getWindowDefinition() != null) { |
| 425 | + subExpressions.addAll(analyticExpression.getWindowDefinition().getAllExpressions()); |
| 426 | + } |
| 427 | + return visitExpressions(analyticExpression, context, subExpressions); |
| 428 | + } |
| 429 | + |
| 430 | + private static void addOrderByExpressions(List<Expression> expressions, |
| 431 | + List<OrderByElement> orderBy) { |
| 432 | + if (orderBy != null) { |
| 433 | + for (OrderByElement element : orderBy) { |
| 434 | + expressions.add(element.getExpression()); |
425 | 435 | } |
426 | 436 | } |
427 | | - if (analyticExpression.getWindowElement() != null) { |
428 | | - /* |
429 | | - * Visit expressions from the range and offset of the window element. Do this using |
430 | | - * optional chains, because several things down the tree can be null e.g. the |
431 | | - * expression. So, null-safe versions of e.g.: |
432 | | - * analyticExpression.getWindowElement().getOffset().getExpression().accept(this, |
433 | | - * parameters); |
434 | | - */ |
435 | | - Optional.ofNullable(analyticExpression.getWindowElement().getRange()) |
436 | | - .map(WindowRange::getStart) |
437 | | - .map(WindowOffset::getExpression).ifPresent(subExpressions::add); |
438 | | - Optional.ofNullable(analyticExpression.getWindowElement().getRange()) |
439 | | - .map(WindowRange::getEnd) |
440 | | - .map(WindowOffset::getExpression).ifPresent(subExpressions::add); |
441 | | - Optional.ofNullable(analyticExpression.getWindowElement().getOffset()) |
442 | | - .map(WindowOffset::getExpression).ifPresent(subExpressions::add); |
| 437 | + } |
| 438 | + |
| 439 | + private static void addFunctionModifiers(List<Expression> expressions, |
| 440 | + Function.HavingClause having, List<Function.KeywordArgument> arguments, |
| 441 | + net.sf.jsqlparser.statement.select.Limit limit) { |
| 442 | + expressions.add(having); |
| 443 | + if (arguments != null) { |
| 444 | + for (Function.KeywordArgument argument : arguments) { |
| 445 | + expressions.add(argument.getExpression()); |
| 446 | + } |
| 447 | + } |
| 448 | + if (limit != null) { |
| 449 | + expressions.add(limit.getOffset()); |
| 450 | + expressions.add(limit.getRowCount()); |
| 451 | + if (limit.getByExpressions() != null) { |
| 452 | + expressions.addAll(limit.getByExpressions()); |
| 453 | + } |
443 | 454 | } |
444 | | - return visitExpressions(analyticExpression, context, subExpressions); |
445 | 455 | } |
446 | 456 |
|
447 | 457 | @Override |
|
0 commit comments