Hi dear friends,
I do have around 100queries created in SQL and have to convert them into Cypher in order to run them in Neo4J. Is there a tool that can convert the queries in order to save some time converting them manually? Thank you.
Hi dear friends,
I do have around 100queries created in SQL and have to convert them into Cypher in order to run them in Neo4J. Is there a tool that can convert the queries in order to save some time converting them manually? Thank you.
Part of the challenge is that due to the differences in the database structure there isn't a 1:1 translation. For example if you have a table that contains columns PERSON, COMPANY and you want all people that work at a company named 'Acme' in SQL it would look like this.
SELECT PERSON, COMPANY
FROM MYTABLE
WHERE COMPANY = 'Acme'
Cypher will be dependent on your data model. For instance if the Person and Company are both nodes it may look like this
MATCH (p:Person)-[r:WORKS_FOR]-(c:Company{name:'Acme'})
RETURN p, c
However if the Company is a property of the person perhaps it would be
MATCH (p:Person{Company:'Acme'})
RETURN p, p.Company
So as you can see there isn't a direct way to "Translate" because the structure of the data itself is different.
Now that said... could you drop something like?
MATCH (p:Person)-[r]-(c)
WHERE c.name = 'Acme'
RETURN p, r,c
sure...
It's a risky move in some regards, especially as the more complex your SQL queries the more this may return more than you intend. Now if you want to hack your way through and if you have repeated portions of your sql you can replace those in chunks.
If anyone else has better idea, please join the discussion.
The way I accomplished this kind of task, is by exporting the query results to csv files and imported the data with Cypher queries. Also, I rewrote SQL queries to suit my data model which helped a lot. First thing is to model your Neo4j database and accordingly export the data from SQL server. Another approach (that worked for me) is to create some stored procedures in SQL and with JDBC connection to Neo4j I executed the stored procedures and used Load Csv to import data. Anyway it's lot of work, but it's finally it works!