-
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
Fix difficult TypeQL expressions #6986
Comments
Given the following query, which is intended to return the name of anything in the UK:
Currently, if there are types that play
Adding Current behaviour is rooted in pre-Fetch versions of TypeDB, in which attributes had to be bound in the |
In many queries we often want to retrieve the type or role played of an instance. This is done with the following patterns:
These currently retrieve type
But if we want to retrieve only the exact role, we need to use:
or
depending on the exact intent. Unlike the type case, the role case is significantly more complex when retrieving the exact role. This behaviour is also unintuitive, when compared with most programming languages. Typically when we retrieve instances of a type, we also want to retrieve instances of its subtypes. Conversely, when we want to retrieve the type of an instance, we typically only want the exact type. Retrieving all of its types is the edge case rather than the typical case. A simple solution to this would be to make the use of
|
I also encountered this unexpected behavior with the following simple query (don't mind the
With the following schema:
And the error sounds like:
|
Retrieving multiple aggregates over the same set of values is pretty cumbersome at the moment, as each aggregate subquery can only retrieve one aggregate.
This isn't very DRY. It would be much better if aggregates could be made more of a "first-class citizen" of Fetch queries. The following syntax would be much nicer, for instance.
This change to Fetch queries would also allow aggregates to be retrieved without using subqueries or a Get query, for instance as follows.
Of course, there are many practical elements not yet considered. One is how a |
I was trying to fetch all subtypes of a type in a meaningful way so that I could visualize the hierarchy between them.
But it didn't work, as it produced the following error:
But I think we should be able to do something like this in TypeQL (when we are using different keywords (like I've come up with a workaround for this query:
But that feels like hacking our type check. P.S. I think Christoph had another use case for having multiple |
This issue is primarily for difficult syntax that does not actually affect expressivity, but I'll also point out this issue: vaticle/typeql#325. I've made it a separate issue as it does affect expressivity. |
Currently, TypeDB does not support SQL-style cascading deletes. This makes almost all practical deletions of entities (and relations playing roles) unintuitive, and potentially very difficult, to do correctly. If not done correctly, relations the entity was playing a role in remain in the database, but with one roleplayer less. These relations are not semantically sound in many cases. The best practice for deleting entities in a generalised manner is detailed in Lesson 4.3 of the new learning course. It requires three queries: one query to retrieve the key attributes of the entities to be deleted (if not already known), another query to delete any relations the entities play roles in, and then a third query to delete the entities themselves. This will guarantee that no dangling relations are left after the entities are deleted, but makes certain assumptions:
If either of this assumptions is not correct, then this strategy will not work. Dangling relations will be left, or a bad delete may occur in which too much or not enough data is deleted. In fact, a generalised strategy for deleting any entity (or relation that plays roles) is currently not possible without making use of IIDs and an additional query per level of relation nesting, requiring an acute understanding of both TypeDB and the specific data model in use to pull off without error. The current lack of cascading deletes makes correclty deleting data unnecessarily difficult. Even if the above assumptions are satisfied, three queries is exceedingly verbose for ensuring a single entity is correctly deleted. |
The deletion sometimes has "a ripple effect" where one deletes an entity and then it's attributes need to be deleted and afterward it's relations and then attributes on the relations and relations related to the relations. I think that as typeDB is closely related to the various development languages so are the various expectations from it like GC. Update also is somewhat unintuitive and may end up with an attribute without anything linked to it that requires an extra query to check if the last link was removed and then clean up (after creating a new one linking to it and removing the previous link). |
Going forward with the development language analogy I think that the expected following requirements that will be asked will be a few basic "data structures" to simplify working with complex sets of objects (e.g., ordered list, not as an attribute type which can be nice, but as ability to easily collect entities in an ordered list - it is currently possible but hard and unintuitive) |
I think that making a query to check if a thing is contained in a set of given things or the other way around that a thing is answering all of a set of constraints is currently possible (through OR) but harder than it should. https://www.w3schools.com/sql/sql_in.asp is quite intuitive Found this: vaticle/typeql#213 and this #6321 |
I am putting it here to be documented but it can be moved or deleted. I am not sure what the ideal solution should be but maybe evolving TypeQL on the single path of MATCH and allowing the user to choose to "flatten" the response to JSON as part of the query or the session connection. This can be done by supplying a default way to "flatten" the result to JSON and allowing the user to supply a "flattening mapping schema" along the query or activate a specific predefined "flattening mapping schema" that is part of the schema. Other ideas are welcomed. |
Optional retrieval was discussed already but raising again the following option
The idea is to break a bit the strong coupling between the
Will return
|
Allow multiple |
Create a Cypher to TypeQL converter
Created an issue with this idea for it: #7031 |
Have you seen Side note: let's try to keep this issue for collecting big UX issues, mostly for @james-whiteside and discussion to discord/forum/precise issues. |
Allow composition of interface implementations into high-level traits: |
Allow negations and disjunctions without exterior bindings: |
Allow variables in disjunction branches to be fetched, and referenced in subqueries. |
Problem to Solve
Some simple queries are difficult to express in TypeQL, and present a significant barrier to the early user journey. This issue will serve as a place to collate them.
Example
For the following schema:
It is difficult to write a query that "inserts a person with a given name, only if a person with that name does not already exist".
The following theoretical query would achieve that, but is not currently valid:
This is because
match
clauses cannot have unbound nested patterns, a recurring theme in many difficult-to-express queries. The following is the best current workaround:This workaround is particularly unintuitive and basically a hack.
The text was updated successfully, but these errors were encountered: