typedb / typeql

TypeQL: the power of programming, in your database
https://typedb.com
Mozilla Public License 2.0
219 stars 46 forks source link

Roles should be scoped within Relations #107

Closed flyingsilverfin closed 3 years ago

flyingsilverfin commented 4 years ago

Problem to Solve

Roles are currenty globally scoped, which not only makes naming more difficult, but also increases complexity of Graql as we can share roles across unrelated parts of the type hierarchy.

Proposed Solution

We will scope roles to belong to relations. In other words, roles will be scoped to a relation and not live independently. This will making naming much simpler, as roles will be interpreted within the context of the relation name the user is providing.

flyingsilverfin commented 4 years ago

Further, we want to add the ability to override a role in a sub-relation using as, which will block the sub-relation from inheriting the role form the parent. Not writing anything should simply inherit the role that is related in the parent.

flyingsilverfin commented 4 years ago

Corner cases:

haikalpribadi commented 4 years ago

There will also be a syntax change to Graql, @flyingsilverfin :

When you define roles in a relation, such as

marriage sub relation,
  relates husband,
  relates wife;

You will refer to the roles being played by an entity, such as:

man sub person,
  plays marriage:husband;

When a relation inherits a role from a parent relation, such as the role child below:

parenthood sub relation,
  relates parent,
  relates child;

motherhood sub parenthood,
  relates mother as parent;
  # the role 'child' is inherited

You must can only refer to the child role through the relation it was first declared:

person sub relation,
  plays parenthood:child;
haikalpribadi commented 4 years ago

Can you aggregate all the comments (both of yours and mine) into a clear breakdown of changes included in this issue, in the issue description, @flyingsilverfin? All this should be one big change that goes in together.

flyingsilverfin commented 4 years ago

@haikalpribadi sure - do you think inheriting roles is a prerequisite? the change is going to be big already, might be worth breaking it down where we can and doing first inheritance, then making the syntax changes.

haikalpribadi commented 4 years ago

Note that some of the changes will be in Graql, and some are in Grakn Core. You can break them into the respective smaller task and put the issue in the correct repo, if that helps you. Make sure to reference them in this issue description - have a checklist of complete ones would be very useful.

JRWest2000 commented 4 years ago

Typo in comment by @haikalpribadi https://github.com/graknlabs/graql/issues/107#issuecomment-602491168
person sub relation; should be person sub entity; this would align it with the latter comment

You will refer to the roles being played by an entity, such as:

man sub person,

JRWest2000 commented 3 years ago

is this fully implemented, if so should this issue be closed, If not how about a description of what is and is not working and why are the changes to the language not documented in the TypeDB release notes

flyingsilverfin commented 3 years ago

they were documented in the first 2.0 graql/typeql release notes, but you're right it should be closed