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


##########
plan/src/main/java/org/apache/flink/agents/plan/condition/ParsedCondition.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.plan.condition;
+
+import dev.cel.common.CelAbstractSyntaxTree;
+import dev.cel.common.CelValidationException;
+import dev.cel.common.ast.CelConstant;
+import dev.cel.common.ast.CelExpr;
+
+import java.util.Objects;
+
+/**
+ * A parsed {@code Action.triggerConditions} entry — either {@link TypeMatch} 
or {@link
+ * ExpressionCondition}. {@link #classify} turns a raw entry string into one 
of the two.
+ */
+public interface ParsedCondition {
+
+    /**
+     * Matching key: the resolved event-type name for {@link TypeMatch}, or 
the expression source
+     * for {@link ExpressionCondition}.
+     */
+    String source();
+
+    /**
+     * Classifies a {@code triggerConditions} entry. A bare identifier or a 
quoted string is an
+     * event-type name ({@link TypeMatch}); anything else must be a boolean 
condition expression
+     * ({@link ExpressionCondition}). Name-shaped entries that are neither — 
e.g. {@code a.b.event}
+     * or {@code order-created} written without quotes — are rejected with the 
quoted spelling
+     * suggested.
+     */
+    static ParsedCondition classify(String source) {

Review Comment:
   After some offline discussions, we have decided to maintain the original API 
design, but `classify()` currently mixes classification, CEL parsing, 
validation, and error reporting. Could we separate classification from 
expression validation?
   
     The classification contract can be deterministic:
   
     - `a.b.c` is an event type.
     - Quoted routable names remain event types for compatibility, like 
`"a.b.c"`
     - A boolean attribute path must be explicit, for example `a.b.c == true`.
     - Everything else is an expression candidate.
   
     For example:
   
     ```
   private static final Pattern EVENT_TYPE =
             Pattern.compile(
                     "^(?:"
                             + 
"([A-Za-z_][A-Za-z0-9_]*(?:\\.[A-Za-z_][A-Za-z0-9_]*)*)"
                             + "|(['\"])([^\\s'\"\\\\\\p{Cntrl}]+)\\2"
                             + ")$");
   
     static ParsedCondition classify(String source) {
         if (source == null || source.trim().isEmpty()) {
             throw new IllegalArgumentException("Trigger condition must not be 
blank.");
         }
   
         String entry = source.trim();
         Matcher matcher = EVENT_TYPE.matcher(entry);
         if (matcher.matches()) {
             String bareType = matcher.group(1);
             String eventType = bareType != null ? bareType : matcher.group(3);
             boolean reservedExpression =
                     eventType.startsWith("EventType.")
                             || (bareType != null
                                     && (bareType.equals("true")
                                             || bareType.equals("false")
                                             || bareType.equals("null")));
             if (!reservedExpression) {
                 return new TypeMatch(eventType);
             }
         }
   
         return new ExpressionCondition(entry);
     }
   ```
   
     `buildParsedConditions()` can then validate only expression entries:
   
   ```
     ParsedCondition condition = ParsedCondition.classify(entry);
     if (condition instanceof ExpressionCondition) {
         ConditionExpressionValidator.validate(condition.source());
     }
     parsed.add(condition);
   ```
   
   The validator should own CEL parsing, syntax errors, allowed constructs, 
reserved EventType references, and standalone-value checks. It should also 
reject formatting variants such as `(a.b.c)` or `a . b . c` and require an 
explicit boolean condition such as `a.b.c == true`. Runtime compilation can 
remain responsible for type-checking and program creation.



-- 
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