Re: representing summarize via basic operators
Date: Wed, 23 Aug 2006 23:15:20 GMT
Message-ID: <ck5Hg.446935$Mn5.70341_at_pd7tw3no>
Aloha Kakuikanu wrote:
> On page 18 of the "New Algebra"
>
> http://www.dcs.warwick.ac.uk/~hugh/TTM/APPXA.pdf
>
> D&D express summarize via basic Tutorial D operators. This construction
> is not obvious to me (especially that I'm not versatile in Tutorial D
> syntax). Can anybody please clarify it step by step on a simple
> example?
>
> Suppose we have an input relation:
>
> { (x=a,y=1), (x=b,y=1), (x=c,y=1) }
>
> What applications of classic Relational Algebra operations would
> produce the relation
>
> { (sum=3) }
>
> ? Certainly, infinite relations like "PLUS" (p.5) are allowed:-)
>
In case you don't have the printed book, on page 160 of the 2nd edition, they give this example for count rather than sum:
(quote, I hope)
SUMMARIZE SP PER S {S#} ADD COUNT AS NP which is shorthand for
( EXTEND S { S# }
ADD ( ( ( SP RENAME S# AS X ) WHERE X = S# ) AS Y, COUNT ( Y ) AS NP )
{ S#, NP}
Step-at-a-time version:
WITH ( S { S# } ) AS t1 ,
( SP RENAME S# AS X ) AS t2 , ( EXTEND t1 ADD ( t2 WHERE X = S# ) AS Y ) AS t3 , ( EXTEND t3 ADD COUNT ( Y ) AS NP ) AS t4 :t4 { S#, NP }
(end quote)
I know this doesn't give exactly the answer you wanted, but it seems parallel enough and quotes the horse which is likely better than any attempt I could make.
I have no clue how to do it with classical relops.
Regarding the infinite relations - my impression is that D&D don't allow them to be assigned to relvars, but it does seem that they can be used in expressions.
On another topic, I'm still enamoured of the idea of re-defining D&D's PROJECT/RENAME in terms of the TA - which definition is almost already in TTM - just lift the definition of <OR>, call it <PROJECT> or somesuch and change tr1 union tr2 to tr1 intersection tr2.
p Received on Thu Aug 24 2006 - 01:15:20 CEST