[jboss-jira] [JBoss JIRA] (DROOLS-1245) Document limitation of (legacy) Accumulate CE Alternate Syntax: single function with return type
Matteo Mortari (JIRA)
issues at jboss.org
Wed Aug 3 09:59:00 EDT 2016
[ https://issues.jboss.org/browse/DROOLS-1245?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Matteo Mortari updated DROOLS-1245:
-----------------------------------
Description:
Document limitations and common pitfalls:
h2. from+accumulate does not iterate
This does NOT iterate over the elements of the accumulate function:
{code:java}
rule R when
$theFrom : Object() from accumulate(MyPerson( $val : name );
collectList( $val ) )
then
list.add($theFrom);
end
{code}
and in fact the binded $theFrom : Object() is the List returned by the collect list.
While normally the "from" iterates over the element of list/iterable collections.
{code:java}
rule R1 when
$list : List( )
$s : Integer() from $list
then
out.add($s);
end
{code}
was:
Document limitations and common pitfalls:
h2. from+accumulate does not iterate
This does NOT iterate over the elements of the accumulate function:
{code:java}
rule R when
$theFrom : Object() from accumulate(MyPerson( $val : name );
collectList( $val ) )
then
list.add($theFrom);
end
{code}
and in fact the binded $theFrom : Object() is the List returned by the collect list.
While normally the "from" iterates over the element of list/iterable collections.
{code:java}
rule R1 when
$list : List( )
$s : Integer() from $list
then
out.add($s);
end
{code}
h2. limited scope of compile-time checks
Compile-time checks are performed for Accumulate Functions returning a single result.
Compile-time checks are NOT performed for iterable Accumulate Functions, the case when the accumulate function returns a collection.
With ref to DROOLS-1243.
For instance this fails at compilation:
{code:java}
rule R when
$theFrom : BigDecimal() from accumulate(MyPerson( $val : age );
sum( $val ) )
then
list.add($theFrom);
end
{code}
but the following does passes compilation:
{code:java}
rule R when
$theFrom : String() from accumulate(MyPerson( $val : name );
collectList( $val ) )
then
list.add($theFrom);
end
{code}
only to fail later at runtime with CCE:
{code:java}
Caused by: java.lang.ClassCastException: java.util.Collections$UnmodifiableRandomAccessList cannot be cast to java.lang.String
{code}
> Document limitation of (legacy) Accumulate CE Alternate Syntax: single function with return type
> ------------------------------------------------------------------------------------------------
>
> Key: DROOLS-1245
> URL: https://issues.jboss.org/browse/DROOLS-1245
> Project: Drools
> Issue Type: Enhancement
> Components: docs
> Affects Versions: 6.4.0.Final
> Reporter: Matteo Mortari
> Assignee: Matteo Mortari
>
> Document limitations and common pitfalls:
> h2. from+accumulate does not iterate
> This does NOT iterate over the elements of the accumulate function:
> {code:java}
> rule R when
> $theFrom : Object() from accumulate(MyPerson( $val : name );
> collectList( $val ) )
> then
> list.add($theFrom);
> end
> {code}
> and in fact the binded $theFrom : Object() is the List returned by the collect list.
> While normally the "from" iterates over the element of list/iterable collections.
> {code:java}
> rule R1 when
> $list : List( )
> $s : Integer() from $list
> then
> out.add($s);
> end
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the jboss-jira
mailing list