Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-27-2021 08:27 AM
I have a CSV source and I want to build 2 things:
Here is what I have already done for (1):
WITH "https://drive.google.com/u/0/uc?id=1FRi5YmWNQJZ2xeTKNO4b12xYGOTWk1jL&export=download" AS data_url
LOAD CSV WITH HEADERS FROM data_url AS requests
But it returns me an error "Query cannot conclude with LOAD CSV (must be RETURN or an update clause)"
Should I transform the data to be in a long format (with data_key and data_value columns) and use the following:
// For each request (request_id), collect it's attributes into key-value pairs
WITH requests.request_id AS request_id,
COLLECT([requests.data_key, requests.data_value]) AS keyValuePairs
WITH request_id,
apoc.map.fromPairs(keyValuePairs) AS map
// Each request converts to a node with it's attributes:
MERGE (r:Requests {request_id:request_id})
SET r += map
// Show all nodes:
MATCH (n) RETURN n
Please advise.
12-27-2021 09:28 PM
I do not see any column names with .data_key and .data_value in the .csv file you referenced. The file has very long column names.
01-01-2022 08:05 AM
LOAD CSV returns only the imported data in the output variable.
You need at least a MERGE or CREATE to create nodes. But your suggestion seems a bit too complicated.
The following example shows the minimum needed to merge nodes. But as @ameyasoft mentioned, your column names are very long and since they contain periods and minus signs, they cannot be used directly as property names in your node. It is better to shorten them beforehand and remove the characters that are not allowed. Moreover, the first column should also be given a title or removed if it is not needed.
(You can use these special characters in property names if you encapsulate them with `, but this must then also be used in this way in all subsequent queries and would be too laborious for me).
LOAD CSV WITH HEADERS FROM data_url AS line
MERGE (r:Request { request_id:line.request_id })
SET r = line
All the sessions of the conference are now available online