|
9 | 9 | */ |
10 | 10 | package net.sf.jsqlparser.statement.select; |
11 | 11 |
|
| 12 | +import java.util.Collections; |
12 | 13 | import java.util.List; |
13 | 14 | import net.sf.jsqlparser.expression.ExpressionVisitor; |
14 | 15 | import net.sf.jsqlparser.expression.ExpressionVisitorAdapter; |
|
19 | 20 | import net.sf.jsqlparser.statement.ParenthesedStatement; |
20 | 21 | import net.sf.jsqlparser.statement.Statement; |
21 | 22 | import net.sf.jsqlparser.statement.StatementVisitor; |
| 23 | +import net.sf.jsqlparser.statement.piped.AggregatePipeOperator; |
| 24 | +import net.sf.jsqlparser.statement.piped.AsPipeOperator; |
| 25 | +import net.sf.jsqlparser.statement.piped.CallPipeOperator; |
| 26 | +import net.sf.jsqlparser.statement.piped.DropPipeOperator; |
| 27 | +import net.sf.jsqlparser.statement.piped.ExtendPipeOperator; |
22 | 28 | import net.sf.jsqlparser.statement.piped.FromQuery; |
| 29 | +import net.sf.jsqlparser.statement.piped.JoinPipeOperator; |
| 30 | +import net.sf.jsqlparser.statement.piped.LimitPipeOperator; |
| 31 | +import net.sf.jsqlparser.statement.piped.OrderByPipeOperator; |
| 32 | +import net.sf.jsqlparser.statement.piped.PipeOperator; |
| 33 | +import net.sf.jsqlparser.statement.piped.PipeOperatorVisitor; |
| 34 | +import net.sf.jsqlparser.statement.piped.PivotPipeOperator; |
| 35 | +import net.sf.jsqlparser.statement.piped.RenamePipeOperator; |
| 36 | +import net.sf.jsqlparser.statement.piped.SelectPipeOperator; |
| 37 | +import net.sf.jsqlparser.statement.piped.SetOperationPipeOperator; |
| 38 | +import net.sf.jsqlparser.statement.piped.SetPipeOperator; |
| 39 | +import net.sf.jsqlparser.statement.piped.TableSamplePipeOperator; |
| 40 | +import net.sf.jsqlparser.statement.piped.UnPivotPipeOperator; |
| 41 | +import net.sf.jsqlparser.statement.piped.WherePipeOperator; |
| 42 | +import net.sf.jsqlparser.statement.piped.WindowPipeOperator; |
23 | 43 |
|
24 | 44 | @SuppressWarnings({"PMD.UncommentedEmptyMethodBody"}) |
25 | 45 | public class SelectVisitorAdapter<T> implements SelectVisitor<T> { |
@@ -272,9 +292,121 @@ public <S> T visit(UnPivotQuery unPivotQuery, S context) { |
272 | 292 |
|
273 | 293 | @Override |
274 | 294 | public <S> T visit(FromQuery fromQuery, S context) { |
| 295 | + visitWithItems(fromQuery.getWithItemsList(), context); |
| 296 | + fromItemVisitor.visitFromItem(fromQuery.getFromItem(), context); |
| 297 | + if (fromQuery.getLateralViews() != null) { |
| 298 | + for (LateralView lateralView : fromQuery.getLateralViews()) { |
| 299 | + expressionVisitor.visitExpression(lateralView.getGeneratorFunction(), context); |
| 300 | + } |
| 301 | + } |
| 302 | + fromItemVisitor.visitJoins(fromQuery.getJoins(), context); |
| 303 | + |
| 304 | + PipeOperatorWalker<S> pipeOperators = new PipeOperatorWalker<>(); |
| 305 | + for (PipeOperator pipeOperator : fromQuery.getPipeOperators()) { |
| 306 | + pipeOperator.accept(pipeOperators, context); |
| 307 | + } |
275 | 308 | return null; |
276 | 309 | } |
277 | 310 |
|
| 311 | + /** Walks the expressions, joins and nested queries of the pipe operators of a FromQuery. */ |
| 312 | + private final class PipeOperatorWalker<S> implements PipeOperatorVisitor<T, S> { |
| 313 | + |
| 314 | + @Override |
| 315 | + public T visit(AggregatePipeOperator aggregate, S context) { |
| 316 | + visitSelectItems(aggregate.getSelectItems(), context); |
| 317 | + visitSelectItems(aggregate.getGroupItems(), context); |
| 318 | + return null; |
| 319 | + } |
| 320 | + |
| 321 | + @Override |
| 322 | + public T visit(AsPipeOperator as, S context) { |
| 323 | + return null; |
| 324 | + } |
| 325 | + |
| 326 | + @Override |
| 327 | + public T visit(CallPipeOperator call, S context) { |
| 328 | + return fromItemVisitor.visitFromItem(call.getTableFunction(), context); |
| 329 | + } |
| 330 | + |
| 331 | + @Override |
| 332 | + public T visit(DropPipeOperator drop, S context) { |
| 333 | + return expressionVisitor.visitExpressions(drop.getColumns(), context); |
| 334 | + } |
| 335 | + |
| 336 | + @Override |
| 337 | + public T visit(ExtendPipeOperator extend, S context) { |
| 338 | + return visit((SelectPipeOperator) extend, context); |
| 339 | + } |
| 340 | + |
| 341 | + @Override |
| 342 | + public T visit(JoinPipeOperator join, S context) { |
| 343 | + return fromItemVisitor.visitJoins(Collections.singletonList(join.getJoin()), context); |
| 344 | + } |
| 345 | + |
| 346 | + @Override |
| 347 | + public T visit(LimitPipeOperator limit, S context) { |
| 348 | + expressionVisitor.visitExpression(limit.getLimitExpression(), context); |
| 349 | + return expressionVisitor.visitExpression(limit.getOffsetExpression(), context); |
| 350 | + } |
| 351 | + |
| 352 | + @Override |
| 353 | + public T visit(OrderByPipeOperator orderBy, S context) { |
| 354 | + return expressionVisitor.visitOrderBy(orderBy.getOrderByElements(), context); |
| 355 | + } |
| 356 | + |
| 357 | + @Override |
| 358 | + public T visit(PivotPipeOperator pivot, S context) { |
| 359 | + expressionVisitor.visitExpression(pivot.getAggregateExpression(), context); |
| 360 | + visitSelectItems(pivot.getPivotColumns(), context); |
| 361 | + return null; |
| 362 | + } |
| 363 | + |
| 364 | + @Override |
| 365 | + public T visit(RenamePipeOperator rename, S context) { |
| 366 | + return visit((SelectPipeOperator) rename, context); |
| 367 | + } |
| 368 | + |
| 369 | + @Override |
| 370 | + public T visit(SelectPipeOperator select, S context) { |
| 371 | + visitSelectItems(select.getSelectItems(), context); |
| 372 | + return null; |
| 373 | + } |
| 374 | + |
| 375 | + @Override |
| 376 | + public T visit(SetPipeOperator set, S context) { |
| 377 | + return expressionVisitor.visitUpdateSets(set.getUpdateSets(), context); |
| 378 | + } |
| 379 | + |
| 380 | + @Override |
| 381 | + public T visit(TableSamplePipeOperator tableSample, S context) { |
| 382 | + return null; |
| 383 | + } |
| 384 | + |
| 385 | + @Override |
| 386 | + public T visit(SetOperationPipeOperator setOperation, S context) { |
| 387 | + for (ParenthesedSelect select : setOperation.getSelects()) { |
| 388 | + select.accept(SelectVisitorAdapter.this, context); |
| 389 | + } |
| 390 | + return null; |
| 391 | + } |
| 392 | + |
| 393 | + @Override |
| 394 | + public T visit(UnPivotPipeOperator unPivot, S context) { |
| 395 | + visitSelectItems(unPivot.getPivotColumns(), context); |
| 396 | + return null; |
| 397 | + } |
| 398 | + |
| 399 | + @Override |
| 400 | + public T visit(WherePipeOperator where, S context) { |
| 401 | + return expressionVisitor.visitExpression(where.getExpression(), context); |
| 402 | + } |
| 403 | + |
| 404 | + @Override |
| 405 | + public T visit(WindowPipeOperator window, S context) { |
| 406 | + return visit((SelectPipeOperator) window, context); |
| 407 | + } |
| 408 | + } |
| 409 | + |
278 | 410 | @Override |
279 | 411 | public <S> T visit(SetOperationList setOpList, S context) { |
280 | 412 | visitWithItems(setOpList.getWithItemsList(), context); |
|
0 commit comments