Uploaded image for project: 'Red Hat Decision Manager'
  1. Red Hat Decision Manager
  2. RHDM-1643

Inconsistent behavior when accumulate function returns null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 7.11.0.GA
    • 7.9.1.GA, 7.10.0.GA
    • BRE
    • This issue was reported on RHDM 7.9.1.
      It is also reproducible on 7.10.0.

    • 2
    • False
    • False
    • CR1
    • +
    • Undefined
    • Hide
      1. Extract the reproducer.
        $ unzip reproducer_accumulate_test.zip
        $ cd reproducer_accumulate_test
        
      2. Edit src/main/java/com/example/reproduccer/DroolsTest.java (Use either of the following lines)
            // target.setText("XXX");
            target.setText("NoMatch");
        
      3. Build and run the reproducer.
        $ ./run_mvn
        

        (1) the result when you use target.setText("XXX")

        $ ./run_mvn
            :
            :
        ***** start
        ***** accumualte_rule_min: $min = 10
        ***** accumualte_rule_max: $max = 10
        ***** accumualte_rule_minmax: $max = 10, $min = 10
        ***** accumualte_rule_average: $ave = 10.0
        ***** accumualte_rule_count: $count = 1
        ***** accumualte_rule_sum: $sum = 10
        ***** end
            :
            :
        

        (2) the result when you use target.setText("NoMatch")

        $ ./run_mvn
            :
            :
        ***** start
        ***** accumualte_rule_minmax: $max = null, $min = null
        ***** accumualte_rule_count: $count = 0
        ***** accumualte_rule_sum: $sum = 0
        ***** end
            :
            :
        
      Show
      Extract the reproducer. $ unzip reproducer_accumulate_test.zip $ cd reproducer_accumulate_test Edit src/main/java/com/example/reproduccer/DroolsTest.java (Use either of the following lines) // target.setText( "XXX" ); target.setText( "NoMatch" ); Build and run the reproducer. $ ./run_mvn (1) the result when you use target.setText("XXX") $ ./run_mvn : : ***** start ***** accumualte_rule_min: $min = 10 ***** accumualte_rule_max: $max = 10 ***** accumualte_rule_minmax: $max = 10, $min = 10 ***** accumualte_rule_average: $ave = 10.0 ***** accumualte_rule_count: $count = 1 ***** accumualte_rule_sum: $sum = 10 ***** end : : (2) the result when you use target.setText("NoMatch") $ ./run_mvn : : ***** start ***** accumualte_rule_minmax: $max = null, $min = null ***** accumualte_rule_count: $count = 0 ***** accumualte_rule_sum: $sum = 0 ***** end : :
    • 2021 Week 10-12 (from Mar 8), 2021 Week 13-15 (from Mar 29)

      When you use accumulate and no fact matches, the behaviors are different depending on accumulate functions:

          rule "accumualte_rule_min"
            when
              accumulate( target : Target( target.getText() == "XXX" ),
                          $min : min( target.getNumber1() ) )
            then
              System.out.println("***** accumualte_rule_min: $min = " + $min);
          end
      

      min() : IntegerMinAccumulateFunction -> returns null if no fact matches
      max() : IntegerMaxAccumulateFunction -> returns null if no fact matches
      ave() : AverageAccumulateFunction -> returns null if no fact matches

      -> If the result is null, the rule won't fire.

      https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/core/phreak/PhreakAccumulateNode.java#L620-L627

      count() : CountAccumulateFunction -> returns 0 if no fact matches
      sum() : IntegerSumAccumulateFunction -> returns 0 if no fact matches

      -> result is not null. So the rule is fired.

      min(), max() : When you have multiple functions in accumulate, MultiAccumulate is used. This returns Object[] which contains multiple results. In this case, result = Object[2] which is [null, null].

      https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/core/rule/MultiAccumulate.java#L163-L177

      -> In this case, the result is not null. So the rule is fired with these "null" results.

      This JIRA is to make it consistent.

            rhn-support-tkobayas Toshiya Kobayashi
            rhn-support-myoshida Masato Yoshida
            Daniel Rosa Daniel Rosa
            Daniel Rosa Daniel Rosa
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: