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

Deprecate legacy pattern syntax #9160

Merged
merged 6 commits into from
Apr 11, 2017

Conversation

thobe
Copy link
Contributor

@thobe thobe commented Apr 5, 2017

Ensure that Neo4j Cypher produces warning for pattern matching syntax that will be unsupported or have different semantics in future versions of Cypher.

Binding of relationships from variable length patterns is deprecated.
Queries such as:

MATCH (n)-[rs*]-() RETURN rs

Will generate a warning. The canonical way to write such a query is:

MATCH p=(n)-[*]-() RETURN relationships(p) AS rs

Using colon for each relationship type in a listing of multiple alternative relationship types in conjunction with using in-lined property predicates will change semantics in future versions.
This query:

MATCH ()-[:A|:B|:C{foo:'bar'}]-()

Currently means that the property predicate should apply to all relationships, but in future versions it will mean that the property predicate applies to relationships with type C, while no property predicates apply for relationships of type A or B. On order to achieve the current behaviour in future versions as well, only a single initial colon should be used, like so:

MATCH ()-[:A|B|C{foo:'bar'}]-()

changelog: Deprecated syntax for legacy patterns:

  • Binding a variable in a variable length pattern
  • Binding a variable when using colon for each relationship type in a pattern with multiple types
  • Inlining a property predicate when using colon for each relationship type in a pattern with multiple types
  • Using colon for each relationship type in a variable length pattern with multiple types

Copy link
Contributor

@Mats-SX Mats-SX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see a number of acceptance tests for this.

| EMPTY ~ push(Seq())
private def RelationshipTypes: Rule1[MaybeLegacyRelTypes] = rule("relationship types") (
(":" ~~ RelTypeName ~~ zeroOrMore(WS ~ "|" ~~ LegacyCompatibleRelTypeName)) ~~>> (
(first: ast.RelTypeName, more:List[(Boolean,ast.RelTypeName)]) => (pos:InputPosition) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style: space after type-spec colon, space after comma.

)

private def LegacyCompatibleRelTypeName: Rule1[(Boolean,ast.RelTypeName)] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code style: space after comma.

)

private def LegacyCompatibleRelTypeName: Rule1[(Boolean,ast.RelTypeName)] =
((":" ~ push(true)) | EMPTY ~ push(false)) ~~ RelTypeName ~~>> (
(legacy:Boolean, name:ast.RelTypeName) => (pos:InputPosition) => (legacy,name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style: space after colon and comma.

@@ -122,3 +129,5 @@ trait Patterns extends Parser
optional(WS ~ (MapLiteral | Parameter))
)
}

case class MaybeLegacyRelTypes(types:Seq[ast.RelTypeName] = Seq.empty, legacySeparator:Boolean = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code style: space after colon.

@@ -35,6 +35,10 @@ object SyntaxDeprecationWarnings extends VisitorPhase[BaseContext, BaseState] {
statement.treeFold(Set.empty[InternalNotification]) {
case f@FunctionInvocation(_, FunctionName(name), _, _) if aliases.get(name).nonEmpty =>
(seq) => (seq + DeprecatedFunctionNotification(f.position, name, aliases(name)), None)
case p@RelationshipPattern(Some(variable),_,Some(_),_, _, _) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code style: space after comma.

@@ -35,6 +35,10 @@ object SyntaxDeprecationWarnings extends VisitorPhase[BaseContext, BaseState] {
statement.treeFold(Set.empty[InternalNotification]) {
case f@FunctionInvocation(_, FunctionName(name), _, _) if aliases.get(name).nonEmpty =>
(seq) => (seq + DeprecatedFunctionNotification(f.position, name, aliases(name)), None)
case p@RelationshipPattern(Some(variable),_,Some(_),_, _, _) =>
(seq) => (seq + DeprecatedVarLengthBindingNotification(p.position, variable.name), None)
case p@RelationshipPattern(_,_,_,Some(_),_,true) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code style: space after comma.

)

private def LegacyCompatibleRelTypeName: Rule1[(Boolean,ast.RelTypeName)] =
((":" ~ push(true)) | EMPTY ~ push(false)) ~~ RelTypeName ~~>> (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is the line that sets the warning condition. So the warning will be emitted when doing

MATCH ()-[:FOO | :BAR]->()

but not when doing

MATCH ()-[:FOO | BAR]->()

and the presence of an inlined property predicate is not checked for. It would be nice to have some acceptance tests that confirms this interpretation.

DEPRECATED_BINDING_VAR_LENGTH_RELATIONSHIP(
SeverityLevel.WARNING,
Status.Statement.FeatureDeprecationWarning,
"Binding relationships to a list in a variable length pattern is deprecated."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find where this condition is checked, but perhaps that's still TODO?

@thobe
Copy link
Contributor Author

thobe commented Apr 6, 2017

I wonder if we also need to deprecate binding together with colon in alternatives. That would make the future syntax easier to implement.

i.e.

MATCH ()-[x:A|:B|:C]-()

@Mats-SX Mats-SX self-assigned this Apr 6, 2017
@thobe thobe force-pushed the 3.2-deprecate-legacy-pattern-syntax branch from d11fd04 to b9d1ceb Compare April 10, 2017 07:02
Copy link
Member

@boggle boggle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at this pairing w mats and am in favour of this.

@Mats-SX Mats-SX merged commit 8684110 into neo4j:3.2 Apr 11, 2017
@thobe thobe deleted the 3.2-deprecate-legacy-pattern-syntax branch April 11, 2017 07:32
@NicholasIoanJones
Copy link

I'm trying to model a situation where there is a heirarchy of organisations such that OrgA can be a MEMBEROF OrgB. Similarly User1 can be MEMBEROF OrgA. Finally a person P1 can give CONSENT to access their account details to either a User or an Organisation, with the expectation being that consent can flow from an Organisation to it's member orgs and ultimately to users.
I can then see who has CONSENT to see a persons account by querying
MATCH (p:Person{PersonID:10000002})-[:CONSENTS]->(o)<-[t:MEMBEROF *0..5]-(accessor) RETURN p, o, t, accessor
This seems to work and is reasonably concise but Neo4J says that this is deprecated - relating it to this change. How should I write this query?

@Mats-SX
Copy link
Contributor

Mats-SX commented May 16, 2017

@NicholasIoanJones The canonical way, as outlined above, suggests your query in this form:

MATCH (p:Person {PersonID: 10000002})-[:CONSENTS]->(o),
  memPath = (o)<-[:MEMBEROF*0..5]-(accessor)
RETURN p, o, relationships(memPath) AS t, accessor

Note: Cypher style guide recommends property keys be written in camelCase with small starting character.

@NicholasIoanJones
Copy link

Thanks Mats, that works perfectly. I obviously need to read more and try out more to get my head better in tune with this. Style comment noted as well.

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.

None yet

4 participants