Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-14-2021 11:12 AM
I am researching but haven't found a solution so far, so appreciate any suggestions.
I noticed when exporting columns into a CSV file using APOC, the file has a blank row after the header row followed by the actual data, not sure what adds the extra row.
I followed example as below:
WITH "MATCH path = (person:Person)-[:DIRECTED]->(movie)
RETURN person.name AS name, person.born AS born,
movie.title AS title, movie.tagline AS tagline, movie.released AS released" AS query
CALL apoc.export.csv.query(query, "movies-directed.csv", {})
YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data
RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data;
My resulting CSV file shows format as:
"name", "born", "tagline", "released"
"","","",""
"data", "data", "data", "data"
"data", "data", "data", "data"
However, I need the file to look this way:
name, born, tagline, released
data, data, data, data
data, data, data, data
I think my apoc is 4.1.
Thanks.
Solved! Go to Solution.
05-21-2021 10:23 AM
The following seems to work but not if I try with person.ID <> 1.
CALL apoc.export.csv.query("Match (person:Person) where person.name <> "Parent" return fields ......", "movies-directed.csv", {})
05-15-2021 01:13 PM
Hello @newkid
Can you execute the query but without exporting to CSV, just let the RETURN
and check if you have an empty row?
MATCH path = (person:Person)-[:DIRECTED]->(movie)
RETURN person.name AS name, person.born AS born,
movie.title AS title, movie.tagline AS tagline, movie.released AS released" AS query
Regards,
Cobra
05-17-2021 08:51 AM
Thanks for the response and helping me narrow it down. I do see a null row as the first row for each field. Not sure how but when I ingested the node csv data files, the counts matched to the # of rows in the csv file following the header row. To test, I ingested a couple of data files in a new database and they seemed correct. However, in the next step, when I ingested a csv file with relationships to the ingested nodes (using merge/apoc.create.relationship), one of the resulting node counts had a null row. The ingested csv data files are comma separated with "" around each field. I wonder if there are extra commas in the files adding a row or this is other data problem in the relationship files. I may have to re-do my data ingest and analyze at each step what added the rows.
Appreciate your suggestions.
I may have to re-do all my data and test again.
05-20-2021 11:02 AM
I wanted to provide an update as I may have found the cause of the null row. Initially, I had also created a parent for the person. So, Parent:Person was the parent node with ID of 1 and name of "Parent". There are many person(s) for a Parent.
In reference to this statement, MATCH path = (person:Person)-[:DIRECTED]->(movie)
If my data file had 100 records+header, and I exported only the properties of Person, I wanted to see 100 records+header. However, I also had a null row of the Parent which also is a Person. So, this row was the null row after the header in my exported csv.
Now I am trying to exclude the null Parent row out:
CALL apoc.export.csv.query(query, "movies-directed.csv", {})
This query exports null row also: CALL apoc.export.csv.query("Match (person:Person) return fields ...", "movies-directed.csv", {})
But, changing the query as below is not working, possibly due to syntax
CALL apoc.export.csv.query("Match (person:Person) match (Parent:Person) where Parent.ID <> 1 return fields ......", "movies-directed.csv", {})
This query exports just the header, 0 rows
I tried changing to Parent.ID <> toInteger(1) and using Parent.name <> "Parent" instead.
Am I missing something?
05-21-2021 10:23 AM
The following seems to work but not if I try with person.ID <> 1.
CALL apoc.export.csv.query("Match (person:Person) where person.name <> "Parent" return fields ......", "movies-directed.csv", {})
All the sessions of the conference are now available online