[jboss-jira] [JBoss JIRA] (DROOLS-414) Queries do not work with chained accessors as arguments
Mario Fusco (JIRA)
issues at jboss.org
Thu Jan 23 08:56:29 EST 2014
[ https://issues.jboss.org/browse/DROOLS-414?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12938249#comment-12938249 ]
Mario Fusco edited comment on DROOLS-414 at 1/23/14 8:56 AM:
-------------------------------------------------------------
For what regards queries documentation clearly states that
The following is not yet supported:
List and Map unification
Variables for the fields of facts
Expression unification - pred( X, X + 1, X * Y / 7 )
For this reason I changed this ticket from bug to feature request. Moreover I developed a test case reproducing this issue.
{code}
@Test
public void testQueryWithAccessorAsArgument() throws Exception {
String str =
"import org.drools.compiler.Person\n" +
"global java.util.List persons;\n" +
"\n" +
"query contains(String $s, String $c)\n" +
" $s := String( this.contains( $c ) )\n" +
"end\n" +
"\n" +
"rule R when\n" +
" $p : Person()\n" +
" contains( $p.name, \"a\"; )\n" +
"then\n" +
" persons.add( $p );\n" +
"end\n";
KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
List<Person> personsWithA = new ArrayList<Person>();
ksession.setGlobal("persons", personsWithA);
ksession.insert("Mark");
ksession.insert("Edson");
ksession.insert("Mario");
ksession.insert(new Person("Mark"));
ksession.insert(new Person("Edson"));
ksession.insert(new Person("Mario"));
ksession.fireAllRules();
assertEquals(2, personsWithA.size());
}
{code}
was (Author: mfusco):
For what regards queries documentation clearly states that
The following is not yet supported:
List and Map unification
Variables for the fields of facts
Expression unification - pred( X, X + 1, X * Y / 7 )
For this reason I changed this ticket from bug to feature request. Moreover I developed a test case reproducing this issue.
{source}
@Test
public void testQueryWithAccessorAsArgument() throws Exception {
String str =
"import org.drools.compiler.Person\n" +
"global java.util.List persons;\n" +
"\n" +
"query contains(String $s, String $c)\n" +
" $s := String( this.contains( $c ) )\n" +
"end\n" +
"\n" +
"rule R when\n" +
" $p : Person()\n" +
" contains( $p.name, \"a\"; )\n" +
"then\n" +
" persons.add( $p );\n" +
"end\n";
KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
List<Person> personsWithA = new ArrayList<Person>();
ksession.setGlobal("persons", personsWithA);
ksession.insert("Mark");
ksession.insert("Edson");
ksession.insert("Mario");
ksession.insert(new Person("Mark"));
ksession.insert(new Person("Edson"));
ksession.insert(new Person("Mario"));
ksession.fireAllRules();
assertEquals(2, personsWithA.size());
}
{source}
> Queries do not work with chained accessors as arguments
> -------------------------------------------------------
>
> Key: DROOLS-414
> URL: https://issues.jboss.org/browse/DROOLS-414
> Project: Drools
> Issue Type: Feature Request
> Security Level: Public(Everyone can see)
> Affects Versions: 5.5.0.Final, 6.0.1.Final
> Reporter: Davide Sottara
> Assignee: Mario Fusco
>
> When processing a query CE that uses chained property accessors:
> when
> $x : Foo()
> myQuery( $x.bar ; )
> then
> the QueryElementBuilder considers the whole expression $x.bar as a variable. Since no variable with that name has been bound, it is taken to be a new declaration, and thus an output. This results in an inconsistent behavior, since an obvious constraint will be ignored.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list