Skip to content
Browse files

fixes #573: Arithmetics operations have wrong type

  • Loading branch information...
1 parent a7a65ef commit b2ed05469466b530e430291fbc7a462b2717d90f @systay committed May 30, 2012
View
2 cypher/src/main/scala/org/neo4j/cypher/internal/commands/Expression.scala
@@ -129,7 +129,7 @@ case class Divide(a: Expression, b: Expression) extends Arithmetics(a, b) {
}
abstract class Arithmetics(left: Expression, right: Expression) extends Expression {
- val identifier = Identifier("%s %s %s".format(left.identifier.name, operand, right.identifier.name), ScalarType())
+ val identifier = Identifier("%s %s %s".format(left.identifier.name, operand, right.identifier.name), NumberType())
def operand: String
def throwTypeError(bVal: Any, aVal: Any): Nothing = {
throw new CypherTypeException("Don't know how to " + verb + " `" + name(bVal) + "` with `" + name(aVal) + "`")
View
32 cypher/src/test/scala/org/neo4j/cypher/ExecutionEngineTest.scala
@@ -1960,4 +1960,36 @@ RETURN x0.name?
assert(result === List(Map("sqrt(12.96)"->3.6)))
}
+
+ @Test def maths_inside_aggregation() {
+ val andres = createNode("name"->"Andres")
+ val michael = createNode("name"->"Michael")
+ val peter = createNode("name"->"Peter")
+ val bread = createNode("type"->"Bread")
+ val veg = createNode("type"->"Veggies")
+ val meat = createNode("type"->"Meat")
+
+ relate(andres, bread, "ATE", Map("times"->10))
+ relate(andres, veg, "ATE", Map("times"->8))
+
+ relate(michael, veg, "ATE", Map("times"->4))
+ relate(michael, bread, "ATE", Map("times"->6))
+ relate(michael, meat, "ATE", Map("times"->9))
+
+ relate(peter, veg, "ATE", Map("times"->7))
+ relate(peter, bread, "ATE", Map("times"->7))
+ relate(peter, meat, "ATE", Map("times"->4))
+
+ val result = parseAndExecute(
+ """ start me=node(1)
+ match me-[r1:ATE]->food<-[r2:ATE]-you
+
+ with me,count(distinct r1) as H1,count(distinct r2) as H2,you
+ match me-[r1:ATE]->food<-[r2:ATE]-you
+
+ return me,you,sum((1-ABS(r1.times/H1-r2.times/H2))*(r1.times+r2.times)/(H1+H2))""").dumpToString()
+
+ println(result)
+ }
+
}

0 comments on commit b2ed054

Please sign in to comment.
Something went wrong with that request. Please try again.