tkobayas opened a new issue, #7079:
URL: https://github.com/apache/incubator-kie/issues/7079

   ## Problem
   
   The RuleUnit DSL (`RuleUnitDefinition`) does not support CEP (Complex Event 
Processing) features. Specifically:
   
   1. **`@EventProcessing(STREAM)` annotation is ignored** — The DSL path in 
`RuleUnitProviderForDSL.ModelRuleUnit` creates the KieBase via 
`KieBaseBuilder.createKieBaseFromModel(model)` with no `KieBaseOption`, so the 
KieBase always uses CLOUD mode. The `@EventProcessing` and `@Clock` annotations 
on the unit class are never read because the DSL path bypasses 
`ReflectiveRuleUnitDescription.loadConfig()`.
   
   2. **No temporal operator support in the DSL** — `RuleFactory` does not 
expose temporal constraint methods (e.g., `after`, `before`, `during`, `meets`, 
`overlaps`), so there is no way to express temporal relationships between 
events in the Java DSL.
   
   As a result, the following CEP features cannot be used or tested with the 
DSL:
   
   - Event expiration (`@Expires` on event classes)
   - Temporal operators (`this after[5s,8s] $a`)
   - Sliding windows
   - Event-driven rule evaluation
   
   ## Context
   
   Discovered while fixing 
[incubator-kie#6911](https://github.com/apache/incubator-kie/issues/6911) 
(RuleUnit DSL does not apply RuleConfig clock type). That fix enables pseudo 
clock via `RuleConfig`, but a full CEP test is not possible because event 
processing mode and temporal operators are missing from the DSL path.
   
   The DRL-based RuleUnit path supports all of these features. For reference, 
`drools-ruleunits-impl` has a working CEP test (`CepTest.java`) that uses:
   - `@EventProcessing(EventProcessingType.STREAM)` and 
`@Clock(ClockType.PSEUDO)` on the unit class
   - `@Role(Role.Type.EVENT)` and `@Expires("10s")` on the event class
   - `this after[5s,8s] $a` temporal operator in DRL
   
   ## Proposed Changes
   
   ### 1. Read `@EventProcessing` annotation in the DSL path
   
   In `RuleUnitProviderForDSL.ModelRuleUnit`, read the `@EventProcessing` 
annotation from the `RuleUnitDefinition` class and pass it as a `KieBaseOption` 
when creating the KieBase.
   
   **File:** 
`drools-ruleunits/drools-ruleunits-dsl/src/main/java/org/drools/ruleunits/dsl/RuleUnitProviderForDSL.java`
   
   The constructor currently does:
   ```java
   this.ruleBase = KieBaseBuilder.createKieBaseFromModel(model);
   ```
   
   It should instead check for the annotation and pass the appropriate option:
   ```java
   EventProcessing eventAnn = type.getAnnotation(EventProcessing.class);
   if (eventAnn != null && eventAnn.value() == EventProcessingType.STREAM) {
       this.ruleBase = KieBaseBuilder.createKieBaseFromModel(model, 
EventProcessingOption.STREAM);
   } else {
       this.ruleBase = KieBaseBuilder.createKieBaseFromModel(model);
   }
   ```
   
   ### 2. Add temporal operator methods to `RuleFactory`
   
   Extend the DSL to allow temporal constraints between patterns. For example:
   
   ```java
   rulesFactory.rule("ACME after DROO")
       .on(stockTicks)
       .filter(EQUAL, StockTick::getCompany, "DROO")
       .join()
       .on(stockTicks)
       .filter(EQUAL, StockTick::getCompany, "ACME")
       .after(5, 8, TimeUnit.SECONDS)  // new temporal constraint
       .execute(results, (r, tick) -> r.add(tick));
   ```
   
   This requires new methods on `Pattern2Def` (or a new `TemporalPatternDef`) 
for temporal operators: `after`, `before`, `during`, `meets`, `overlaps`, etc.
   
   ### 3. Add a CEP integration test
   
   Once the above changes are in place, add a test to `drools-ruleunits-dsl` 
equivalent to `CepTest` in `drools-ruleunits-impl`:
   
   ```java
   @EventProcessing(EventProcessingType.STREAM)
   public class StockTickDslUnit implements RuleUnitDefinition {
       private final DataStream<StockTick> stockTicks;
       private final List<StockTick> results = new ArrayList<>();
       // ...
       @Override
       public void defineRules(RulesFactory rulesFactory) {
           rulesFactory.rule("ACME after DROO")
               .on(stockTicks).filter(EQUAL, StockTick::getCompany, "DROO")
               .join().on(stockTicks).filter(EQUAL, StockTick::getCompany, 
"ACME")
               .after(5, 8, TimeUnit.SECONDS)
               .execute(results, (r, tick) -> r.add(tick));
       }
   }
   ```
   
   The test should verify:
   - Pseudo clock can be set via `RuleConfig.setClockType(ClockType.PSEUDO)` 
(fixed in incubator-kie#6911)
   - Temporal operator `after` correctly matches events within the time window
   - Events expire after `@Expires` duration when using pseudo clock
   - `DataStream.append()` works with STREAM mode
   
   ## Acceptance Criteria
   
   - [ ] `@EventProcessing(EventProcessingType.STREAM)` annotation on a 
`RuleUnitDefinition` class configures the KieBase in STREAM mode
   - [ ] At least one temporal operator (e.g., `after`) is available in the DSL
   - [ ] Event expiration (`@Expires`) works with DSL rule units in STREAM mode
   - [ ] A CEP test in `drools-ruleunits-dsl` exercises pseudo clock, temporal 
operators, and event expiration
   - [ ] Existing DSL tests continue to pass (CLOUD mode remains the default)


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to