Hello I have a large data set . I am daily updating nodes and relationships from csv files using load csv. My relationship files have a field(property key) called Timestamp which contains dates and times in string format "2019-09-08T17:46:10Z". I need to cast it in date time object . previously I was not sure about that I need this casting . since the data sizing is getting big so it will be very tiresome for reworking from scratch.
so I am looking for a query or casting mechanism to cast this timestamp field. the data size is around 7 million +
Hi kalyan.b.aninda,
I think you can really easily cast the String. I quickly tested it creating a new node once just setting the String and once converting it into datetime.
CREATE (a:New {dateString: "2019-09-08T17:46:10Z", dateTime: datetime("2019-09-08T17:46:10Z")})
When returning the values, I obtain:
So, I guess, you will then also be able to sort by dateTime and do all the other operations, you want to do.
Converting all your nodes then should be possible by
MATCH (a) SET a.Timestamp = datetime(a.Timestamp)
You can find more information on time formats here: https://neo4j.com/docs/cypher-manual/current/syntax/temporal/
Regards,
Elean
thanks for reply, but It works for casting node attributes. But my Timestamp field is an attribute of Relationships. I am uploading nodes from separate CSV files and uploading relationships from separate csv files. The relationship file looks like this
relation id 1 id 2 Timestamp channel
wash. 01 02 2019-09-08T17:46:10Z. test
after relation completed the text look like this
[{"ID":"01"},{"CHANNEL":"test","TIMESTAMP":"2019-09│
│-08T17:46:10Z"},{"ID":"02"}]
I want to cast that relationship's time stamp attribute
There is no TIMESTAMP attribute in my nodes. Node attributes only has id and some extra information, relationship as node ids, relationship, timestamp , channel field
is there any way to create a new field in nodes like timestampval (date time type) by the reference of casting relationship's Timestamp field
Hi kalyan,
If you just want to change the timestamp of the relationship, The cypher is like this:
MATCH ()-[a]->()
SET a.Timestamp = datetime(a.Timestamp)
or
MATCH (:NodeLabel)-[a:RELATIONSHIP_LABEL]->(:NodeLabel)
SET a.Timestamp = datetime(a.Timestamp)
If you use it for LoadCSV:
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///RELATIONSHIP_DATA.csv' AS line
MATCH (id_from:NodeLabel {id:line.ID_FROM}), (id_to:NodeLabel {id:line.ID_TO})
CREATE (id_from)-[:RELATIONSHIP_LABEL {timestamp:datetime(line.TIMESTAMP)}]->(id_to);
This is my RELATIONSHIP_DATA.csv.
"ID_FROM","TIMESTAMP","ID_TO"
"01","2019-09-01T10:00:10Z","02"
"01","2019-09-02T11:00:10Z","03"
"02","2019-09-03T12:00:10Z","04"
"03","2019-09-04T13:00:10Z","05"
"04","2019-09-05T14:00:10Z","06"
Don't forget to index
CREATE CONSTRAINT ON (n:NodeLabel) ASSERT n.id IS UNIQUE;
This is the create node cypher.
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///RELATIONSHIP_DATA.csv' AS line
MERGE (:NodeLabel {id:line.ID_FROM})
MERGE (:NodeLabel {id:line.ID_TO});
THANK YOU VERY MUCH for your details samples and explaination