[jboss-jira] [JBoss JIRA] (DROOLS-574) str operator in 'accumulate', with operand from 'from', results in NPE at KB build
Mario Fusco (JIRA)
issues at jboss.org
Thu Aug 14 06:22:29 EDT 2014
[ https://issues.jboss.org/browse/DROOLS-574?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12992868#comment-12992868 ]
Mario Fusco commented on DROOLS-574:
------------------------------------
I've reproduced the problem and I'll fix it.
The other way to workaround it (the one I suggest) is using directly the startsWith method of the Java String class like in:
acc ( $msg : Message( text.startsWith($word) ) over window:time( 5m ) ;
> str operator in 'accumulate', with operand from 'from', results in NPE at KB build
> ----------------------------------------------------------------------------------
>
> Key: DROOLS-574
> URL: https://issues.jboss.org/browse/DROOLS-574
> Project: Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Affects Versions: 6.1.0.Final
> Reporter: Matteo Mortari
> Assignee: Mario Fusco
> Attachments: 20140813.drools6test.strStandardEvInAccumulate.zip
>
>
> This is an exercise for "group by" words.
> Consider the following pattern for realizing a "group by" by means of from/accumulate/count : the goal is to count Messages which starts with preferred keyword, if the count for a keyword is >= 2, then rule should fire.
> {code}
> declare GroupByString
> groupId : String
> groups : String[]
> end
> rule "init words of my interest"
> no-loop
> when
> then
> GroupByString grp = new GroupByString();
> grp.setGroupId("wordGroup");
> grp.setGroups(new String[]{"ciao", "bella"});
> insert(grp);
> end
> rule "group by word and count if >=2 then "
> no-loop
> when
> $group : GroupByString( groupId == "wordGroup")
> $word : String() from $group.groups
> accumulate ( $msg : Message( text str[startsWith] $word ) over window:time( 5m ) ;
> $list : collectList( $msg ),
> $count : count( $msg );
> $count >= 2
> )
> then
> System.out.println("group by " + $word + " count is "+ $count + " list: " + $list);
> insert(new Integer($count.intValue()));
> end
> {code}
> However trying to compile the KB with the kie-maven-plugin fails with this NPE and stacktrace (snippet):
> {noformat}
> java.lang.NullPointerException
> at org.drools.compiler.rule.builder.dialect.java.JavaAccumulateBuilder.buildExternalFunctionCall(JavaAccumulateBuilder.java:182)
> at org.drools.compiler.rule.builder.dialect.java.JavaAccumulateBuilder.build(JavaAccumulateBuilder.java:101)
> at org.drools.compiler.rule.builder.dialect.java.JavaAccumulateBuilder.build(JavaAccumulateBuilder.java:66)
> at org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:320)
> at org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:138)
> at org.drools.compiler.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:66)
> at org.drools.compiler.rule.builder.RuleBuilder.build(RuleBuilder.java:89)
> at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addRule(KnowledgeBuilderImpl.java:1652)
> at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.compileRules(KnowledgeBuilderImpl.java:968)
> {noformat}
> I've also noticed the following 2 aspects:
> 1-/ If you use another operator instead of {{str startsWith}}, for instance you replace with the {{contains}} operators, it does compile the KB successfully. In this scenario would change the exercise to "count Messages which _contains_ the preferred keyword", but it works:
> {code}
> rule "group by word and count if >=2 then "
> no-loop
> when
> $group : GroupByString( groupId == "wordGroup")
> $word : String() from $group.groups
> accumulate ( $msg : Message( text contains $word ) over window:time( 5m ) ;
> $list : collectList( $msg ),
> $count : count( $msg );
> $count >= 2
> )
> then
> System.out.println("group by " + $word + " count is "+ $count + " list: " + $list);
> insert(new Integer($count.intValue()));
> end
> {code}
> 2-/ If you use an hard-coded operand in the {{str startsWith}}, it works too. For instance if you hard-code the rule as:
> {code}
> rule "group by word and count if >=2 then "
> no-loop
> when
> accumulate ( $msg : Message( text str[startsWith] "ciao" ) over window:time( 5m ) ;
> $list : collectList( $msg ),
> $count : count( $msg );
> $count >= 2
> )
> then
> insert(new Integer($count.intValue()));
> end
> {code}
> It does not give NPE at KB build and executes as expected.
> For my application it's okay to deal with the first option above, but anyway I thought worthy to report a JIRA. I will attach reproducer. Ciao
--
This message was sent by Atlassian JIRA
(v6.2.6#6264)
More information about the jboss-jira
mailing list