-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7542 from Mats-SX/3.1-named-paths-pattern-compreh…
…ensions Support named paths in pattern comprehensions
- Loading branch information
Showing
21 changed files
with
561 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...nternal/compiler/v3_1/ast/conditions/noUnnamedPatternElementsInPatternComprehension.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.cypher.internal.compiler.v3_1.ast.conditions | ||
|
||
import org.neo4j.cypher.internal.frontend.v3_1.ast._ | ||
import org.neo4j.cypher.internal.compiler.v3_1.tracing.rewriters.Condition | ||
import org.neo4j.cypher.internal.frontend.v3_1.Foldable._ | ||
|
||
case object noUnnamedPatternElementsInPatternComprehension extends Condition { | ||
|
||
override def name: String = productPrefix | ||
|
||
override def apply(that: Any): Seq[String] = that.treeFold(Seq.empty[String]) { | ||
case expr: PatternComprehension if containsUnNamedPatternElement(expr.pattern) => | ||
acc => (acc :+ s"Expression $expr contains pattern elements which are not named", None) | ||
} | ||
|
||
private def containsUnNamedPatternElement(expr: RelationshipsPattern) = expr.exists { | ||
case p: PatternElement => p.variable.isEmpty | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...cypher/internal/compiler/v3_1/ast/rewriters/inlineNamedPathsInPatternComprehensions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.cypher.internal.compiler.v3_1.ast.rewriters | ||
|
||
import org.neo4j.cypher.internal.frontend.v3_1.ast._ | ||
import org.neo4j.cypher.internal.frontend.v3_1.{Rewriter, bottomUp} | ||
|
||
case object inlineNamedPathsInPatternComprehensions extends Rewriter { | ||
|
||
private val instance = bottomUp(Rewriter.lift { | ||
case expr @ PatternComprehension(Some(path), pattern, predicate, projection) => | ||
val patternElement = pattern.element | ||
expr.copy( | ||
namedPath = None, | ||
predicate = predicate.map(_.inline(path, patternElement)), | ||
projection = projection.inline(path, patternElement) | ||
)(expr.position) | ||
}) | ||
|
||
private implicit final class InliningExpression(val expr: Expression) extends AnyVal { | ||
def inline(path: Variable, patternElement: PatternElement) = | ||
expr.copyAndReplace(path) by { | ||
PathExpression(projectNamedPaths.patternPartPathExpression(patternElement))(expr.position) | ||
} | ||
} | ||
|
||
override def apply(v: AnyRef): AnyRef = instance(v) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...cypher/internal/compiler/v3_1/ast/rewriters/namePatternComprehensionPatternElements.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.cypher.internal.compiler.v3_1.ast.rewriters | ||
|
||
import org.neo4j.cypher.internal.compiler.v3_1.planner.logical.PatternExpressionPatternElementNamer | ||
import org.neo4j.cypher.internal.frontend.v3_1.ast._ | ||
import org.neo4j.cypher.internal.frontend.v3_1.{Rewriter, bottomUp} | ||
|
||
case object namePatternComprehensionPatternElements extends Rewriter { | ||
|
||
private val instance = bottomUp(Rewriter.lift { | ||
case expr: PatternComprehension => | ||
val (namedComprehension, _) = PatternExpressionPatternElementNamer(expr) | ||
namedComprehension | ||
}) | ||
|
||
override def apply(v: AnyRef): AnyRef = instance(v) | ||
} |
35 changes: 35 additions & 0 deletions
35
...o4j/cypher/internal/compiler/v3_1/ast/rewriters/namePatternPredicatePatternElements.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.cypher.internal.compiler.v3_1.ast.rewriters | ||
|
||
import org.neo4j.cypher.internal.frontend.v3_1.ast._ | ||
import org.neo4j.cypher.internal.compiler.v3_1.planner.logical.PatternExpressionPatternElementNamer | ||
import org.neo4j.cypher.internal.frontend.v3_1.{Rewriter, bottomUp} | ||
|
||
case object namePatternPredicatePatternElements extends Rewriter { | ||
|
||
override def apply(in: AnyRef): AnyRef = instance.apply(in) | ||
|
||
private val instance: Rewriter = bottomUp(Rewriter.lift { | ||
case expr: PatternExpression => | ||
val (rewrittenExpr, _) = PatternExpressionPatternElementNamer(expr) | ||
rewrittenExpr | ||
}) | ||
} |
44 changes: 44 additions & 0 deletions
44
...ain/scala/org/neo4j/cypher/internal/compiler/v3_1/ast/rewriters/nameUpdatingClauses.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.cypher.internal.compiler.v3_1.ast.rewriters | ||
|
||
import org.neo4j.cypher.internal.frontend.v3_1.ast._ | ||
import org.neo4j.cypher.internal.frontend.v3_1.{Rewriter, bottomUp} | ||
|
||
case object nameUpdatingClauses extends Rewriter { | ||
|
||
def apply(that: AnyRef): AnyRef = instance(that) | ||
|
||
private val findingRewriter: Rewriter = Rewriter.lift { | ||
case createUnique@CreateUnique(pattern) => | ||
val rewrittenPattern = pattern.endoRewrite(nameAllPatternElements.namingRewriter) | ||
createUnique.copy(pattern = rewrittenPattern)(createUnique.position) | ||
|
||
case create@Create(pattern) => | ||
val rewrittenPattern = pattern.endoRewrite(nameAllPatternElements.namingRewriter) | ||
create.copy(pattern = rewrittenPattern)(create.position) | ||
|
||
case merge@Merge(pattern, _) => | ||
val rewrittenPattern = pattern.endoRewrite(nameAllPatternElements.namingRewriter) | ||
merge.copy(pattern = rewrittenPattern)(merge.position) | ||
} | ||
|
||
private val instance = bottomUp(findingRewriter, _.isInstanceOf[Expression]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.