I am using apache age and I have a CSV file with a bunch of data in it. I want to populate my graph using the information in the csv file, so can anyone help me with this, and also tell me if I have to preprocess my CSV file so that it is readable by the function which is going to be called by apache age.
Question posted in PostgreSQL
The official documentation can be found here.
The official documentation can be found here.
4
Answers
Yes, you can load data from CSV files into Postrgres using Apache AGE. The docs detail the steps necessary here: https://age.apache.org/age-manual/master/intro/agload.html
It is likely that you will need to preprocess your files so that the columns and headings are in the correct format.
Function load_labels_from_file is used to load vertices from the CSV files. Sample format is showing below:
As well as if we want to exclude the id field, then we need to add fourth parameter as false which such as:
*** Use this when there is no id field in the file***
Again, Function load_edges_from_file can be used to load properties from the CSV file. Please see the file structure in the following.
Note: make sure that ids in the edge file are identical to ones that are in vertices files.
You can check this tutorial from official page(age).
You can populate a graph using the information in the CSV file. According to the documentation, there are two steps for the loading of graph:
‘load_labels_from_file’ is used to load vertices from the CSV files and ‘load_edges_from_file’ can be used to load properties from the CSV files.
You can find detailed information about it in this documentation: https://age.apache.org/age-manual/master/intro/agload.html
In Apache AGE,
A CSV file containing nodes’ data should be formatted as following:
id:
It should be the first column of the file and all values should be a positive integer. This is an optional field when id_field_exists is false. However, it should be present when id_field_exists is not set to false.
Properties:
All other columns contains the properties for the nodes. Header row shall contain the name of property
Create Vertex Lable:
Load Data from CSV:
Similarly, In Apache AGE a CSV file for edges should be formatted as follows:
start_id
node id of the node from where the edge is stated. This id shall be present in nodes.csv file.
start_vertex_type
It should contain class/ label of the node.
end_id
The end id of the node at which the edge shall be terminated. This id should also be present in nodes.csv file.
end_vertex_type
It should contain class/ label of the node.
properties
The properties of the edge. The header (1st Row ) shall contain the property name. 2nd Row and onward rows contains data (values).
Create Edge Label:
Load Edge Data from csv File:
For more details you can also study this Answer: https://stackoverflow.com/a/76022161/20972645