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

DrlDumper generates wrong drl when AccumulateDescr does not have constraint

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • None
    • 7.44.0.Final, 7.46.0.Final
    • core engine
    • 2020 Week 49-51 (from Nov 30)
    • Hide

      run attached reproducer (mvn clean test)

      Show
      run attached reproducer (mvn clean test)
    • Hide

      add constraint even if it's not needed.

      Show
      add constraint even if it's not needed.
    • Undefined
    • NEW
    • NEW
    • ---
    • ---

    Description

      When AccumulateDescr does not have constraint, generated DRL can not be built.

      Here is an example code.

              PackageDescr packageDescr = DescrFactory.newPackage().name("example")
                      .newImport().target("java.math.BigDecimal").end()
                      .newRule().name("Test Rule")
                          .lhs()
                              .accumulate()
                                  .source().pattern().type("example.RuleTest.Fact").id("$target", false)
                                  .end()
                              .end()
                          .function("count", "$cnt", false)
      //  adding the following constraint can avoid from KieBase build error
      //                 .constraint("true")
                          .end()
                      .end() 
                      .rhs("System.out.println($cnt);")
                      .end()
                  .end().getDescr();
      
              String drl = new DrlDumper().dump(packageDescr);
      

      This dumps the following DRL.

      package example 
      
      import java.math.BigDecimal
      
      rule "Test Rule"
      when
          accumulate(     
          $target : example.RuleTest.Fact(  )  ,
              $cnt : count(  ) ;
               ) 
      then
      System.out.println($cnt);
      
      end
      

      KieBase build with above drl fails with the following error.

      2020-12-02 15:05:47,875 ERROR [org.drools.compiler.kie.builder.impl.KieProject] (main) Unable to build KieBaseModel:defaultKieBase
      [10,9]: [ERR 101] Line 10:9 no viable alternative at input ')' in rule "Test Rule"
      [0,0]: Parser returned a null Package
      

      Adding constraint like comment line in above code can avoid from build error.

      Attachments

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              rhn-support-hmiura Hiroko Miura
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: