Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-6351

PredicateInformation contains only one rule name even when shared

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Minor Minor
    • 7.60.0.Final
    • 7.54.0.Final
    • executable model
    • None
    • 2021 Week 19-21 (from May 10), 2021 Week 25-27 (from Jun 21), 2021 Week 31-33 (from Aug 2), 2021 Week 34-36 (from Aug 23)
    • 2
    • Undefined
    • NEW
    • NEW

      If you have rules like below:

      rule R1 when
        $p : Person( money < salary * 20 )
      then
      end
      rule R2 when
        $p : Person( money < salary * 20 )
      then
      end
      

      The constraint [money < salary * 20] will be shared as a LambdaPredicate in case of executable-model.

      public enum LambdaPredicate2065AA73CFC215ED50F8D776F13475F4 implements org.drools.model.functions.Predicate1<org.drools.modelcompiler.domain.Person>, org.drools.model.functions.HashedExpression {
      
          ...
      
          @Override()
          public boolean test(org.drools.modelcompiler.domain.Person _this) throws java.lang.Exception {
              return org.drools.modelcompiler.util.EvaluationUtil.lessThan(org.drools.modelcompiler.util.EvaluationUtil.toBigDecimal(_this.getMoney()), org.drools.modelcompiler.util.EvaluationUtil.toBigDecimal(_this.getSalary() * 20));
          }
      
          @Override()
          public org.drools.model.functions.PredicateInformation predicateInformation() {
              return new org.drools.model.functions.PredicateInformation("money < salary * 20", "R2", "r0.drl");
          }
      }
      

      See that PredicateInformation contains only one rule name among rules which share the LambdaPredicate.

      At the moment, the only downside of this issue is that an error message can tell the only one rule name. Probably this is trivial but filed a JIRA for the record.

      java.lang.RuntimeException: Error evaluating constraint 'money < salary * 20' in [Rule "R2" in r0.drl]
      	at org.drools.model.functions.PredicateInformation.betterErrorMessage(PredicateInformation.java:56)
      	at org.drools.modelcompiler.constraints.LambdaConstraint.isAllowed(LambdaConstraint.java:178)
              ...
      

      Luca wrote:
      > I think it could be useful to add all the rules referring to that particular constraint, something we can probably use for other optimisations

            rhn-support-tkobayas Toshiya Kobayashi
            rhn-support-tkobayas Toshiya Kobayashi
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: