To import CSV files to AGE, these files must initially be formatted in the following way depending on what they will store in the graph:
# Nodes
id,property1,property2,...,propertyN
123,content1,content2,...,contentN
124,content1,content2,...,contentN
# Edges
start_id,start_vertex_type,end_id,end_vertex_type, (properties goes here, just like above)
123,LabelStart,124,LabelEnd
There is also three CSV files located at regress/age_load/data
that shows how to store the data for cities, countries, and their relationships with one another. These files are named cities.csv
, countries.csv
, and edges.csv
.
Now, with a postgres instance running, create the graph and the labels for the nodes and edges stored in the CSV files.
LOAD 'age';
SET search_path TO ag_catalog;
SELECT create_graph('agload_test_graph');
SELECT create_vlabel('agload_test_graph','Country');
SELECT create_vlabel('agload_test_graph','City');
SELECT create_elabel('agload_test_graph','has_city');
After these labels have been created, load the CSV files to AGE.
-- The arguments for the functions are: <graph_name>, <label>, <file_path>
SELECT load_labels_from_file('agload_test_graph','Country','age_load/data/countries.csv');
SELECT load_labels_from_file('agload_test_graph','City', 'age_load/data/cities.csv');
SELECT load_edges_from_file('agload_test_graph','has_city','age_load/data/edges.csv');
Then you can check if everything was created correctly.
SELECT COUNT(*) FROM agload_test_graph."Country";
SELECT COUNT(*) FROM agload_test_graph."City";
SELECT COUNT(*) FROM agload_test_graph."has_city";
SELECT COUNT(*) FROM cypher('agload_test_graph', $$MATCH(n) RETURN n$$) as (n agtype);
SELECT COUNT(*) FROM cypher('agload_test_graph', $$MATCH (a)-[e]->(b) RETURN e$$) as (n agtype);