Reputation: 553
Referring to this use case, I have a set of similar data that contain people names and their ownership of companies. However, the ownership is identified by percentages and the numbers change frequently. So I cannot simply record "Tom own X company" but I need "Tom own 50% of X company from 1 Jan 2015 to 6 Jun 2015, 55% from 7 Jun 2015 to 10 Oct 2016"
What is the best way to model the data? Ultimately, is Neo4J a good tool for this type of data?
Upvotes: 0
Views: 1804
Reputation: 30407
I think you might want to consider :Ownership nodes, which represent an owner of a percentage of a company valid during a range in time. Your timestamps will likely need to be indexed.
This can let you perform queries such as:
// find the percentage of ownership in a company at a point of time
WITH {params.instant} as instant
MATCH (p:Person{name:'Bob Barker'})-[:Owns]->(o:Ownership)-[:Of]->(:Company{name:'KrispyKreme'})
WHERE o.start <= instant <= o.end
RETURN o.percentage
// find the max percentage a user has ever owned of any company
MATCH (p:Person{name:'Bob Barker'})-[:Owns]->(o:Ownership)
ORDER BY o.percentage DESC
LIMIT 1
WITH o
MATCH (o)-[:OF]->(c:Company)
RETURN c, o.percentage
// find who owned what percentages of a company at a point in time
WITH {params.instant} as instant
MATCH (o:Ownership)-[:Of]->(c:Company{name:'KripsyKreme'})
WHERE o.start <= instant <= o.end
WITH o
MATCH (p:Person)-[:Owns]->(o)
RETURN p, o.percentage
The weakness of this model is that there are bound to be a great many ownership nodes, so queries on ownership from a company or companies may slow depending on how much data you have, but queries of individuals and their ownerships should be comparatively quick.
Upvotes: 1