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

Inconsistent behavior when accumulate function returns null

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Verified (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 7.9.1.GA, 7.10.0.GA
    • Fix Version/s: 7.11.0.GA
    • Component/s: BRE
    • Labels:
    • Environment:

      This issue was reported on RHDM 7.9.1.
      It is also reproducible on 7.10.0.

    • Target Release:
    • Fix Build:
      CR1
    • Steps to Reproduce:
      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 : :
    • Story Points:
      2
    • Sprint:
      2021 Week 10-12 (from Mar 8), 2021 Week 13-15 (from Mar 29)
    • QE Test Coverage:
      +

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tkobayashi Toshiya Kobayashi
              Reporter:
              myoshida Masato Yoshida
              Tester:
              Daniel Rosa Daniel Rosa
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: