[jboss-jira] [JBoss JIRA] (DROOLS-3527) executable-model fails to compare BigDecimal

Toshiya Kobayashi (Jira) issues at jboss.org
Thu Jan 17 02:40:03 EST 2019


     [ https://issues.jboss.org/browse/DROOLS-3527?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Toshiya Kobayashi updated DROOLS-3527:
--------------------------------------
    Description: 
When executable-model builds BigDecimal constraint, BigDecimal(double) constructor is used hence fails to compare at runtime.

It generates source code like this:
{code:java}
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;
    }
}
{code}

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

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

It generates source code like this:
{code:java}
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;
    }
}
{code}

See: org.drools.modelcompiler.util.EvaluationUtil.toBigDecimal(12.111) 



> executable-model fails to compare BigDecimal
> --------------------------------------------
>
>                 Key: DROOLS-3527
>                 URL: https://issues.jboss.org/browse/DROOLS-3527
>             Project: Drools
>          Issue Type: Bug
>          Components: executable model
>    Affects Versions: 7.16.0.Final
>            Reporter: Toshiya Kobayashi
>            Assignee: Luca Molteni
>            Priority: Major
>              Labels: support
>
> When executable-model builds BigDecimal constraint, BigDecimal(double) constructor is used hence fails to compare at runtime.
> It generates source code like this:
> {code:java}
> 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;
>     }
> }
> {code}
> I think org.drools.modelcompiler.util.EvaluationUtil.toBigDecimal(12.111) is the problem.



--
This message was sent by Atlassian Jira
(v7.12.1#712002)


More information about the jboss-jira mailing list