[rules-users] how to do things like "distinct"?

Simon Chen simonchennj at gmail.com
Wed Jun 1 10:55:33 EDT 2011


Hi all,

I have the following problem.

Let's say, I have a class Number3(), with three fields a, b, and c.

I have the following rule:

rule "test3"
    when
        Number3($a: a, $b: b)
        $minvalue: Number()
            from accumulate(Number3(a == $a, b == $b, $c: c), min($c))
    then
        System.out.println($a + " " + $b + " " + $minvalue);
end


Say, I have four objects (1,2,3), (1,2,4), (1,3,4), (1,3,5).

The result shows four lines:
1 3 4.0
1 3 4.0
1 2 3.0
1 2 3.0

But I want the output to be:
1 3 4.0
1 2 3.0

meaning that for each unique pair of a and b, I want the rule to fire only once.

Is this doable?

Thanks.
-Simon



More information about the rules-users mailing list