Skip to content

Commit

Permalink
Fixes neo4j#390 - IN/ANY/NONE/ANY/SINGLE causes RuntimeException for …
Browse files Browse the repository at this point in the history
…some patterns
  • Loading branch information
systay committed Jan 7, 2013
1 parent 591665f commit 183ba17
Show file tree
Hide file tree
Showing 104 changed files with 233 additions and 207 deletions.
4 changes: 4 additions & 0 deletions community/cypher/CHANGES.txt
@@ -1,3 +1,7 @@
1.9.RC
-------
Fixes #390 - IN/ANY/NONE/ANY/SINGLE causes RuntimeException for some patterns

1.9.M03
-------
o Fixes #336 - Patterns that re-use a pattern node can produce non-existing matches
Expand Down
@@ -0,0 +1,85 @@
/**
* Copyright (c) 2002-2013 "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

import mutation.UpdateAction
import pipes.{QueryState, MutableMaps}
import scala.Predef.String
import org.neo4j.cypher.ParameterNotFoundException
import collection.Iterator
import collection.mutable.{Queue, Map => MutableMap}

object ExecutionContext {
def empty = new ExecutionContext()

def from(x: (String, Any)*) = new ExecutionContext().newWith(x)
}

case class ExecutionContext(m: MutableMap[String, Any] = MutableMaps.empty,
mutationCommands: Queue[UpdateAction] = Queue.empty,
state: QueryState = QueryState())
extends MutableMap[String, Any] {
def get(key: String): Option[Any] = m.get(key)

def getParam(key: String): Any =
state.params.getOrElse(key, throw new ParameterNotFoundException("Expected a parameter named " + key))

def iterator: Iterator[(String, Any)] = m.iterator

override def size = m.size

def ++(other: ExecutionContext): ExecutionContext = copy(m = m ++ other.m)

override def foreach[U](f: ((String, Any)) => U) {
m.foreach(f)
}

def +=(kv: (String, Any)) = {
m += kv
this
}

def -=(key: String) = {
m -= key
this
}

def newWith(newEntries: Seq[(String, Any)]) =
createWithNewMap(MutableMaps.create(this.m) ++= newEntries)

def newWith(newEntries: scala.collection.Map[String, Any]) =
createWithNewMap(MutableMaps.create(this.m) ++= newEntries)

def newFrom(newEntries: Seq[(String, Any)]) =
createWithNewMap(MutableMaps.create(newEntries: _*))

def newFrom(newEntries: scala.collection.Map[String, Any]) =
createWithNewMap(MutableMaps.create(newEntries))

def newWith(newEntry: (String, Any)) =
createWithNewMap(MutableMaps.create(this.m) += newEntry)

override def clone(): ExecutionContext = newFrom(m)

protected def createWithNewMap(newMap: MutableMap[String, Any]) = {
copy(m = newMap)
}
}

Expand Up @@ -19,13 +19,10 @@
*/
package org.neo4j.cypher.internal.commands

import collection.Seq
import expressions.Expression
import org.neo4j.cypher.internal.Comparer
import java.lang.String
import org.neo4j.cypher.internal.{ExecutionContext, Comparer}
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.internal.helpers.IsCollection
import org.neo4j.cypher.internal.pipes.ExecutionContext

