Skip to content

Commit

Permalink
Merge pull request #6388 from Mats-SX/3.0-list-not-collection
Browse files Browse the repository at this point in the history
Rename CTCollection to CTList
  • Loading branch information
systay committed Feb 11, 2016
2 parents 34d4273 + 70681b9 commit 59c65b3
Show file tree
Hide file tree
Showing 89 changed files with 353 additions and 359 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ case class ParsedVarLengthRelation(name: String,
copy(props = props.rewrite(f), start = start.rewrite(f), end = end.rewrite(f))

def possibleStartPoints: Seq[(String, CypherType)] =
(start.possibleStartPoints :+ name -> CTCollection(CTRelationship)) ++ end.possibleStartPoints
(start.possibleStartPoints :+ name -> CTList(CTRelationship)) ++ end.possibleStartPoints
}

case class ParsedShortestPath(name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ object ExpressionConverters {
case e: ast.HasLabels => hasLabels(e)
case e: ast.Collection => commandexpressions.Collection(toCommandExpression(e.expressions): _*)
case e: ast.MapExpression => mapExpression(e)
case e: ast.CollectionSlice => commandexpressions.CollectionSliceExpression(toCommandExpression(e.collection), toCommandExpression(e.from), toCommandExpression(e.to))
case e: ast.CollectionSlice => commandexpressions.CollectionSliceExpression(toCommandExpression(e.list), toCommandExpression(e.from), toCommandExpression(e.to))
case e: ast.ContainerIndex => commandexpressions.ContainerIndex(toCommandExpression(e.expr), toCommandExpression(e.idx))
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))
Expand All @@ -276,7 +276,7 @@ object ExpressionConverters {
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.ReduceExpression => commandexpressions.ReduceFunction(toCommandExpression(e.collection), e.variable.name, toCommandExpression(e.expression), e.accumulator.name, toCommandExpression(e.init))
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))
case e: ast.GetDegree => getDegree(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ case class Addition(lhs: CodeGenExpression, rhs: CodeGenExpression) extends Code

override def nullable(implicit context: CodeGenContext) = lhs.nullable || rhs.nullable

val validTypes = Seq(CTString, CTFloat, CTInteger, CTCollection(CTAny))
val validTypes = Seq(CTString, CTFloat, CTInteger, CTList(CTAny))

override def cypherType(implicit context: CodeGenContext) = (lhs.cypherType, rhs.cypherType) match {
// Strings
case (CTString, CTString) => CTString

// Collections
case (CollectionType(left), CollectionType(right)) => CollectionType(left leastUpperBound right)
case (CollectionType(innerType), singleElement) => CollectionType(innerType leastUpperBound singleElement)
case (singleElement, CollectionType(innerType)) => CollectionType(innerType leastUpperBound singleElement)
case (ListType(left), ListType(right)) => ListType(left leastUpperBound right)
case (ListType(innerType), singleElement) => ListType(innerType leastUpperBound singleElement)
case (singleElement, ListType(innerType)) => ListType(innerType leastUpperBound singleElement)

// Numbers
case (CTInteger, CTInteger) => CTInteger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ case class CastToCollection(expression: CodeGenExpression) extends CodeGenExpres

override def nullable(implicit context: CodeGenContext) = expression.nullable

override def cypherType(implicit context: CodeGenContext) = CTCollection(CTAny)
override def cypherType(implicit context: CodeGenContext) = CTList(CTAny)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ case class Collection(expressions: Seq[CodeGenExpression]) extends CodeGenExpres
override def cypherType(implicit context: CodeGenContext) = {
val commonType = expressions.map(_.cypherType).reduce[CypherType](_ leastUpperBound _)

CTCollection(commonType)
CTList(commonType)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ case class ToSet(expression: CodeGenExpression) extends CodeGenExpression {

override def nullable(implicit context: CodeGenContext) = false

override def cypherType(implicit context: CodeGenContext) = CTCollection(CTAny)
override def cypherType(implicit context: CodeGenContext) = CTList(CTAny)
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ case class PathExpression(pathPattern: Seq[Pattern], predicate:Predicate=True())

def rewrite(f: (Expression) => Expression): Expression = f(PathExpression(pathPattern.map(_.rewrite(f)), predicate.rewriteAsPredicate(f)))

def calculateType(symbols: SymbolTable): CypherType = CTCollection(CTPath)
def calculateType(symbols: SymbolTable): CypherType = CTList(CTPath)

def symbolTableDependencies = {
val patternDependencies = pathPattern.flatMap(_.symbolTableDependencies).toSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ case class AllRelationships(columnName: String) extends StartItem(columnName, Se

case class LoadCSV(withHeaders: Boolean, url: Expression, variable: String, fieldTerminator: Option[String]) extends StartItem(variable, Seq.empty)
with ReadOnlyStartItem {
def variables: Seq[(String, CypherType)] = Seq(variableName -> (if (withHeaders) CTMap else CTCollection(CTAny)))
def variables: Seq[(String, CypherType)] = Seq(variableName -> (if (withHeaders) CTMap else CTList(CTAny)))
override def localEffects(symbols: SymbolTable) = Effects()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ case class Add(a: Expression, b: Expression) extends Expression with TypeSafeMat
val aT = a.getType(symbols)
val bT = b.getType(symbols)

(CTCollection(CTAny).isAssignableFrom(aT), CTCollection(CTAny).isAssignableFrom(bT)) match {
(CTList(CTAny).isAssignableFrom(aT), CTList(CTAny).isAssignableFrom(bT)) match {
case (true, false) => mergeWithCollection(collection = aT, singleElement = bT)
case (false, true) => mergeWithCollection(collection = bT, singleElement = aT)
case _ => (aT, bT) match {
Expand All @@ -66,9 +66,9 @@ case class Add(a: Expression, b: Expression) extends Expression with TypeSafeMat
}

private def mergeWithCollection(collection: CypherType, singleElement: CypherType):CypherType= {
val collectionType = collection.asInstanceOf[CollectionType]
val collectionType = collection.asInstanceOf[ListType]
val mergedInnerType = collectionType.innerType.leastUpperBound(singleElement)
CTCollection(mergedInnerType)
CTList(mergedInnerType)
}

def symbolTableDependencies = a.symbolTableDependencies ++ b.symbolTableDependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ case class Collect(anInner: Expression) extends AggregationWithInnerExpression(a

def rewrite(f: (Expression) => Expression) = f(Collect(anInner.rewrite(f)))

def calculateType(symbols: SymbolTable) = CTCollection(anInner.getType(symbols))
def calculateType(symbols: SymbolTable) = CTList(anInner.getType(symbols))
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ case class Collection(arguments: Expression*) extends Expression {

def calculateType(symbols: SymbolTable): CypherType =
arguments.map(_.getType(symbols)) match {
case Seq() => CTCollection(CTAny)
case types => CTCollection(types.reduce(_ leastUpperBound _))
case Seq() => CTList(CTAny)
case types => CTList(types.reduce(_ leastUpperBound _))
}

def symbolTableDependencies = arguments.flatMap(_.symbolTableDependencies).toSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ case class CollectionSliceExpression(collection: Expression, from: Option[Expres
protected def calculateType(symbols: SymbolTable): CypherType = {
from.foreach(_.evaluateType(CTNumber, symbols))
to.foreach(_.evaluateType(CTNumber, symbols))
collection.evaluateType(CTCollection(CTAny), symbols)
collection.evaluateType(CTList(CTAny), symbols)
}

def rewrite(f: (Expression) => Expression): Expression =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ with CollectionSupport {
val exprT = expression.evaluateType(CTAny, symbols)
val indexT = index.evaluateType(CTAny, symbols)

val isColl = CTCollection(CTAny).isAssignableFrom(exprT)
val isColl = CTList(CTAny).isAssignableFrom(exprT)
val isMap = CTMap.isAssignableFrom(exprT)
val isInteger = CTInteger.isAssignableFrom(indexT)
val isString = CTString.isAssignableFrom(indexT)
Expand All @@ -67,8 +67,8 @@ with CollectionSupport {

if (collectionLookup && !mapLookup) {
index.evaluateType(CTInteger, symbols)
expression.evaluateType(CTCollection(CTAny), symbols) match {
case collectionType: CollectionType => collectionType.innerType
expression.evaluateType(CTList(CTAny), symbols) match {
case collectionType: ListType => collectionType.innerType
case x if x.isInstanceOf[AnyType] => CTAny
case x => throw new CypherTypeException("Expected a collection, but was " + x)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ case class ExtractFunction(collection: Expression, id: String, expression: Expre
def arguments: Seq[Expression] = Seq(collection)

def calculateType(symbols: SymbolTable): CypherType = {
val iteratorType = collection.evaluateType(CTCollection(CTAny), symbols).legacyIteratedType
val iteratorType = collection.evaluateType(CTList(CTAny), symbols).legacyIteratedType
val innerSymbols = symbols.add(id, iteratorType)
CTCollection(expression.evaluateType(CTAny, innerSymbols))
CTList(expression.evaluateType(CTAny, innerSymbols))
}

def symbolTableDependencies = symbolTableDependencies(collection, expression, id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ case class FilterFunction(collection: Expression, id: String, predicate: Predica

def arguments: Seq[Expression] = Seq(collection)

def calculateType(symbols: SymbolTable): CypherType = collection.evaluateType(CTCollection(CTAny), symbols)
def calculateType(symbols: SymbolTable): CypherType = collection.evaluateType(CTList(CTAny), symbols)

def symbolTableDependencies = symbolTableDependencies(collection, predicate, id)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ case class KeysFunction(expr: Expression) extends NullInNullOutExpression(expr)
protected def calculateType(symbols: SymbolTable) = expr match {
case node: Node => expr.evaluateType(CTNode, symbols)
case rel: Relationship => expr.evaluateType(CTRelationship, symbols)
case _ => CTCollection(CTString)
case _ => CTList(CTString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ case class LabelsFunction(nodeExpr: Expression) extends Expression {

protected def calculateType(symbols: SymbolTable) = {
nodeExpr.evaluateType(CTNode, symbols)
CTCollection(CTString)
CTList(CTString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ case class RangeFunction(start: Expression, end: Expression, step: Expression) e
start.evaluateType(CTNumber, symbols)
end.evaluateType(CTNumber, symbols)
step.evaluateType(CTNumber, symbols)
CTCollection(CTNumber)
CTList(CTNumber)
}

def symbolTableDependencies = start.symbolTableDependencies ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ case class NestedPipeExpression(pipe: Pipe, path: ProjectedPath) extends Express

def arguments = Nil

def calculateType(symbols: SymbolTable): CypherType = CTCollection(CTPath)
def calculateType(symbols: SymbolTable): CypherType = CTList(CTPath)

def symbolTableDependencies = Set()
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ case class NodesFunction(path: Expression) extends NullInNullOutExpression(path)
def calculateType(symbols: SymbolTable) = {
path.evaluateType(CTPath, symbols)

CTCollection(CTNode)
CTList(CTNode)
}

def symbolTableDependencies = path.symbolTableDependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ case class PrefixSeekRangeExpression(range: PrefixRange[Expression]) extends Exp

override def arguments: Seq[Expression] = Seq.empty

override protected def calculateType(symbols: SymbolTable): CypherType = CTCollection(CTNode)
override protected def calculateType(symbols: SymbolTable): CypherType = CTList(CTNode)

override def symbolTableDependencies: Set[String] = Set.empty
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ case class ReduceFunction(collection: Expression, id: String, expression: Expres
def variableDependencies(expectedType: CypherType) = AnyType

def calculateType(symbols: SymbolTable) = {
val iteratorType = collection.evaluateType(CTCollection(CTAny), symbols).legacyIteratedType
val iteratorType = collection.evaluateType(CTList(CTAny), symbols).legacyIteratedType
var innerSymbols = symbols.add(acc, init.evaluateType(CTAny, symbols))
innerSymbols = innerSymbols.add(id, iteratorType)
// return expressions's type as the end result for reduce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ case class RelationshipFunction(path: Expression) extends NullInNullOutExpressio

def calculateType(symbols: SymbolTable) = {
path.evaluateType(CTPath, symbols)
CTCollection(CTRelationship)
CTList(CTRelationship)
}

def symbolTableDependencies = path.symbolTableDependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ case class ShortestPathExpression(shortestPathPattern: ShortestPath, predicates:

def rewrite(f: (Expression) => Expression): Expression = f(ShortestPathExpression(shortestPathPattern.rewrite(f)))

def calculateType(symbols: SymbolTable) = if (shortestPathPattern.single) CTPath else CTCollection(CTPath)
def calculateType(symbols: SymbolTable) = if (shortestPathPattern.single) CTPath else CTList(CTPath)

def symbolTableDependencies = shortestPathPattern.symbolTableDependencies + shortestPathPattern.left.name + shortestPathPattern.right.name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ case class SplitFunction(orig: Expression, separator: Expression)

override def rewrite(f: (Expression) => Expression) = f(SplitFunction(orig.rewrite(f), separator.rewrite(f)))

override def calculateType(symbols: SymbolTable) = CTCollection(CTString)
override def calculateType(symbols: SymbolTable) = CTList(CTString)

override def symbolTableDependencies = orig.symbolTableDependencies ++ separator.symbolTableDependencies
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ object LiteralTypeSupport {
case _: Number => CTFloat
case _: Boolean => CTBoolean
case IsMap(_) => CTMap
case IsCollection(coll) if coll.isEmpty => CTCollection(CTAny)
case IsCollection(coll) => CTCollection(coll.map(deriveType).reduce(_ leastUpperBound _))
case IsCollection(coll) if coll.isEmpty => CTList(CTAny)
case IsCollection(coll) => CTList(coll.map(deriveType).reduce(_ leastUpperBound _))
case _ => CTAny
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ case class DeleteEntityAction(elementToDelete: Expression, forced: Boolean)
def localEffects(symbols: SymbolTable) = elementToDelete match {
case i: Variable => effectsFromCypherType(symbols.variables(i.entityName))
case ContainerIndex(i: Variable, _) => symbols.variables(i.entityName) match {
case CollectionType(innerType) => effectsFromCypherType(innerType)
case ListType(innerType) => effectsFromCypherType(innerType)
}
// There could be a nested map/collection expression here, so we'll
// just say that we don't know what type the entity has
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ case class ForeachAction(collection: Expression, id: String, actions: Seq[Update
def variables = Nil

def addInnerVariable(symbols: SymbolTable): SymbolTable = {
val t = collection.evaluateType(CTCollection(CTAny), symbols).legacyIteratedType
val t = collection.evaluateType(CTList(CTAny), symbols).legacyIteratedType

val innerSymbols: SymbolTable = symbols.add(id, t)
innerSymbols
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.neo4j.cypher.internal.compiler.v3_0.planDescription.InternalPlanDescr
import org.neo4j.cypher.internal.compiler.v3_0.spi.QueryContext
import org.neo4j.cypher.internal.compiler.v3_0.symbols.SymbolTable
import org.neo4j.cypher.internal.frontend.v3_0.LoadExternalResourceException
import org.neo4j.cypher.internal.frontend.v3_0.symbols.{AnyType, CollectionType, MapType}
import org.neo4j.cypher.internal.frontend.v3_0.symbols.{AnyType, ListType, MapType}

sealed trait CSVFormat
case object HasHeaders extends CSVFormat
Expand Down Expand Up @@ -118,7 +118,7 @@ case class LoadCSVPipe(source: Pipe,

override def symbols: SymbolTable = format match {
case HasHeaders => source.symbols.add(variable, MapType.instance)
case NoHeaders => source.symbols.add(variable, CollectionType(AnyType.instance))
case NoHeaders => source.symbols.add(variable, ListType(AnyType.instance))
}

override def localEffects = Effects()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ case class ShortestPathPipe(source: Pipe, shortestPathCommand: ShortestPath, pre
val withPath = source.symbols.add(pathName, CTPath)
shortestPathCommand.relIterator match {
case None => withPath
case Some(x) => withPath.add(x, CTCollection(CTRelationship))
case Some(x) => withPath.add(x, CTList(CTRelationship))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ case class VarLengthExpandPipe(source: Pipe,
def planDescriptionWithoutCardinality = source.planDescription.
andThen(this.id, s"VarLengthExpand(${if (nodeInScope) "Into" else "All"})", variables, ExpandExpression(fromName, relName, types.names, toName, projectedDir, varLength = true))

def symbols = source.symbols.add(toName, CTNode).add(relName, CTCollection(CTRelationship))
def symbols = source.symbols.add(toName, CTNode).add(relName, CTList(CTRelationship))

override def localEffects = Effects(ReadsAllNodes, ReadsAllRelationships)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class VariableLengthPatternRelationship(pathName: String,
override def variables2: Map[String, CypherType] =
Map(startNode.key -> CTNode,
endNode.key -> CTNode,
key -> CTCollection(CTRelationship)) ++ relIterable.map(_ -> CTCollection(CTRelationship)).toMap
key -> CTList(CTRelationship)) ++ relIterable.map(_ -> CTList(CTRelationship)).toMap

override def getGraphRelationships(node: PatternNode, realNode: Node, state: QueryState, f: => ExecutionContext): Seq[GraphRelationship] = {
val matchedPaths: Iterator[Path] = state.query.variableLengthPathExpand(node, realNode, minHops, maxHops, getDirection(node), relType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ final case class VariableLengthStepTrail(next: Trail,
val end = next.end

def symbols(table: SymbolTable) = {
val symbolTable = next.symbols(table).add(start, CTNode).add(path, CTCollection(CTRelationship))
val symbolTable = next.symbols(table).add(start, CTNode).add(path, CTList(CTRelationship))

//If we have a rel-iterator, let's include it
relIterator match {
case None => symbolTable
case Some(r) => symbolTable.add(r, CTCollection(CTRelationship))
case Some(r) => symbolTable.add(r, CTList(CTRelationship))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FilteringExpressionTest extends CypherFunSuite {
}

test("shouldSemanticCheckPredicateInStateContainingTypedVariable") {
val expression = DummyExpression(CTCollection(CTNode) | CTBoolean | CTCollection(CTString), DummyPosition(5))
val expression = DummyExpression(CTList(CTNode) | CTBoolean | CTList(CTString), DummyPosition(5))

val error = SemanticError("dummy error", DummyPosition(8))
val predicate = new DummyExpression(CTAny, DummyPosition(7)) {
Expand Down

0 comments on commit 59c65b3

Please sign in to comment.