@@ -108,9 +108,9 @@ public int hashCode() {
108108 public boolean equals (Object obj ) {
109109 if (super .equals (obj )) {
110110
111- PromqlCommand other = (PromqlCommand ) obj ;
112- return Objects .equals (child (), other .child ()) && Objects .equals (promqlPlan , other .promqlPlan );
113- }
111+ PromqlCommand other = (PromqlCommand ) obj ;
112+ return Objects .equals (child (), other .child ()) && Objects .equals (promqlPlan , other .promqlPlan );
113+ }
114114
115115 return false ;
116116 }
@@ -132,26 +132,35 @@ public String nodeString() {
132132
133133 @ Override
134134 public void postAnalysisVerification (Failures failures ) {
135- promqlPlan ().collectFirstChildren (PromqlFunctionCall .class ::isInstance )
136- .stream ()
137- .filter (WithinSeriesAggregate .class ::isInstance )
138- .forEach (
139- withinSeriesAggregate -> failures .add (
140- fail (
141- withinSeriesAggregate ,
142- "within time series aggregate function [{}] "
135+ promqlPlan ().forEachDownMayReturnEarly ((lp , breakEarly ) -> {
136+ if (lp instanceof PromqlFunctionCall fc ) {
137+ if (fc instanceof AcrossSeriesAggregate ) {
138+ breakEarly .set (true );
139+ fc .forEachDown ((childLp -> verifyNonFunctionCall (failures , childLp )));
140+ } else if (fc instanceof WithinSeriesAggregate withinSeriesAggregate ) {
141+ failures .add (
142+ fail (
143+ withinSeriesAggregate ,
144+ "within time series aggregate function [{}] "
143145 + "can only be used inside an across time series aggregate function at this time" ,
144- withinSeriesAggregate .sourceText ()
145- )
146- )
147- );
148- promqlPlan ().forEachDown (Selector .class , s -> {
146+ withinSeriesAggregate .sourceText ()
147+ )
148+ );
149+ }
150+ } else {
151+ verifyNonFunctionCall (failures , lp );
152+ }
153+ });
154+ }
155+
156+ private void verifyNonFunctionCall (Failures failures , LogicalPlan logicalPlan ) {
157+ if (logicalPlan instanceof Selector s ) {
149158 if (s .labelMatchers ().nameLabel ().matcher ().isRegex ()) {
150159 failures .add (fail (s , "regex label selectors on __name__ are not supported at this time [{}]" , s .sourceText ()));
151160 }
152161 if (s .evaluation ().offset () != null && s .evaluation ().offset () != TimeValue .ZERO ) {
153162 failures .add (fail (s , "offset modifiers are not supported at this time [{}]" , s .sourceText ()));
154163 }
155- });
164+ }
156165 }
157166}
0 commit comments