JOIN alternative for partial data?

This forum is for any questions about the language Tutorial D or the Rel implementation of it.
Post Reply
asulling
Posts: 1
Joined: Sun Oct 28, 2018 6:28 am

JOIN alternative for partial data?

Post by asulling » Sat Nov 10, 2018 3:28 am

Hello!

I am new here and still struggling with the big picture, sorry:

Does Tutorial D support a more compact alternative than the example below to the SQL "X left join Y" clause where in the relational domain missing data from Y joined with tuples of X would be marked by (alternatively put: grouped as) an empty new relation Z, and tuples from y in the result would be similarly grouped as relation Z?

If not then what is the Tutorial D philosophy behind not quite supporting such a frequently needed alternative of retrieving highly cohesive data preferably in one operation? What is the Tutorial D approach to retrieving e.g. a list of all persons with phones attached to those associated with at least one?

Code: Select all

VAR person REAL RELATION {name CHARACTER} KEY {name};
VAR phone REAL RELATION {number INTEGER, owner CHARACTER} KEY {number};
CONSTRAINT phone_fkey_person phone { owner } RENAME { owner AS name } <= person { name };
person := RELATION {
    TUPLE {name 'Jack'},
    TUPLE {name 'Jill'},
    TUPLE {name 'Jane'}
};
phone := RELATION {
    TUPLE {owner 'Jack', number 123},
    TUPLE {owner 'Jane', number 456},
    TUPLE {owner 'Jane', number 789}
};
VAR tmp REAL RELATION {name CHARACTER} KEY {name};
tmp := person RENAME {name AS j} SEMIJOIN ( phone RENAME {owner AS j} ) RENAME {j AS name};
tmp := person MINUS tmp;
VAR leftjoin REAL RELATION {name CHARACTER, phones RELATION {number INTEGER}} KEY {name};
leftjoin := EXTEND tmp : {phones := RELATION {number INTEGER} {}};
leftjoin := leftjoin UNION ( person RENAME {name AS j} JOIN ( phone RENAME {owner AS j} ) GROUP {number} AS phones RENAME {j AS name} );

Dave
Site Admin
Posts: 361
Joined: Sun Nov 27, 2005 7:19 pm

Re: JOIN alternative for partial data?

Post by Dave » Tue Nov 13, 2018 9:39 am

As this is a relatively broad question about Tutorial D in general rather than Rel in particular, I encourage you to join the TTM Forum at https://forum.thethirdmanifesto.com and ask your question there.

Post Reply