Skip to content

Commit

Permalink
Rename more classes to use List instead of Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
boggle committed Sep 21, 2016
1 parent de56d04 commit b948d7f
Show file tree
Hide file tree
Showing 60 changed files with 164 additions and 165 deletions.
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.internal.cypher.acceptance

import org.neo4j.cypher.internal.compiler.v3_0.helpers.CollectionSupport
import org.neo4j.cypher.internal.compiler.v3_0.helpers.ListSupport
import org.neo4j.cypher.{CypherException, ExecutionEngineFunSuite, QueryStatisticsTestSupport}
import org.neo4j.graphdb.Node
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine
Expand All @@ -28,7 +28,7 @@ import org.scalatest.Assertions
import org.scalautils.LegacyTripleEquals

class LabelsAcceptanceTest extends ExecutionEngineFunSuite
with QueryStatisticsTestSupport with Assertions with CollectionSupport with LegacyTripleEquals {
with QueryStatisticsTestSupport with Assertions with ListSupport with LegacyTripleEquals {

test("Adding_single_literal_label") {
assertThat("create (n {}) set n:FOO", List("FOO"))
Expand Down
Expand Up @@ -20,7 +20,7 @@
package org.neo4j.cypher.internal.compiler.v3_0

import org.neo4j.cypher.internal.compiler.v3_0.commands.values.KeyToken
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{IsCollection, IsMap}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{IsList, IsMap}
import org.neo4j.cypher.internal.compiler.v3_0.pipes.QueryState
import org.neo4j.cypher.internal.compiler.v3_0.spi.QueryContext
import org.neo4j.graphdb.{Node, PropertyContainer, Relationship}
Expand All @@ -46,7 +46,7 @@ trait CypherSerializer {
case x: Node => x.toString + serializeProperties(x, qtx)
case x: Relationship => ":" + x.getType.name() + "[" + x.getId + "]" + serializeProperties(x, qtx)
case IsMap(m) => makeString(m, qtx)
case IsCollection(coll) => coll.map(elem => serialize(elem, qtx)).mkString("[", ",", "]")
case IsList(coll) => coll.map(elem => serialize(elem, qtx)).mkString("[", ",", "]")
case x: String => "\"" + x + "\""
case v: KeyToken => v.name
case Some(x) => x.toString
Expand Down
Expand Up @@ -23,7 +23,7 @@ import java.io.PrintWriter
import java.util

import org.neo4j.cypher.internal.compiler.v3_0.executionplan.{InternalExecutionResult, InternalQueryType}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{CollectionSupport, RuntimeJavaValueConverter}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{ListSupport, RuntimeJavaValueConverter}
import org.neo4j.cypher.internal.compiler.v3_0.pipes.QueryState
import org.neo4j.cypher.internal.compiler.v3_0.planDescription.InternalPlanDescription
import org.neo4j.cypher.internal.compiler.v3_0.spi.{InternalResultVisitor, QueryContext}
Expand All @@ -41,7 +41,7 @@ class PipeExecutionResult(val result: ResultIterator,
val executionMode: ExecutionMode,
val executionType: InternalQueryType)
extends InternalExecutionResult
with CollectionSupport {
with ListSupport {

self =>

Expand Down
Expand Up @@ -274,10 +274,10 @@ object ExpressionConverters {
case e: ast.FilterExpression => commandexpressions.FilterFunction(toCommandExpression(e.expression), e.variable.name, e.innerPredicate.map(toCommandPredicate).getOrElse(predicates.True()))
case e: ast.ExtractExpression => commandexpressions.ExtractFunction(toCommandExpression(e.expression), e.variable.name, toCommandExpression(e.scope.extractExpression.get))
case e: ast.ListComprehension => listComprehension(e)
case e: ast.AllIterablePredicate => commands.AllInCollection(toCommandExpression(e.expression), e.variable.name, e.innerPredicate.map(toCommandPredicate).getOrElse(predicates.True()))
case e: ast.AnyIterablePredicate => commands.AnyInCollection(toCommandExpression(e.expression), e.variable.name, e.innerPredicate.map(toCommandPredicate).getOrElse(predicates.True()))
case e: ast.NoneIterablePredicate => commands.NoneInCollection(toCommandExpression(e.expression), e.variable.name, e.innerPredicate.map(toCommandPredicate).getOrElse(predicates.True()))
case e: ast.SingleIterablePredicate => commands.SingleInCollection(toCommandExpression(e.expression), e.variable.name, e.innerPredicate.map(toCommandPredicate).getOrElse(predicates.True()))
case e: ast.AllIterablePredicate => commands.AllInList(toCommandExpression(e.expression), e.variable.name, e.innerPredicate.map(toCommandPredicate).getOrElse(predicates.True()))
case e: ast.AnyIterablePredicate => commands.AnyInList(toCommandExpression(e.expression), e.variable.name, e.innerPredicate.map(toCommandPredicate).getOrElse(predicates.True()))
case e: ast.NoneIterablePredicate => commands.NoneInList(toCommandExpression(e.expression), e.variable.name, e.innerPredicate.map(toCommandPredicate).getOrElse(predicates.True()))
case e: ast.SingleIterablePredicate => commands.SingleInList(toCommandExpression(e.expression), e.variable.name, e.innerPredicate.map(toCommandPredicate).getOrElse(predicates.True()))
case e: ast.ReduceExpression => commandexpressions.ReduceFunction(toCommandExpression(e.list), e.variable.name, toCommandExpression(e.expression), e.accumulator.name, toCommandExpression(e.init))
case e: ast.PathExpression => toCommandProjectedPath(e)
case e: NestedPipeExpression => commandexpressions.NestedPipeExpression(e.pipe, toCommandProjectedPath(e.path))
Expand Down
Expand Up @@ -19,13 +19,13 @@
*/
package org.neo4j.cypher.internal.compiler.v3_0.ast.convert.plannerQuery

import org.neo4j.cypher.internal.compiler.v3_0.helpers.CollectionSupport
import org.neo4j.cypher.internal.compiler.v3_0.helpers.ListSupport
import org.neo4j.cypher.internal.compiler.v3_0.planner._
import org.neo4j.cypher.internal.compiler.v3_0.planner.logical.plans.IdName
import org.neo4j.cypher.internal.frontend.v3_0.SemanticTable

case class PlannerQueryBuilder(private val q: PlannerQuery, semanticTable: SemanticTable, returns: Seq[IdName] = Seq.empty)
extends CollectionSupport {
extends ListSupport {

def withReturns(returns: Seq[IdName]): PlannerQueryBuilder = copy(returns = returns)

Expand Down
Expand Up @@ -22,13 +22,13 @@ package org.neo4j.cypher.internal.compiler.v3_0.commands
import org.neo4j.cypher.internal.compiler.v3_0._
import expressions.{Closure, Expression}
import org.neo4j.cypher.internal.compiler.v3_0.commands.predicates.Predicate
import org.neo4j.cypher.internal.compiler.v3_0.helpers.CollectionSupport
import org.neo4j.cypher.internal.compiler.v3_0.helpers.ListSupport
import pipes.QueryState
import collection.Seq

abstract class InCollection(collectionExpression: Expression, id: String, predicate: Predicate)
abstract class InList(collectionExpression: Expression, id: String, predicate: Predicate)
extends Predicate
with CollectionSupport
with ListSupport
with Closure {

type CollectionPredicate[U] = ((U) => Option[Boolean]) => Option[Boolean]
Expand Down Expand Up @@ -59,8 +59,8 @@ abstract class InCollection(collectionExpression: Expression, id: String, predic
def symbolTableDependencies = symbolTableDependencies(collectionExpression, predicate, id)
}

case class AllInCollection(collection: Expression, symbolName: String, inner: Predicate)
extends InCollection(collection, symbolName, inner) {
case class AllInList(collection: Expression, symbolName: String, inner: Predicate)
extends InList(collection, symbolName, inner) {

private def forAll[U](collectionValue: Seq[U])(predicate: (U => Option[Boolean])): Option[Boolean] = {
var result: Option[Boolean] = Some(true)
Expand All @@ -80,14 +80,14 @@ case class AllInCollection(collection: Expression, symbolName: String, inner: Pr
def name = "all"

def rewrite(f: (Expression) => Expression) =
f(AllInCollection(
f(AllInList(
collection = collection.rewrite(f),
symbolName = symbolName,
inner = inner.rewriteAsPredicate(f)))
}

case class AnyInCollection(collection: Expression, symbolName: String, inner: Predicate)
extends InCollection(collection, symbolName, inner) {
case class AnyInList(collection: Expression, symbolName: String, inner: Predicate)
extends InList(collection, symbolName, inner) {

private def exists[U](collectionValue: Seq[U])(predicate: (U => Option[Boolean])): Option[Boolean] = {
var result: Option[Boolean] = Some(false)
Expand All @@ -108,14 +108,14 @@ case class AnyInCollection(collection: Expression, symbolName: String, inner: Pr
def name = "any"

def rewrite(f: (Expression) => Expression) =
f(AnyInCollection(
f(AnyInList(
collection = collection.rewrite(f),
symbolName = symbolName,
inner = inner.rewriteAsPredicate(f)))
}

case class NoneInCollection(collection: Expression, symbolName: String, inner: Predicate)
extends InCollection(collection, symbolName, inner) {
case class NoneInList(collection: Expression, symbolName: String, inner: Predicate)
extends InList(collection, symbolName, inner) {

private def none[U](collectionValue: Seq[U])(predicate: (U => Option[Boolean])): Option[Boolean] = {
var result: Option[Boolean] = Some(true)
Expand All @@ -136,14 +136,14 @@ case class NoneInCollection(collection: Expression, symbolName: String, inner: P
def name = "none"

def rewrite(f: (Expression) => Expression) =
f(NoneInCollection(
f(NoneInList(
collection = collection.rewrite(f),
symbolName = symbolName,
inner = inner.rewriteAsPredicate(f)))
}

case class SingleInCollection(collection: Expression, symbolName: String, inner: Predicate)
extends InCollection(collection, symbolName, inner) {
case class SingleInList(collection: Expression, symbolName: String, inner: Predicate)
extends InList(collection, symbolName, inner) {

private def single[U](collectionValue: Seq[U])(predicate: (U => Option[Boolean])): Option[Boolean] = {
var matched = false
Expand All @@ -165,7 +165,7 @@ case class SingleInCollection(collection: Expression, symbolName: String, inner:
def name = "single"

def rewrite(f: (Expression) => Expression) =
f(SingleInCollection(
f(SingleInList(
collection = collection.rewrite(f),
symbolName = symbolName,
inner = inner.rewriteAsPredicate(f)))
Expand Down
Expand Up @@ -23,7 +23,7 @@ import org.neo4j.cypher.internal.compiler.v3_0._
import org.neo4j.cypher.internal.compiler.v3_0.commands.expressions.Expression
import org.neo4j.cypher.internal.compiler.v3_0.commands.values.KeyToken
import org.neo4j.cypher.internal.compiler.v3_0.executionplan.{SetLabel, Effect, Effects}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{CastSupport, CollectionSupport}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{CastSupport, ListSupport}
import org.neo4j.cypher.internal.compiler.v3_0.mutation.SetAction
import org.neo4j.cypher.internal.compiler.v3_0.pipes.QueryState
import org.neo4j.cypher.internal.compiler.v3_0.symbols.SymbolTable
Expand All @@ -36,7 +36,7 @@ case object LabelRemoveOp extends LabelOp

//TODO: Should take single label
case class LabelAction(entity: Expression, labelOp: LabelOp, labels: Seq[KeyToken])
extends SetAction with CollectionSupport {
extends SetAction with ListSupport {

def localEffects(ignored: SymbolTable) = Effects(labels.map(l => SetLabel(l.name)).toSet[Effect])

Expand Down
Expand Up @@ -20,7 +20,7 @@
package org.neo4j.cypher.internal.compiler.v3_0.commands

import org.neo4j.cypher.internal.compiler.v3_0.{Geometry, Point}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{IsCollection, IsMap}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{IsList, IsMap}
import org.neo4j.cypher.internal.compiler.v3_0.spi.QueryContext
import org.neo4j.cypher.internal.frontend.v3_0.CypherTypeException
import org.neo4j.cypher.internal.frontend.v3_0.symbols._
Expand All @@ -45,8 +45,8 @@ object coerce {
case t: ListType => value match {
case p: Path if t.innerType == CTNode => throw cantCoerce(value, typ)
case p: Path if t.innerType == CTRelationship => throw cantCoerce(value, typ)
case IsCollection(coll) if t.innerType == CTAny => coll
case IsCollection(coll) => coll.map(coerce(_, t.innerType))
case IsList(coll) if t.innerType == CTAny => coll
case IsList(coll) => coll.map(coerce(_, t.innerType))
case _ => throw cantCoerce(value, typ)
}
case CTBoolean => value.asInstanceOf[Boolean]
Expand Down
Expand Up @@ -20,7 +20,7 @@
package org.neo4j.cypher.internal.compiler.v3_0.commands.expressions

import org.neo4j.cypher.internal.compiler.v3_0._
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{IsCollection, TypeSafeMathSupport}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{IsList, TypeSafeMathSupport}
import org.neo4j.cypher.internal.compiler.v3_0.pipes.QueryState
import org.neo4j.cypher.internal.compiler.v3_0.symbols.SymbolTable
import org.neo4j.cypher.internal.frontend.v3_0.CypherTypeException
Expand All @@ -36,9 +36,9 @@ case class Add(a: Expression, b: Expression) extends Expression with TypeSafeMat
case (_, null) => null
case (x: Number, y: Number) => plus(x,y)
case (x: String, y: String) => x + y
case (IsCollection(x), IsCollection(y)) => x ++ y
case (IsCollection(x), y) => x ++ Seq(y)
case (x, IsCollection(y)) => Seq(x) ++ y
case (IsList(x), IsList(y)) => x ++ y
case (IsList(x), y) => x ++ Seq(y)
case (x, IsList(y)) => Seq(x) ++ y
case (x: String, y: Number) => x + y.toString
case (x: Number, y: String) => x.toString + y
case _ => throw new CypherTypeException("Don't know how to add `" + aVal.toString + "` and `" + bVal.toString + "`")
Expand Down
Expand Up @@ -20,14 +20,14 @@
package org.neo4j.cypher.internal.compiler.v3_0.commands.expressions

import org.neo4j.cypher.internal.compiler.v3_0._
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{CastSupport, CollectionSupport, IsCollection, IsMap}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{CastSupport, ListSupport, IsList, IsMap}
import org.neo4j.cypher.internal.compiler.v3_0.pipes.QueryState
import org.neo4j.cypher.internal.compiler.v3_0.symbols.SymbolTable
import org.neo4j.cypher.internal.frontend.v3_0.{CypherTypeException, InvalidArgumentException}
import org.neo4j.cypher.internal.frontend.v3_0.symbols._

case class ContainerIndex(expression: Expression, index: Expression) extends NullInNullOutExpression(expression)
with CollectionSupport {
with ListSupport {
def arguments = Seq(expression, index)

def compute(value: Any, ctx: ExecutionContext)(implicit state: QueryState): Any = {
Expand All @@ -36,7 +36,7 @@ with CollectionSupport {
val idx = CastSupport.castOrFail[String](index(ctx))
m(state.query).getOrElse(idx, null)

case IsCollection(collection) =>
case IsList(collection) =>
val number = CastSupport.castOrFail[Number](index(ctx))

val longValue = number match {
Expand Down
Expand Up @@ -20,14 +20,14 @@
package org.neo4j.cypher.internal.compiler.v3_0.commands.expressions

import org.neo4j.cypher.internal.compiler.v3_0._
import org.neo4j.cypher.internal.compiler.v3_0.helpers.CollectionSupport
import org.neo4j.cypher.internal.compiler.v3_0.helpers.ListSupport
import org.neo4j.cypher.internal.compiler.v3_0.pipes.QueryState
import org.neo4j.cypher.internal.compiler.v3_0.symbols.SymbolTable
import org.neo4j.cypher.internal.frontend.v3_0.symbols._

case class ExtractFunction(collection: Expression, id: String, expression: Expression)
extends NullInNullOutExpression(collection)
with CollectionSupport
with ListSupport
with Closure {

def compute(value: Any, m: ExecutionContext)(implicit state: QueryState) = makeTraversable(value).map {
Expand Down
Expand Up @@ -21,14 +21,14 @@ package org.neo4j.cypher.internal.compiler.v3_0.commands.expressions

import org.neo4j.cypher.internal.compiler.v3_0._
import org.neo4j.cypher.internal.compiler.v3_0.commands.predicates.Predicate
import org.neo4j.cypher.internal.compiler.v3_0.helpers.CollectionSupport
import org.neo4j.cypher.internal.compiler.v3_0.helpers.ListSupport
import org.neo4j.cypher.internal.compiler.v3_0.pipes.QueryState
import org.neo4j.cypher.internal.compiler.v3_0.symbols.SymbolTable
import org.neo4j.cypher.internal.frontend.v3_0.symbols._

case class FilterFunction(collection: Expression, id: String, predicate: Predicate)
extends NullInNullOutExpression(collection)
with CollectionSupport
with ListSupport
with Closure {
def compute(value: Any, m: ExecutionContext)(implicit state: QueryState) =
makeTraversable(value).filter(element => predicate.isTrue(m.newWith(id -> element) ))
Expand Down
Expand Up @@ -20,15 +20,15 @@
package org.neo4j.cypher.internal.compiler.v3_0.commands.expressions

import org.neo4j.cypher.internal.compiler.v3_0._
import org.neo4j.cypher.internal.compiler.v3_0.helpers.CollectionSupport
import org.neo4j.cypher.internal.compiler.v3_0.helpers.ListSupport
import org.neo4j.cypher.internal.compiler.v3_0.symbols.SymbolTable
import pipes.QueryState
import org.neo4j.cypher.internal.frontend.v3_0.symbols._
import org.neo4j.graphdb.Path

case class LengthFunction(inner: Expression)
extends NullInNullOutExpression(inner)
with CollectionSupport {
with ListSupport {
//NOTE all usage except for paths is deprecated
def compute(value: Any, m: ExecutionContext)(implicit state: QueryState): Long = value match {
case path: Path => path.length()
Expand Down
Expand Up @@ -20,13 +20,13 @@
package org.neo4j.cypher.internal.compiler.v3_0.commands.expressions

import org.neo4j.cypher.internal.compiler.v3_0._
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{CastSupport, CollectionSupport}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{CastSupport, ListSupport}
import org.neo4j.cypher.internal.compiler.v3_0.symbols.SymbolTable
import pipes.QueryState
import org.neo4j.cypher.internal.frontend.v3_0.symbols._

case class ListSlice(list: Expression, from: Option[Expression], to: Option[Expression])
extends NullInNullOutExpression(list) with CollectionSupport {
extends NullInNullOutExpression(list) with ListSupport {
def arguments: Seq[Expression] = from.toSeq ++ to.toSeq :+ list

private val function: (Iterable[Any], ExecutionContext, QueryState) => Any =
Expand Down
Expand Up @@ -23,7 +23,7 @@ import org.neo4j.cypher.internal.compiler.v3_0._
import org.neo4j.cypher.internal.compiler.v3_0.symbols.SymbolTable
import pipes.QueryState
import org.neo4j.cypher.internal.frontend.v3_0.symbols._
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{LiteralTypeSupport, IsCollection, IsMap}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{LiteralTypeSupport, IsList, IsMap}

case class Literal(v: Any) extends Expression {
def apply(ctx: ExecutionContext)(implicit state: QueryState): Any = v
Expand Down
Expand Up @@ -20,13 +20,13 @@
package org.neo4j.cypher.internal.compiler.v3_0.commands.expressions

import org.neo4j.cypher.internal.compiler.v3_0._
import org.neo4j.cypher.internal.compiler.v3_0.helpers.CollectionSupport
import org.neo4j.cypher.internal.compiler.v3_0.helpers.ListSupport
import org.neo4j.cypher.internal.compiler.v3_0.symbols.SymbolTable
import pipes.QueryState
import org.neo4j.cypher.internal.frontend.v3_0.symbols._

case class ReduceFunction(collection: Expression, id: String, expression: Expression, acc:String, init:Expression )
extends NullInNullOutExpression(collection) with CollectionSupport {
extends NullInNullOutExpression(collection) with ListSupport {
def compute(value: Any, m: ExecutionContext)(implicit state: QueryState) = {
val initMap = m.newWith(acc -> init(m))
val computedMap = makeTraversable(value).foldLeft(initMap) { (accMap, k) => {
Expand Down

0 comments on commit b948d7f

Please sign in to comment.