view CWEP-002.rst @ 6:f00e0e8cdeaf

CWEP-003: proof-reading
author Nicolas Chauvat <nicolas.chauvat@logilab.fr>
date Thu, 13 Feb 2014 17:11:45 +0100
parents c628b3e8a6f1
children 0de3fa52f5a5
line wrap: on
line source
CWEP-0002 RQL rewriting
=======================

:champion: Lea Capgen
:reviewers: COPIL
:last update: 2014/01/10
:status: draft


Computed relations
------------------

Schema definition
~~~~~~~~~~~~~~~~~

.. sourcecode:: python

    class illustrator_of(ComputedRelationType):
	rule  = ('C is Contribution, C contributor S, C manifestation O,'
		 'C role R, R name "illustrator"')

* define a virtual `illustrator_of` relation type

* XXX alternative proposition `ComputedRelation`

* possible (subject, object) are infered from the rule

* cardinality can't be specifed and is forced '**'

* nothing else may be defined on the `ComputedRelationType` subclass (e.g. no
  permissions, cardinality, etc., `BadSchema` raised on attempt to specify those
  attributes)


Schema API
~~~~~~~~~~

Computed relation type are represented by `ComputedRelationSchema` holding the
special logic.

XXX implementation will tell if we want `ComputedRDef` class for associated
generated relation definitions.

* computed relation definition have empty 'add'/'delete' permissions, this
  should nicely drive the automatic ui


Cubicweb
~~~~~~~~

* computed relation can't be used in SET / DELETE (`BadQuery` exception raised)

* need new entity type for serialization

* computed relations are virtual, RQL is rewritten to handle them and nothing is
  stored in the database. At some point you'll probably want to handle this
  using e.g.

  .. sourcecode::

    class illustrator_of(ComputedRelationType):
	rule  = ('C is Contribution, C contributor S, C manifestation O,'
		 'C role R, R name "illustrator"')
	__annotations__ = {'materialized': True}

See CWEP-XXXX regarding the annotation syntax.

XXX explain why those restrictions


Computed attribute
------------------

Schema definition
~~~~~~~~~~~~~~~~~
.. sourcecode:: python:

    class Company(EntityType):
	name = String()
	total_salary = Int(formula=('Any SUM(SA) GROUPBY X WHERE P works_for X, P salary SA'))

* define a computed `total_salary` attribute on `Company`

* XXX alternative proposition: `ComputedAttribute(formula=<rql>)`, actual type
  being infered from the formula.

* every other attribute's property should/could be defined, including
  permissions.

* cardinality can't be specifed and is forced '?*'

Schema API
~~~~~~~~~~

XXX alternative:

  Computed attributes are represented by `ComputedAttribute` holding the special
  logic.

vs

  Computed attributes are represented by regular type with a 'formula' property
  set to a value.


Similarly to computed relation:

* computed attribute can't be used in SET / DELETE (`BadQuery` exception raised)

* computed attribute have empty 'add'/'update' permissions


Cubicweb
~~~~~~~~

* computed attributes are materialized, hooks are generated to handle them and
  value is stored in the database. At some point you'll probably want to handle
  this using e.g.

  .. sourcecode::


    class Company(EntityType):
	name = String()
	total_salary = Int(formula=('Any SUM(SA) GROUPBY X WHERE P works_for X, P salary SA'))
	total_salary.__annotations__ = {'materialized': False}