skip to Main Content

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.

4

Answers


  1. 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.

    Login or Signup to reply.
  2. Function load_labels_from_file is used to load vertices from the CSV files. Sample format is showing below:

    load_labels_from_file('<graph name>', '<label name>','<file path>')
    

    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***

    load_labels_from_file('<graph name>', '<label name>','<file path>',false)
    

    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.

    load_edges_from_file('<graph name>','<label name>','<file path>');
    

    You can check this tutorial from official page(age).

    Login or Signup to reply.
  3. 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:

    1. loading of vertices and
    2. loading of edges

    ‘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

    Login or Signup to reply.
  4. 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:

    SELECT create_vlabel('GraphName','LabelName');
    

    Load Data from CSV:

    SELECT load_labels_from_file('GraphName',
                                 'LabelName',
                                 'Path/to/file.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:

    SELECT create_elabel('GraphName','EdgeLabelName');
    

    Load Edge Data from csv File:

    SELECT load_edges_from_file('GraphName', 'EdgeLabelName',
         'Path/to/file.csv');
    

    For more details you can also study this Answer: https://stackoverflow.com/a/76022161/20972645

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search