- From: Juan Sequeda <juanfederico@gmail.com>
- Date: Tue, 27 Jul 2010 08:52:13 -0500
- To: "Eric Prud'hommeaux" <eric@w3.org>
- Cc: public-rdb2rdf-wg@w3.org
- Message-ID: <AANLkTi=pmhSP0B0HW5=eVgz9o+EMbDDGR6iUpJ_Xjw99@mail.gmail.com>
:) Juan Sequeda +1-575-SEQ-UEDA www.juansequeda.com On Tue, Jul 27, 2010 at 8:26 AM, Eric Prud'hommeaux <eric@w3.org> wrote: > Just so we can all speak each others' languages, here's a definition > of a view in SQL, Datalog (Horn Rules without functions) and RIF¹. > Imagine two tables, Employees and Departments: > > Employees(emp_id, fname, lname, dept) > Departments(dpt_id, deptname, manager) > > CREATE TABLE Employees(emp_id INT PRIMARY KEY, fname STRING, lname STRING, > dept INT) > CREATE TABLE Departments(dpt_id INT PRIMARY KEY, deptname STRING, manager > INT) > > In SQL, we can create a view of employees and their managers, > EmpManager: > > CREATE VIEW EmpManager AS > SELECT (e.emp_id, e.fname, e.lname, m.fname, m.lname) > FROM Employees AS e > JOIN Departments AS d ON d.dpt_id=e.dept > JOIN Employees AS m ON m.emp_id=d.manager > > We can write this in Datalog: > > EmpManager(EMP_ID, E_FNAME, E_LNAME, M_FNAME, M_LNAME) :- > Employees(EMP_ID, E_FNAME, E_LNAME, DEPT), > Departments(DEPT, _, MANAGER), > Employees(MANAGER, M_FNAME, M_LNAME, _) > > or in RIF's n-ary predicate syntax: > > Document( > Base(<http://mydb.example/#>) > Group ( > Forall ?emp_id ?e_fname ?e_lname ?e_dept > ?e_dept, ?deptName, ?manager > ?manager ?d_fname ?d_lname ?d_dept ( > EmpManager(?emp_id, ?e_fname, ?e_lname, ?m_fname, ?m_lname) :- > Employees(?emp_id, ?e_fname, ?e_lname, ?dept), > Departments?(dept, ?deptName, ?manager), > Employees(?manager, ?m_fname, ?m_lname, m_dept) > ) > ) > ) > > ¹ If Employees or Departments did not have unique keys (labeled > "PRIMARY KEY" in the SQL definitions), these wouldn't be strictly > identical views as the SQL operational semantics preserves > cardinality over multisets, while the others use set semantics for > their predicates and specifically avoid an operational semantics. > > For interested parties, the RIF semantics are defined at > http://www.w3.org/TR/rif-bld/#Direct_Specification_of_RIF-BLD_Semantics > > -- > -ericP > >
Received on Tuesday, 27 July 2010 13:52:48 UTC