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

DrlDumper generates wrong drl when AccumulateDescr does not have constraint

    XMLWordPrintable

Details

    • Bug
    • Status: Verified (View Workflow)
    • Major
    • Resolution: Done
    • 7.9.0.GA
    • 7.10.0.GA
    • BRE
    • CR1
    • 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.
    • Release Notes
    • 2020 Week 49-51 (from Nov 30)
    • +

    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
              Daniel Rosa Daniel Rosa
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: