Re: Couple of questions...

John Lenton <[email protected]> Wed, 21 Apr 2004 19:12:09 -0300
Newsgroups gmane.comp.python.modeling
Message-ID <[email protected]>
Sender: John Lenton <[email protected]>

On Tue, Apr 20, 2004 at 11:46:10PM +0200, Sebastien Bigaret wrote:
> 
>   Yes, that's another approach indeed. But while I'm a fervent defender
> for KeyValueCoding ;)) in such cases one should be careful. Here are
> some thoughts:
> 
>   - if the database have a lot of books, the KVC approach will load them
>     all in memory: KVC traverses relationships at the object level, and
>     in this case this means fetching Books published by every Publisher,
>     then these Books' Authors. This is probably the worst case one can
>     get. That's probably why you were asking for a callable vFKP on a
>     class, weren't you?
> 
>   - In the resulting lists, if an author has published N books for a
>     publisher, the corresponding list will receive N duplicates for that
>     author.

agreed, and I think I pointed out (I know I tried to point out) the
second one of these. However the first is what I understood was being
requested.

The way I think I'd *like* to solve the second one is along the lines of

  ec.fetch('Writer.books.publisher', unique=True)

or, perhaps (if something sensible can be found to fill in the
ellipsis),

  ec.fetch('Writer.books.publisher', groupBy='...')


The first could be ameliorated by having fetch return an iterator
instead of a list...

 in fact...

  if fetch returned something smarter than a list, it might be
  possible to do something like

    ec.fetch('Writer') - \
        ec.fetch('Writer', 'books.publisher.bizName == "P1"')

  this means ec.fetch returns a set, as in relational algebra[1] sets,
  which you can operate on. These set objects wouldn't perform the
  select on the database until you accessed them as sequences, so the
  above wouldn't even touch the database until someone used the result
  for something other than operating on other sets. Maybe 'fetch' is a
  bad name for a method returning something that hasn't actually
  fetched :)

  If this falls in the 'intersting, but show me the code' category,
  I'm afraid it'll have to wait :(

On Wed, Apr 21, 2004 at 10:55:26PM +0200, Mario Ruggier wrote:
> ec.fetch('Writer', 'books.publisher.numPages>50
> AND (books.publisher.bizName IN ["P1","P2"])
> AND NOT EXISTS(books.publisher.country NOT IN ["c1","c2"] ) '

well, that's the same as

    ec.fetch('Writer', 'books.publisher.numPages > 50 \
            AND books.publisher.bizName IN ["P1", "P2"]') - \
        ec.fetch('Writer', 'books.publisher.country IN ["c1","c2"]')

right?

  
References:
1) http://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter3/node7.html

-- 
John Lenton ([email protected]) -- Random fortune:
Above all else -- sky.


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click