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

Order of statements described in rule action part does not keep after model generation in executable model.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Major
    • None
    • None
    • executable model
    • Hide
      1. Extract reproducer.
        $ unzip reproducer_model_compiler_14a.zip
        $ cd reproducer_model_compiler_14a
        
      2. Build and execute the rule with executable model disabled.
        $ mvn clean compile exec:exec -DgenerateModel=NO
            :
            :
        ***** start
        ***** Action of rule14a
        $model = ABC A180, count = 1           <----- as expected
        $manufacturer = ABC, totalCount = 1    <----- as expected
        ***** end
            :
            :
        
      3. Build and execute the rule with executable model enabled.
        $ mvn clean compile exec:exec -DgenerateModel=YES
            :
            :
        ***** start
        ***** Action of rule14a
        $model = ABC A180, count = 0           <----- unexpected result
        $manufacturer = ABC, totalCount = 0    <----- unexpected result
        ***** end
            :
            :
        
      Show
      Extract reproducer. $ unzip reproducer_model_compiler_14a.zip $ cd reproducer_model_compiler_14a Build and execute the rule with executable model disabled. $ mvn clean compile exec:exec -DgenerateModel=NO : : ***** start ***** Action of rule14a $model = ABC A180, count = 1 <----- as expected $manufacturer = ABC, totalCount = 1 <----- as expected ***** end : : Build and execute the rule with executable model enabled. $ mvn clean compile exec:exec -DgenerateModel=YES : : ***** start ***** Action of rule14a $model = ABC A180, count = 0 <----- unexpected result $manufacturer = ABC, totalCount = 0 <----- unexpected result ***** end : :
    • Show
      Already fixed in https://github.com/lucamolteni/drools/commit/52833df6eb8339db5220cb2aad5cf5e1c46bbcd1#diff-7005781af3e64c302fb7d7ea6d7af39b13a21641ff8d3415e58e91f4681e0009R142
    • NEW
    • NEW
    • ---
    • ---

    Description

      Building a rule written in MVEL dialect like (*1) in executable rule model, the order of the statements described in action (then) part of the rule changes after model generation like (*2). The generated code looks like that all statements outside the modify blocks come first, followed by all statements inside the modify blocks, and finally update statements for the modified properties are called together. The original order of the statements in action part should keep after model generation.

      (*1)

      package com.example.reproducer
      
      dialect "mvel"
      
      rule "rule14a"
          when
              $manufacturer : Manufacturer()
              $model : Model( manufacturer == $manufacturer )
              $car : Car( model == $model )
          then
              System.out.println("***** Action of rule14a");
              modify($model) {
                  count = $model.count + 1
              }
              System.out.println("$model = " + $model + ", count = " + $model.count);
              modify($manufacturer) {
                  totalCount = $manufacturer.totalCount + 1
              }
              System.out.println("$manufacturer = " + $manufacturer + ", totalCount = " + $manufacturer.totalCount);
      end
      

      (*2) LambdaConsequence<hash>.java generated from the action (then) part of the rule.

          @Override()
          public void execute(org.drools.model.Drools drools, com.example.reproducer.Model $model, com.example.reproducer.Manufacturer $manufacturer) throws java.lang.Exception {
              System.out.println("***** Action of rule14a");
              System.out.println("$model = " + $model + ", count = " + $model.getCount());
              System.out.println("$manufacturer = " + $manufacturer + ", totalCount = " + $manufacturer.getTotalCount());
              $model.setCount($model.getCount() + 1);
              $manufacturer.setTotalCount($manufacturer.getTotalCount() + 1);
              drools.update($model, mask_$model);
              drools.update($manufacturer, mask_$manufacturer);
          }
      

      Attachments

        Issue Links

          Activity

            People

              lmolteni@redhat.com Luca Molteni
              lmolteni@redhat.com Luca Molteni
              Daniel Rosa Daniel Rosa
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: