typedb / typeql

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

Allow matching on types using a type label directly #341

Open dmitrii-ubskii opened 4 months ago

dmitrii-ubskii commented 4 months ago

Problem to Solve

Corrently, when a user attempts to, e.g., match all attributes a specific type may own, they are greeted with a TypeQL error:

test::data::read> match person owns $n;

[TQL03] TypeQL Error: There is a syntax error at line 1:
match person owns $n;
                     ^
no viable alternative at input 'match person owns $n;'

This is because all statements in a match query must currently start with a variable.

Current Workaround

Currently the user would have to introduce a variable binding for the type and either filter it out at the end of the query, or accept an extraneous concept in each answer.

match
  $t type person;
  $t owns $att;
get $att;

Proposed Solution

We could treat person owns $n; as a valid pattern which decomposes into $_0 type person; $_0 owns $n;.

Note that there is no danger in this allowing trivial queries like person owns name; (which would either be redundant or immediately unsatisfiable depending on the schema) because of the requirement that each statement contain a named variable.