rosemarYuan commented on code in PR #821:
URL: https://github.com/apache/flink-agents/pull/821#discussion_r3394189318


##########
runtime/src/main/java/org/apache/flink/agents/runtime/condition/ActionRouter.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.agents.runtime.condition;
+
+import org.apache.flink.agents.api.Event;
+import org.apache.flink.agents.plan.AgentPlan;
+import org.apache.flink.agents.plan.actions.Action;
+import org.apache.flink.agents.plan.condition.ParsedCondition;
+import org.apache.flink.agents.plan.condition.ParsedCondition.CelExpression;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Routes an event to matching actions: type-index fast path first, then CEL 
slow path.
+ *
+ * <p>Each action fires at most once per event; typed hits ordered before CEL 
hits.
+ */
+public final class ActionRouter {
+
+    private final AgentPlan agentPlan;
+
+    /** Null when the plan contains no CEL expressions. */
+    private CelConditionEvaluator conditionEvaluator;
+
+    public ActionRouter(AgentPlan agentPlan) {
+        if (agentPlan == null) {
+            throw new IllegalArgumentException("ActionRouter: agentPlan must 
not be null");
+        }
+        this.agentPlan = agentPlan;
+    }
+
+    /** Pre-compiles all CEL expressions in the plan. */
+    public void open() {
+        List<CelExpression> celExpressions = new ArrayList<>();
+        for (Action action : agentPlan.getActions().values()) {
+            for (ParsedCondition pc : action.getParsedConditions()) {
+                if (pc instanceof CelExpression) {
+                    celExpressions.add((CelExpression) pc);
+                }
+            }
+        }
+        if (celExpressions.isEmpty()) {
+            return;
+        }
+        conditionEvaluator = new CelConditionEvaluator();

Review Comment:
   Thanks for the review suggestion. Good catch — that error path was not 
covered before.
   
   I added two paired cases in `ActionRouterTest`, both using the same erroring 
expression (`attributes.nonexistent > 3`) and the same event:
   
   * `route_failPolicyFromConfig_throwsOnConditionEvaluationError`: sets 
`CEL_EVALUATION_FAILURE_POLICY=FAIL` via `getConfig().set(...)` and verifies 
that `route()` throws `IllegalStateException`.
   * `route_defaultWarnAndSkip_swallowsConditionEvaluationError`: leaves the 
policy unset and verifies that `route()` returns an empty result.
   
   The pairing is intentional. A standalone `FAIL -> throw` test could still 
pass if the default policy were accidentally changed, the option key were 
misread, or the configured value were dropped. By keeping the expression and 
event identical and varying only the policy source, the tests make those 
regression modes visible.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to