Permalink
Browse files

Fixes #841: Collect should ignore null values

  • Loading branch information...
1 parent f279740 commit f01240b2d112e7a0a0130bdfd69c4eafcaf760ed @systay committed Sep 6, 2012
@@ -28,7 +28,10 @@ class CollectFunction(value:Expression) extends AggregationFunction {
val collection = new ListBuffer[Any]()
def apply(data: Map[String, Any]) {
- collection += value(data)
+ val v = value(data)
+ if (v != null) {
+ collection += v
+ }
}
def result: Any = collection.toSeq
@@ -2248,4 +2248,11 @@ RETURN x0.name?
assert(result.toList === List(3,4,5))
}
+ @Test
+ def empty_collect_should_not_contain_null() {
+ val result = parseAndExecute("START n=node(0) MATCH n-[?:NOT_EXIST]->x RETURN n, collect(x)")
+
+ assert(result.toList === List(Map("n" -> refNode, "collect(x)" -> List())))
+ }
+
}
@@ -112,8 +112,8 @@ class AggregationTest extends DocumentingTestBase {
@Test def collect() {
testQuery(
title = "COLLECT",
- text = "+COLLECT+ collects all the values into a list.",
- queryText = "start n=node(%A%,%B%,%C%) return collect(n.property)",
+ text = "+COLLECT+ collects all the values into a list. It will ignore null values,",
+ queryText = "start n=node(%A%,%B%,%C%,%D%) return collect(n.property?)",
returns = "Returns a single row, with all the values collected.",
assertions = p => assertEquals(Map("collect(n.property)" -> Seq(13, 33, 44)), p.toList.head))
}
@@ -20,14 +20,22 @@
package org.neo4j.cypher.internal.pipes.aggregation
import org.junit.Test
-import org.junit.Assert._
import org.neo4j.cypher.internal.commands.Expression
+import org.scalatest.Assertions
-class CollectFunctionTest extends AggregateTest {
+class CollectFunctionTest extends AggregateTest with Assertions {
def createAggregator(inner: Expression) = new CollectFunction(inner)
@Test def singleOne() {
- assertEquals(Seq(1), aggregateOn(1))
+ assert(Seq(1) === aggregateOn(1))
+ }
+
+ @Test def empty_returns_empty_seq() {
+ assert(Seq() === aggregateOn())
+ }
+
+ @Test def doesnt_collect_null_values() {
+ assert(Seq() === aggregateOn(null))
}
}

0 comments on commit f01240b

Please sign in to comment.