abstract sealed class ComparablePredicate(left: Expression, right: Expression) extends Predicate with Comparer {
def compare(comparisonResult: Int): Boolean
Expand Down
Expand Up @@ -23,7 +23,7 @@ import collection.Seq
import expressions.{Closure, Expression}
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.internal.helpers.CollectionSupport
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

abstract class InCollection(collection: Expression, id: String, predicate: Predicate)
extends Predicate
Expand Down
Expand Up @@ -26,7 +26,7 @@ import org.neo4j.cypher.internal.pipes.matching.MatchingContext
import org.neo4j.helpers.ThisShouldNotHappenError
import org.neo4j.graphdb.Path
import org.neo4j.cypher.internal.executionplan.builders.PatternGraphBuilder
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class PathExpression(pathPattern: Seq[Pattern])
extends Expression
Expand Down
Expand Up @@ -25,7 +25,7 @@ import org.neo4j.graphdb._
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.CypherTypeException
import org.neo4j.cypher.internal.helpers.{IsCollection, CollectionSupport}
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

abstract class Predicate extends Expression {
def apply(ctx: ExecutionContext) = isMatch(ctx)
Expand Down
Expand Up @@ -22,7 +22,7 @@ package org.neo4j.cypher.internal.commands.expressions
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.CypherTypeException
import org.neo4j.cypher.internal.helpers.{TypeSafeMathSupport, IsCollection}
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class Add(a: Expression, b: Expression) extends Expression with TypeSafeMathSupport {
def apply(ctx: ExecutionContext) = {
Expand Down
Expand Up @@ -19,13 +19,11 @@
*/
package org.neo4j.cypher.internal.commands.expressions

import collection.Seq
import org.neo4j.cypher.internal.pipes.aggregation._
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.SyntaxException
import collection.Map
import org.neo4j.helpers.ThisShouldNotHappenError
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

abstract class AggregationExpression extends Expression {
def apply(ctx: ExecutionContext) = throw new ThisShouldNotHappenError("Andres", "Aggregations should not be used like this.")
Expand Down
Expand Up @@ -20,8 +20,7 @@
package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.cypher.internal.symbols._
import collection.Map
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class CoalesceFunction(children: Expression*) extends Expression {
def apply(ctx: ExecutionContext): Any = children.toStream.map(expression => expression(ctx)).find(value => value != null) match {
Expand Down
Expand Up @@ -20,8 +20,7 @@
package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.cypher.internal.symbols._
import collection.Map
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class Collection(children: Expression*) extends Expression {
def apply(ctx: ExecutionContext): Any = children.map(e => e(ctx))
Expand Down
Expand Up @@ -21,8 +21,8 @@ package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.cypher._
import internal.commands.AstNode
import internal.ExecutionContext
import internal.helpers.TypeSafeMathSupport
import internal.pipes.ExecutionContext
import internal.symbols._

abstract class Expression extends (ExecutionContext => Any)
Expand Down
Expand Up @@ -20,9 +20,8 @@
package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.cypher.internal.symbols._
import collection.Map
import org.neo4j.cypher.internal.helpers.CollectionSupport
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class ExtractFunction(collection: Expression, id: String, expression: Expression)
extends NullInNullOutExpression(collection)
Expand Down
Expand Up @@ -22,7 +22,7 @@ package org.neo4j.cypher.internal.commands.expressions
import org.neo4j.cypher.internal.helpers.CollectionSupport
import org.neo4j.cypher.internal.commands.Predicate
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class FilterFunction(collection: Expression, id: String, predicate: Predicate)
extends NullInNullOutExpression(collection)
Expand Down
Expand Up @@ -20,7 +20,7 @@
package org.neo4j.cypher.internal.commands.expressions
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.internal.helpers.CollectionSupport
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class HeadFunction(collection: Expression) extends NullInNullOutExpression(collection) with CollectionSupport {
def compute(value: Any, m: ExecutionContext) = {
Expand Down
Expand Up @@ -21,9 +21,8 @@ package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.graphdb.{Relationship, Node}
import org.neo4j.cypher.internal.symbols._
import collection.Map
import org.neo4j.cypher.CypherTypeException
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class IdFunction(inner: Expression) extends NullInNullOutExpression(inner) {
def compute(value: Any, m: ExecutionContext) = value match {
Expand Down
Expand Up @@ -23,7 +23,7 @@ import org.neo4j.graphdb.NotFoundException
import org.neo4j.cypher.internal.symbols._
import collection.Map
import org.neo4j.helpers.ThisShouldNotHappenError
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext


object Identifier {
Expand Down
Expand Up @@ -18,10 +18,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.commands.expressions
import collection.Map
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.internal.helpers.CollectionSupport
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class LastFunction(collection: Expression) extends NullInNullOutExpression(collection) with CollectionSupport {
def compute(value: Any, m: ExecutionContext) = makeTraversable(value).last
Expand Down
Expand Up @@ -21,9 +21,8 @@ package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.graphdb.Path
import org.neo4j.cypher.internal.symbols._
import collection.Map
import org.neo4j.cypher.internal.helpers.CollectionSupport
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class LengthFunction(inner: Expression)
extends NullInNullOutExpression(inner)
Expand Down
Expand Up @@ -20,8 +20,7 @@
package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.cypher.internal.symbols.{SymbolTable, CypherType}
import collection.Map
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class Literal(v: Any) extends Expression {
def apply(ctx: ExecutionContext): Any = v
Expand Down
Expand Up @@ -21,9 +21,8 @@ package org.neo4j.cypher.internal.commands.expressions

import java.lang.Math
import org.neo4j.cypher.CypherTypeException
import collection.Map
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

abstract class MathFunction(arg: Expression) extends Expression with NumericHelper {
def innerExpectedType = NumberType()
Expand Down
Expand Up @@ -22,9 +22,8 @@ package org.neo4j.cypher.internal.commands.expressions
import org.neo4j.graphdb.Path
import org.neo4j.cypher.SyntaxException
import org.neo4j.cypher.internal.symbols._
import collection.Map
import collection.JavaConverters._
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class NodesFunction(path: Expression) extends NullInNullOutExpression(path) {
def compute(value: Any, m: ExecutionContext) = value match {
Expand Down
Expand Up @@ -20,8 +20,7 @@
package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.cypher.internal.symbols.{SymbolTable, CypherType, ScalarType}
import collection.Map
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class Null() extends Expression {
def apply(v1: ExecutionContext) = null
Expand Down
Expand Up @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.commands.expressions
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

abstract class NullInNullOutExpression(argument: Expression) extends Expression {
def compute(value: Any, m: ExecutionContext): Any
Expand Down
Expand Up @@ -21,9 +21,8 @@ package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.cypher.internal.symbols.{SymbolTable, CypherType}
import org.neo4j.cypher.EntityNotFoundException
import collection.Map
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.graphdb.NotFoundException
import org.neo4j.cypher.internal.ExecutionContext

case class Nullable(expression: Expression) extends Expression {
def apply(ctx: ExecutionContext) = try {
Expand Down
Expand Up @@ -20,9 +20,7 @@
package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.cypher.internal.symbols.{SymbolTable, AnyType}
import org.neo4j.cypher.ParameterNotFoundException
import collection.Map
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class ParameterExpression(parameterName: String) extends Expression {
def apply(ctx: ExecutionContext) = ctx.getParam(parameterName)
Expand Down
Expand Up @@ -21,8 +21,8 @@ package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.cypher.internal.symbols._
import org.neo4j.helpers.ThisShouldNotHappenError
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.helpers.IsMap
import org.neo4j.cypher.internal.ExecutionContext

case class Property(mapExpr: Expression, property: String) extends Expression {
def apply(ctx: ExecutionContext): Any = mapExpr(ctx) match {
Expand Down
Expand Up @@ -20,7 +20,7 @@
package org.neo4j.cypher.internal.commands.expressions
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.internal.helpers.CollectionSupport
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class ReduceFunction(collection: Expression, id: String, expression: Expression, acc:String, init:Expression )
extends NullInNullOutExpression(collection) with CollectionSupport {
Expand Down
Expand Up @@ -22,7 +22,7 @@ import org.neo4j.graphdb.Path
import org.neo4j.cypher.SyntaxException
import org.neo4j.cypher.internal.symbols._
import collection.JavaConverters._
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class RelationshipFunction(path: Expression) extends NullInNullOutExpression(path) {
def compute(value: Any, m: ExecutionContext) = value match {
Expand Down
Expand Up @@ -21,8 +21,7 @@ package org.neo4j.cypher.internal.commands.expressions

import org.neo4j.graphdb.Relationship
import org.neo4j.cypher.internal.symbols._
import collection.Map
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class RelationshipTypeFunction(relationship: Expression) extends NullInNullOutExpression(relationship) {
def compute(value: Any, m: ExecutionContext) = value.asInstanceOf[Relationship].getType.name()
Expand Down
Expand Up @@ -27,9 +27,8 @@ import scala.collection.JavaConverters._
import org.neo4j.cypher.SyntaxException
import org.neo4j.kernel.Traversal
import org.neo4j.graphdb.{Path, DynamicRelationshipType, Node, Expander}
import scala.Some
import org.neo4j.cypher.internal.commands.{Pattern, PathExtractor, ShortestPath}
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.ExecutionContext

case class ShortestPathExpression(ast: ShortestPath) extends Expression with PathExtractor {
val pathPattern:Seq[Pattern] = Seq(ast)
Expand Down
Expand Up @@ -24,8 +24,7 @@ import scala.collection.JavaConverters._
import org.neo4j.cypher.internal.helpers.{IsCollection, CollectionSupport}
import org.neo4j.graphdb.{PropertyContainer, Relationship, Node}
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.internal.StringExtras
import org.neo4j.cypher.internal.pipes.ExecutionContext
import org.neo4j.cypher.internal.{ExecutionContext, StringExtras}
import org.neo4j.cypher.internal.spi.QueryContext

abstract class StringFunction(arg: Expression) extends NullInNullOutExpression(arg) with StringHelper with CollectionSupport {
Expand Down

0 comments on commit 183ba17

Please sign in to comment.