-
Notifications
You must be signed in to change notification settings - Fork 11
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
Quantified Path Patterns #290
Comments
This task is closely related to #292 |
@angrykoala I'm planning to use the new quantified graph patterns and quantified relationships from 5.9 pretty extensively. I was going to try to see if I could make this update to cypher-builder myself, but it seems it might require some breaking changes to how patterns/partial patterns work.... Did you already have any ideas for how you saw this new syntax getting implemented? |
Hi @tomhayford It would be really helpful if you could share some examples of the type of queries you want to achieve and maybe any though/preference of how the Cypher Builder API would look like? Ideally we should try to avoid breaking changes for this. But we were already planning on releasing CypherBuilder 2.0.0 soonish so it is not the end of the world if we decide to make this for that version, although that would mean waiting a bit more for this to be ready |
A very initial draft on the api could be to add a method to
Translating to
|
My queries are pretty similar in structure the ones on the documentation page.
I was thinking maybe creating an explicit Path container ("Path" right now would conflict with the Path reference... but using it just for illustrative purposes). This could make it clear where the quantifier applies. And could make logic checks easier for the union of quantified paths with other quantified paths or simple paths (need to check for minimum multiplicity and no nested quantified paths/relationships).
|
I'm not sure |
After giving some though to Quantified Patterns. I have the following proposal:
For example: const quantifiedPath = new QuantifiedPath(
new Cypher.Pattern({labels: ["Movie"]}),
new Cypher.Pattern({labels: ["Movie"]}).related({type: "ACTED_IN"}).to({labels:["Person"]}).quantified({min:1, max:4}),
new Cypher.Pattern({variable: node, labels: "Movie"})
) This would translate to the following pattern in Cypher (:Movie) ((:Movie)-[:ACTED_IN]-(:Person)){1,4} (m:Movie) It is not too dissimilar to your proposal @tomhayford, just some renames to avoid collisions. This one shouldn't be breaking either. Any thoughts? Technically, QuantifiedPath is not an accurate name in Cypher, as these refer to a set of node pattern pairs |
Yea, I think that the How would you see that working with Quantified Relationships? I image we'd want a similar implementation using new Cypher.Pattern().related().quantified("+").to()
new Cypher.Pattern().related().quantified({min:2}).to() ()-[]->+()
()-[]->{2,}() Also just thinking out loud with observations on some implementation details (and I'm not sure how much syntax enforcement cypher-builder is intended to provide...) but there is some interesting complexity with the syntax rules that come with Quantified Paths & Quantified Relationships:
|
For QuantifiedRelationships. The syntax could be what you have there, alternatively, it could be part of the options for the relationship (like new Cypher.Pattern().related().quantified("+").to() vs. new Cypher.Pattern().related({quantified: "+"}).to() another third option, a bit different, but would help on correctness would be to have a separate method instead of new Cypher.Pattern().relatedQuantified({quantifier: "+"}).to() Personally, I hate the naming of this option (ideas welcome), but it would ensure that variable length and quantifier are never in the same relationship Regarding the extra class. We can also take the shortcut on keeping the quantifier within the In general for syntax enforcement, while we try to have a syntax and types that promote correct usage, Cypher Builder does not provide any guarantee of Cypher correctness. In general, we try to add any check that can be done through typings (as these will provide helpful warnings in the IDE), but runtime checks are out of scope for now. From the considerations that you raised, I would say that we should pay special attention to the second, third and fifth as these could potentially be enforced through types (although we may not be able to do so without breaking changes) I don't see how we could enforce the first and fourth just with types so I would leave them out of scope for now On top of these considerations, there is another limitation which is making sure that a QuantifiedPattern is composed at least one relationship pattern, not a single node, it could be enforced but we would need a way of differentiating a single node pattern and a relationship pattern with types, which I think would be breaking |
Relevant docs:
The text was updated successfully, but these errors were encountered: