Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dividing in Neo4j

Everytime I try to divide something in neo4j, I keep getting zero. I am using the following query:

MATCH (m:Member)-[:ACTIVITY{issue_d:"16-Jan"}]->(l:Loan)
MATCH (m)-[:ACTIVITY]->(p:Payments)
WHERE l.installment<1000 AND p.total_pymnt>0
RETURN (l.funded_amnt-p.total_pymnt),(l.funded_amnt-p.total_pymnt)/(l.funded_amnt), l.funded_amnt, p.total_pymnt, m.member_id
LIMIT 1000;

I checked to make sure that my values for funded_amnt and total_pymnt are not messing up the operation they seem good:

screenshot - query result

Even when I just do:

500/l.funded_amnt 

I still get zero. What am I doing wrong?

like image 204
Aly Avatar asked Jun 02 '16 18:06

Aly


People also ask

What is unwind in Neo4j?

With UNWIND , you can transform any list back into individual rows. These lists can be parameters that were passed in, previously collect -ed result or other list expressions. One common usage of unwind is to create distinct lists. Another is to create data from parameter lists that are provided to the query.

How do you create a relationship between two nodes in Neo4j?

To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them. The created relationship is returned by the query.

How do you perform aggregation in Cypher?

The Cypher query offers aggregation similar to GROUP BY offered by SQL. The aggregate function can take multiple values and can calculate the aggregated values for them. In this recipe, we will learn the common aggregation techniques, with the help of examples.

What can you do to improve the performance of Neo4j?

The size of the available heap memory is an important aspect for the performance of Neo4j. Generally speaking, it is beneficial to configure a large enough heap space to sustain concurrent operations. For many setups, a heap size between 8G and 16G is large enough to run Neo4j reliably.


1 Answers

Multiply your numerator by 1.0.

MATCH (m:Member)-[:ACTIVITY {issue_d:"16-Jan"}]->(l:Loan)
MATCH (m)-[:ACTIVITY]->(p:Payments)
WHERE l.installment < 1000 AND p.total_pymnt > 0
RETURN (l.funded_amnt - p.total_pymnt), ((l.funded_amnt - p.total_pymnt) * 1.0) / l.funded_amnt, l.funded_amnt, p.total_pymnt, m.member_id
LIMIT 1000;

Integer division discards the remainder, so you need to multiply your numerator by 1.0 or wrap it in toFloat().

RETURN 5 / 12;          // 0
RETURN 5 * 1.0 / 12;    // 0.4166666666666667
RETURN toFloat(5) / 12; // 0.4166666666666667
like image 137
Nicole White Avatar answered Sep 22 '22 15:09

Nicole White