Skip to content

Constraints for edges #1174

Closed
Closed

Description

@lvca

Discussed in #1026

Originally posted by lvca April 10, 2023
Recently asked on Discord, but discussed in many other topics and issues, we'd need a way to create constraints for edges so they can be attached only to specific vertex types.

The most natural way to achieve this is to mimic what OrientDB does: create constraints on out and in properties. While in OrientDB out and in are real properties in the document, with ArcadeDB are managed in binary form (much faster), but then exposed to the users as respectively @out and @in metadata.

To provide constraints on edge we could simply allow the following syntax alter property Friend.@out linkedtype Account;alter property Friend.@in linkedtype Account (in OrientDB was LINKEDCLASS). This would mean Friend edge type can only connect Account to another Account.

Activity

  1. added
    enhancement
    on Jul 18, 2023
  2. self-assigned this
    on Jul 18, 2023
  3. lvca commented on Jul 18, 2023

    @lvca
    MemberAuthor

    In the end I used just of:

    CREATE EDGE TYPE HasParts
    CREATE PROPERTY HasParts.`@out` link OF Product
    CREATE PROPERTY HasParts.`@in` link OF Component

    You can now set constraints also for LIST, MAP, and EMBEDDED. Example (part of the test suite):

    create document type Invoice
    create document type Product
    CREATE PROPERTY Invoice.products LIST of Product
    CREATE PROPERTY Invoice.tags LIST of String
    CREATE PROPERTY Invoice.settings MAP of String
    CREATE PROPERTY Invoice.mainProduct LINK of Product
    CREATE PROPERTY Invoice.embedded EMBEDDED of Product
  4. added this to the 23.7.1 milestone on Jul 18, 2023
  5. lvca commented on Jul 18, 2023

    @lvca
    MemberAuthor

    I forgot 3 things:

    1. The validation if polymorphic. So in the example above, Invoice.products is a LIST of Product, but you can also insert any sub-type of Product
    2. If the constraint is not validated, a ValidationException is thrown
    3. There is no support for ALTER PROPERTY right now, so the linked type must be defined at creation time. To apply updates, just drop and re-create the property (changes to the schema don't update the records)
  6. lvca commented on Jul 18, 2023

    @lvca
    MemberAuthor

    It's 100% implemented under the main branch. @gramian could you please help with the docs of this new part?

    Also, now that we have such constraints, Studio could display a UML-like diagram of types and relationships.

  7. gramian commented on Jul 18, 2023

    @gramian
    Collaborator

    Very cool. I help with the docs, too.

  8. gramian commented on Jul 18, 2023

    @gramian
    Collaborator

    About your hasParts example: Why do I have to CREATE @in and @out properties and not use ALTER?

  9. lvca commented on Jul 18, 2023

    @lvca
    MemberAuthor

    Because the properties don't exist in the schema. If don't exist, they are considered as simple RID. But keep in mind @out and @in are not regular properties but hardcoded in the vertex/edge records.

  10. lvca commented on Jul 18, 2023

    @lvca
    MemberAuthor

    Docs are in place, thanks @gramian. Closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions