[Cubicweb] CWEP-0002 - RQL rewriting
Aurélien Campéas
aurelien.campeas at logilab.fr
Fri Dec 13 17:26:55 CET 2013
On 13/12/2013 17:11, Léa Capgen wrote:
> Hi Cubicweb users,
>
> Here is the first hints about allowing users rewriting RQL.
>
> Léa,
>
Hi Léa,
>
> Rationale
> ==========
>
>
> Logilab has been thinking about rules and RQL rewriting for years, but
> never had the time. Using rules in database queries is not a new topic,
> that dates back to the 70s (read about Datalog_ for example).
>
> .. _Datalog: http://en.wikipedia.org/wiki/Datalog
>
> With rules and RQL rewriting, we could have syntactic sugar for almost
> free and have more flexible schemas that define relations and attributes
> that we can chose not to materialize at the SQL table level.
>
> Here are a few examples of use cases. A more complete document can be
> found here:
>
> http://hg.logilab.org/users/lcapgen/cw_rules/file/44522d5906d4/cw-regles-utilisations.rst
>
>
> Proposal
> ========
>
> Relation rewriting
> --------------------------
>
> Instead of::
>
> Any A,B WHERE C is Contribution, C contributor A, C manifestation B,
> C role R, R name "illustrator"
>
> we would like to write::
>
> Any A,B WHERE A illustrator_of B
>
> after adding a rule to the schema as follows:
>
> .. sourcecode:: python
>
> class illustrator_of(RelationDefinition):
> subject = 'Person'
> object = 'Manifestation'
> rule = ('C is Contribution, C contributor S, C manifestation O,'
> 'C role R, R name "illustrator"')
>
>
So is illustrator_of actually:
* a pure read-only, not db-backed, kindof "virtual" relation ?
* a computed relation ?
* would the (default) primary views of a Person show it ? hide the
contributions ?
* what about the edition forms ?
>
> Computed attribute
> ----------------------------
>
> Instead of::
>
> Any SUM(SA) GROUPBY S WHERE P works_for S, P salary SA
>
> we would like to write::
>
> Any A WHERE S total_salary A
>
> after adding to the schema a rule for the computed attribute as follows:
>
> .. sourcecode:: python
>
> class Company(EntityType):
> name = String()
> total_salary = Int(computed=('Any SUM(SA) GROUPBY S WHERE P
> works_for S, P salary SA'))
>
I'd ask the exact same questions, plus:
* what happens if it is actually in the backend and one writes:
c.cw_set(total_salary=42) ?
>
>
> Map RDF to Yams
> -------------------------
>
> Given the following XY equivalences:
>
> .. sourcecode:: python
>
> xy.add_equivalence('CWUser', 'foaf:Person')
> xy.add_equivalence('Person', 'foaf:Person')
>
> when writing::
>
> Any S WHERE S is foaf:Person
>
> we would like the query to be rewritten as::
>
> Any A WHERE A is IN(Person, User)
>
>
> Implementation
> ===============
>
> A first implementation is available here:
>
> http://hg.logilab.org/review/rql/rev/3a74699faa12
>
> http://hg.logilab.org/review/yams/rev/501931830b3a
>
> http://hg.logilab.org/review/cubicweb/rev/972a53c416a8
>
>
> Discussion
> ==========
>
> Please comment. Known limitations can be found here:
>
> http://hg.logilab.org/users/lcapgen/cw_rules/file/44522d5906d4/cw-regles-limitations.rst
Regards,
Aurélien.
More information about the Cubicweb
mailing list