Skip to content
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

Relax rule validation to allow unanswerable but coherent rules #6801

Merged

Conversation

flyingsilverfin
Copy link
Member

@flyingsilverfin flyingsilverfin commented May 2, 2023

What is the goal of this PR?

We allow rules to be written in a way that is semantically sensible in the schema, but may not produce any answers (specifically, if when types can't have any instances because they are abstract).

We therefore match the current behaviour of match queries: match $r isa relation; does not throw any exceptions even if there are no concrete subtypes of relation. As a result, after this change, it will be possible to write rules that will never trigger any inferences, since never match any concrete types.

This change allows writing and sharing 'general' rules that work over an abstract schema, only to be specialised at a later part of the development cycle.

Note that a rule then must still be written using concrete, insertable types.

What are the changes implemented in this PR?

We relax rule validation to log a server-side warning if the rule is not answerable, but it is coherent (eg. it makes sense in the schema).

@typedb-bot
Copy link
Member

typedb-bot commented May 2, 2023

PR Review Checklist

Do not edit the content of this comment. The PR reviewer should simply update this comment by ticking each review item below, as they get completed.


Trivial Change

  • This change is trivial and does not require a code or architecture review.

Code

  • Packages, classes, and methods have a single domain of responsibility.
  • Packages, classes, and methods are grouped into cohesive and consistent domain model.
  • The code is canonical and the minimum required to achieve the goal.
  • Modules, libraries, and APIs are easy to use, robust (foolproof and not errorprone), and tested.
  • Logic and naming has clear narrative that communicates the accurate intent and responsibility of each module (e.g. method, class, etc.).
  • The code is algorithmically efficient and scalable for the whole application.

Architecture

  • Any required refactoring is completed, and the architecture does not introduce technical debt incidentally.
  • Any required build and release automations are updated and/or implemented.
  • Any new components follows a consistent style with respect to the pre-existing codebase.
  • The architecture intuitively reflects the application domain, and is easy to understand.
  • The architecture has a well-defined hierarchy of encapsulated components.
  • The architecture is extensible and scalable.

@flyingsilverfin flyingsilverfin merged commit 4003ab4 into typedb:development May 3, 2023
@flyingsilverfin flyingsilverfin deleted the relax-rule-answerability branch May 3, 2023 13:13
flyingsilverfin added a commit that referenced this pull request Jun 1, 2023
…pes (#6815)

## What is the goal of this PR?

A follow on from #6801 , we finish the rule validation relaxation implemented there. We further relax the 'then' of the rule to operate over concrete  variables, as long as all the type variables that define _which_ instances to create during materialisation are concrete.

For example:
```
define
abstract-person sub entity, abstract, plays friendship:friend; #abstract
friendship sub relation, relates friend;  #non-abstract

rule concrete-relation-over-abstract-players: 
when { 
   $x isa abstract-person;
} then {
   (friend: $x) isa friendship;
};
```

Is now a legal rule to write since the 'friendship' that would be created is an instance of a concrete type.


## What are the changes implemented in this PR?

* Relax rule 'then' validation to only validate that the type provided in 'isa' constraints may not contain abstract types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants