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

TypeQL syntax updates #383

Merged
merged 11 commits into from
Dec 18, 2024
Merged

Conversation

krishnangovindraj
Copy link
Member

@krishnangovindraj krishnangovindraj commented Dec 10, 2024

Usage and product changes

Adds let keyword before assignments & moves the constraint on an isa to the end. E.g. $x isa marriage ($a, $b)

@typedb-bot
Copy link
Member

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.

@krishnangovindraj krishnangovindraj changed the title Shorthands TypeQL syntactic sugar Dec 10, 2024
@krishnangovindraj krishnangovindraj marked this pull request as ready for review December 13, 2024 12:12
@krishnangovindraj krishnangovindraj changed the title TypeQL syntactic sugar TypeQL syntax updates Dec 13, 2024
@krishnangovindraj krishnangovindraj self-assigned this Dec 13, 2024
@krishnangovindraj krishnangovindraj merged commit 8acf8f2 into typedb:3.0 Dec 18, 2024
3 of 6 checks passed
flyingsilverfin added a commit to typedb/typedb that referenced this pull request Dec 19, 2024
## Release notes: product changes

We mirror the changes from typedb/typeql#383,
which is composed of 3 changes:

1) We now require that all assignments are preceded with a `let`
keyword:
```
match
 $p isa person, has monthly-salary $monthly;
 let $annual_salary = $monthly * 12;
```

2) We rename `long` to `integer`, to use a more familiar term for
integer values (`long` is very c-like!)
```
define
  attribute age, value integer;
```
This is still defined as a 64-bit signed integer in TypeDB's backend.

3) We make a consistent constructor syntax for instances:
```
insert
  $p isa person;      # create entity
  $f isa friendship (friend: $p);    # create relation with players
  $a isa age 20;      # create attribute with value
```

Previously, we would write this as:
```
insert 
  $p isa person;
  $f (friend: $p) isa friendship;
  $a isa age; $a == 20;
```

Note that the _anonymous relation constructor_ is now allowed like this:
```
insert
  friendship (friend: $p) ;
```
instead of:
```
insert
  (friend: $p) isa friendship;
```
 


## Motivation

For 1), the `let` binding makes it clearer to users when a attribute
value is a computed value within the query, and not being looked up from
storage.

For 2), we feel that the `integer` syntax will be clearer and more
familiar to users of most programming languages.

For 3), we resolve a long-standing inconsistency with giving
newly-created attributes a value. We already had the following syntactic
sugar for `has` clauses: `match $x isa person, has age 10;`. We make
this syntactic sugar as the basis of a consistent form for creating
entites, relations, and attributes.


## Implementation

We update all tests using the above syntaxes, and update the translation
phase to use the new TypeQL data structures.

---------

Co-authored-by: joshua <[email protected]>
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