[rules-users] Using from with named queries

rouvas at di.uoa.gr rouvas at di.uoa.gr
Wed Jul 28 15:45:56 EDT 2010


Wolfang,

Wolfgang Laun wrote:
> Don't be too keen on using "from" in connection with queries. The simple
> reason is that queries return nothing but what rules can do just as well.
>
> Thus, getting all pairs of Person's and Restaurant's with matching "food"
> and "zipcode", the straightforward LHS would be
>
>   p:Person( $favFood : favouriteFood, $zip : address.zipcode )
>   r: Restaurant( food == $favFood, postcode == $zip )

That was(is) my initial approach, and it is clearly the most
straightforward one.

Then I learned that the (theoretical) number of facts for "Person" objects
the client has, is about 65 billion with the potential of doubling every
year.

Of course, they are in a database and I was looking into using the "from"
keyword to do lookups in the database to retrieve the facts I need.

By the way, I have looked into "eval" and I am not sure how to use it in
respect to inline vs conditional element.

Regardless, my primary issue is how to reason over the "facts" as records
in a database.

Any ideas will be greatly appreciated.

-Stathis

>
> "from" is required if the objects aren't facts but, for instance, elements
> in a collection contained in a fact. So, if you have Restaurants only
> as a List<Restaurant> in a (say) City object, you would write
>
>   p:Person( $favFood : favouriteFood, $zip : address.zipcode )
>   c: City( zipcodeSet contains $zip )            # a person's home town
>   r: Restaurant( food == $favFood, postcode == $zip ) from
> c.restaurantList
>
> assuming that a (biggish) City typically has many zipcodes.
>
> -W
>
>
>
> On 28 July 2010 15:06,  <rouvas at di.uoa.gr> wrote:
>> Hello list,
>>
>> I'm using Drools.5.0.1 and I am trying to comprehend how to used the
>> "from" keyword over a named query.
>>
>> I've googled this:
>> http://blog.athico.com/2007/06/chained-from-accumulate-collect.html
>>
>> where it states:
>>
>> p : Person( )
>>  Restaurant( food == p.favouriteFood )
>>                from hs.getNamedQuery( "list restaurants by postcode" )
>>                     .setProperties( [ "postcode" : p.address.zipcode ] )
>>                     .list()
>>
>> If I understand the above correctly, the "hs.getNamedQuery" returns
>> "Restaurant" objects using values from "Person" object.
>>
>> There are a couple of issues that I would like to resolve.
>>
>> Where and how is the "hs" object in "hs.getNamedQuery" statement is
>> declared?
>>
>> If the "Person" object itself is the result of a NamedQuery, could the
>> above statement be rewritten as:
>>
>>  p : Person( ) from ps.getNamedQuery("return list of persons")
>>  Restaurant( food == p.favouriteFood )
>>                from hs.getNamedQuery( "list restaurants by postcode" )
>>                     .setProperties( [ "postcode" : p.address.zipcode ] )
>>                     .list()
>>
>> Thank you for your time.
>> -Stathis
>>
>> PS: Please take note that this is a newbie (in Drools) speaking.
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>





More information about the rules-users mailing list