@@ -91,29 +91,39 @@ public <S> T visit(MatchRecognize matchRecognize, S context) {
9191 matchRecognize .getInput ().accept (this , context );
9292 matchRecognize
9393 .forEachExpression (expression -> expression .accept (expressionVisitor , context ));
94+ visitPivots (matchRecognize , context );
95+ return null ;
96+ }
97+
98+ /** Walks the PIVOT / UNPIVOT clause the grammar may attach to any FROM item. */
99+ private <S > void visitPivots (FromItem fromItem , S context ) {
94100 PivotVisitorAdapter <T > pivots = new PivotVisitorAdapter <>(expressionVisitor );
95- if (matchRecognize .getPivot () != null ) {
96- matchRecognize .getPivot ().accept (pivots , context );
101+ if (fromItem .getPivot () != null ) {
102+ fromItem .getPivot ().accept (pivots , context );
97103 }
98- if (matchRecognize .getUnPivot () != null ) {
99- matchRecognize .getUnPivot ().accept (pivots , context );
104+ if (fromItem .getUnPivot () != null ) {
105+ fromItem .getUnPivot ().accept (pivots , context );
100106 }
101- return null ;
102107 }
103108
104109 @ Override
105110 public <S > T visit (Table table , S context ) {
111+ visitPivots (table , context );
106112 return null ;
107113 }
108114
109115 @ Override
110116 public <S > T visit (ParenthesedSelect select , S context ) {
111- return select .getSelect ().accept (selectVisitor , context );
117+ T result = select .getSelect ().accept (selectVisitor , context );
118+ visitPivots (select , context );
119+ return result ;
112120 }
113121
114122 @ Override
115123 public <S > T visit (LateralSubSelect lateralSubSelect , S context ) {
116- return lateralSubSelect .getSelect ().accept (selectVisitor , context );
124+ T result = lateralSubSelect .getSelect ().accept (selectVisitor , context );
125+ visitPivots (lateralSubSelect , context );
126+ return result ;
117127 }
118128
119129 @ Override
@@ -123,13 +133,15 @@ public <S> T visit(TableFunction tableFunction, S context) {
123133 function .accept (expressionVisitor , context );
124134 }
125135 }
136+ visitPivots (tableFunction , context );
126137 return null ;
127138 }
128139
129140 @ Override
130141 public <S > T visit (ParenthesedFromItem fromItem , S context ) {
131142 T result = fromItem .getFromItem ().accept (this , context );
132143 visitJoins (fromItem .getJoins (), context );
144+ visitPivots (fromItem , context );
133145 return result ;
134146 }
135147
@@ -138,6 +150,7 @@ public <S> T visit(Values values, S context) {
138150 for (Expression expression : values .getExpressions ()) {
139151 expression .accept (expressionVisitor , context );
140152 }
153+ visitPivots (values , context );
141154 return null ;
142155 }
143156
0 commit comments