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

executable-model fails to compare BigDecimal

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • None
    • 7.16.0.Final
    • executable model
    • 2019 Week 02-04
      • See unit test PR
    • NEW
    • NEW

      When executable-model builds BigDecimal constraint, BigDecimal(double) constructor is used hence fails to compare at runtime.

      It generates source code like this:

      public class Rules64ef7d59a364454aa08fdda838c67ad1RuleMethods0 {
      
          /**
           * Rule name: R1
           */
          public static org.drools.model.Rule rule_R1() {
              final org.drools.model.Variable<com.sample.Customer> var_$customer = D.declarationOf(com.sample.Customer.class,
                                                                                                   "$customer");
              org.drools.model.Rule rule = D.rule("com.sample",
                                                  "R1").build(D.pattern(var_$customer).expr("$expr$1$",
                                                                                            (_this) -> org.drools.modelcompiler.util.EvaluationUtil.equals(org.drools.modelcompiler.util.EvaluationUtil.toBigDecimal(_this.getRate()),
                                                                                                                                                           org.drools.modelcompiler.util.EvaluationUtil.toBigDecimal(12.111)),
                                                                                            D.alphaIndexedBy(java.math.BigDecimal.class,
                                                                                                             org.drools.model.Index.ConstraintType.EQUAL,
                                                                                                             0,
                                                                                                             _this -> _this.getRate(),
                                                                                                             new java.math.BigDecimal("12.111")),
                                                                                            D.reactOn("rate")),
                                                              D.execute(() -> {
                  System.out.println("hello");
              }));
              return rule;
          }
      }
      

      I think org.drools.modelcompiler.util.EvaluationUtil.toBigDecimal(12.111) is the problem.

            lmolteni@redhat.com Luca Molteni
            rhn-support-tkobayas Toshiya Kobayashi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: