|You can also read an interactive and live version of this blog post as a Neo4j GraphGist.|
Since version 2.1 Neo4j provides out-of-the box support for CSV ingestion. The
LOAD CSV command that was added to the Cypher Query language is a versatile and powerful ETL tool.
It allows you to ingest CSV data from any URL into a friendly parameter stream for your simple or complex graph update operation, that … conversion.
But hear my words of advice before you jump directly into using it. There are some tweaks and configuration aspects that you should know to be successful on the first run.
Data volume: LOAD CSV was built to support around 1M rows per import, it still works with 10M rows but you have to wait a bit, at 100M it’ll try your patience.
Except for tiny datasets never run it without the saveguard of periodic commits, which prevent you from large transactions overflowing your available database memory (JVM Heap).
The CSV used in this example is pretty basic, but enough to show some issues and make a point, it’s people and companies they work(ed) for.
PersonName,"Company Name",year "Kenny Bastani","Neo Technology",2013 "Michael Hunger","Neo Technology",2010 "James Ward","Heroku",2011 "Someone",, "John","Doe.com","ninetynine"
I never heard of UbiGraph before, but this tweet by @a61dr41n made me curious.
— a61dr41n (@a61dr41n) June 20, 2014
So I checked it out. UbiGraph is a graph rendering server that is controlled remotely and also interactively with a XML-RPC API (which is a weird choice).
It comes with example clients in Java, Python, Ruby and C.
You can download it from here. After unzipping the file and starting
bin/ubigraph_server &, you should see a black window rendering the void, waiting for your commands.
Presentation: “Using AsciiArt to Analyse your SourceCode with Neo4j and OSS Tools” at GeekOut.ee 2014
So instead of using a existing presentation I decided to finally write one up over night that covers one aspect of graph databases that is close to my heart:
Software Analytics with Graphs
When I first learned about Neo4j in 2008, my first project was pulling in Java class-file information into Neo4j, to find interesting tidbits about the JDK. Fast forward 4 years.
Other things kept me busy until I 2012, when I was speaking at a InnoQ tech-day and thought this would be a good topic to talk about.
I was so amazed by projects that others did in this area and published a blog post on “Graph Databases and Software Metrics to show what I’ve found. These were:
- Raoul-Gabriel Urma: Expressive and Scalable Source Code Queries with Graph Databases (Paper)
- Rickard Öberg: NeoMVN is tracing maven dependencies (GitHub)
- Pavlo Baron: Graphlr, a ANTLR storage in Neo4j (GitHub)
When having a train-ride with my friend Dirk from Buschmais for two hours, he got a full load of my excitement about this topic, and he saw a real good practical use for his daily work with large software projects. Having your projects structure in a graph allows you to:
- Query the graph structures for insights on the code level (e.g. code-smells)
- Enrich the graph structure with higher level, technical, architectural and business concepts
- Define rules and metrics based on those higher level concepts.
- Run the parsing, enrichment, metrics computation and rule checking as part of your build process, generating reports and failing it in case of violation of those rules
All those ideas resulted in an impressive open-source project called jQAssistant which does all of the above (and much more).
The session has been recorded, I’ll embed the video as soon as it is online. Then you can even listen to my hoarse voice.
Styling Neo4j Server Visualisation
To give you a head start when using Neo4j-Browser I wanted to share these quick tips for styling and querying.
In this blog post, I want to show the power of LOAD CSV, which is much more than just a simple data ingestion clause for Neo4j’s Cypher.
I want to demonstrate how easy it is to use by importing a project’s git commit history into Neo4j. For demonstration purposes, I use Neo4j’s repository on GitHub, which contains
about 27000 commits.
— Paul Horn (@knutwalker) May 24, 2014
I really liked the idea and wanted to take a look. His python script takes the following approach:
Sometimes you don’t see the forest for the trees. But if you do, you probably use a graph database.
Trees are one of the simple graph datastructures, directed acyclic graphs (DAGs).
For our example we use a time-tree that we want to import into the database.
1 year = 12 months = 365 days = 8.760 hours = 525.600 minutes = 31.536.000 seconds
So we have to import about 32M nodes and 32M relationships. Sounds good enough.
After reading the interesting blog post of my colleague Rik van Bruggen on “Media, Politics and Graphs” I thought it would be really cool to render it as a GrapGist. Especially, as he already shared all the queries as a GitHub Gist.
Unfortunately the dataset was a bit large for a sensible GraphGist representation, so I thought about means of extracting a smaller sample of his raw data that he made available (see his blog post for the link).
We want to run some test queries on an existing graph model but have no sample data at hand and also no input files (CSV,GraphML) that would provide it.
Why not create quickly it on our own just using cypher. First I thought about using Cypher to generate CSV files and loading them back, but it is much easier.
The domain is simple
(:User)-[:OWN]→(:Product) but good enough for collaborative filtering or demographic analysis.
With Neo4j 2.0 we got automatic schema indexes based on labels and properties for exact lookups of nodes on property values.
Fulltext and other indexes (spatial, range) are on the roadmap but not addressed yet.
For fulltext indexes you still have to use legacy indexes.
As you probably don’t want to add nodes to an index manually, the existing “auto-index” mechanism should be a good fit.