-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeDB 3.0: list role players and changes to standard role definitions #7029
Labels
Milestone
Comments
flyingsilverfin
changed the title
TypeDB 3.0: list role players and default cardinalities
TypeDB 3.0: list role players and changes to standard role definitions
Apr 5, 2024
Will array ops be available? Some detailed example: #6327 (comment) |
Right now the default behaviour (and most of your tests are built around this) is WiIl the default I think the most two common cardinality configs are |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem to Solve
Currently there is no way to operate over ordered collections in TypeDB. We address one aspect of this, which is ordering role players within relations.
Current Workaround
Currently, users explicitly order relations with attributes or with a linked-list style relation.
Proposed Solution
We aim to consistently extend TypeQL to have role player list semantics and make it easy for users by drawing strong parallels with attribute ownership (#7028).
Modifications to existing multi-set semantics
Current multiset-semantics syntax:
Currently, this allows a traffic light to have
red
,red
,red
as a 3-way reflexive relation representing a traffic light, in other words, each role type restricts to an unordered multiset of players.We aim to simplify this by introducing defaults and moving to set semantics:
We will make the default cardinality of roles with set semantics
@card(1,1)
and also disallow duplicates.Extension to list semantics
Defining ordered roles
We will allow extending role players to be 'ordered':
We should consider this to be a modification of the existing traffic-light:light roles, excep that now these can be considered a list instead of a set: ordering is provided, duplicates are allowed, and there is no restriction on cardinality. In short, this switches from set semantics to proper list semantics.
Note that this means we cannot easily optimise/index relations with list players, since they can be unbounded, and we should expect them to be in general less performant when traversing from role players to role players without visiting the relation explicitly.
If one requires ordered-set semantics, we can enforce this with an
@distinct
annotation:Inserting ordered players
Insert role players must use list expression. E.g., we can use the bracket constructor for lists:
Inserts will always address entire lists at a time. To easily insert individual role players, we provide a
@replace
annotation. E.g., to append a single role player we may write:Deleting and updating ordered player
Similarly to inserts, deletes will always require us to deal with entire lists in each statement relating to the ordered players of a relation.
Reading ordered players (data read)
Set-semantically data can be read as before:
However, lists can be read as either individual elements of a collection or as an entire ordered list:
Note that we are now introducing variables that contain an ordered collection of concepts! Eg. the type of
$lights
isList<Light>
orOrderedSet<Light>
depending on the annotations provided in the schema.We should be able to index into the ordered collection as one would expect:
Reading ordered roles (schema read)
Ordered roles can by read from schema. The basic principle is that type variables
$type
will always match simple schema types, but that we may apply the list type operator ([]
) to them just as we can apply it to simple types (e.g.string -> string[]
,edge -> edge[]
). Thus, when variabilizing the role type in:we would obtain:
In this case,
$role_type
will match the role typetraffic-light:light
.The text was updated successfully, but these errors were encountered: