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.
- clones
-
DROOLS-5872 DrlDumper generates wrong drl when AccumulateDescr does not have constraint
- Closed