YMatrix
Quick Start
Connecting
Benchmarks
Deployment
Data Usage
Manage Clusters
Upgrade
Global Maintenance
Expansion
Monitoring
Security
Best Practice
Technical Principles
Data Type
Storage Engine
Execution Engine
Streaming Engine(Domino)
MARS3 Index
Extension
Advanced Features
Advanced Query
Federal Query
Grafana
Backup and Restore
Disaster Recovery
Graph Database
Introduction
Clauses
Functions
Advanced
Guide
Performance Tuning
Troubleshooting
Tools
Configuration Parameters
SQL Reference
You can create a graph from files using the instructions below. This document covers:
Users load graphs in two steps:
You must create the graph and its labels before loading data from files.
The following functions load vertices and edges from files.
The function load_labels_from_file loads vertices from a CSV file.
load_labels_from_file('<graph name>',
'<label name>',
'<file path>')
A fourth argument lets users omit the id field. Use this option only when the input file contains no id column.
load_labels_from_file('<graph name>',
'<label name>',
'<file path>',
false)
The function load_edges_from_file loads edges from a CSV file. See the file structure specification below.
Note: Ensure that
idvalues in the edge file match existingidvalues in the vertex file.
load_edges_from_file('<graph name>',
'<label name>',
'<file path>');
The following describes the required structure for vertex and edge CSV files.
| Column Name | Description |
|---|---|
id |
Must be the first column. All values must be positive integers. Optional only when id_field_exists is set to false. Otherwise, it must be present. |
Properties |
All remaining columns define vertex properties. The header row must contain property names. |
| Column Name | Description |
|---|---|
start_id |
The id of the source vertex. Must exist in the vertex file. |
start_vertex_type |
The label of the source vertex. |
end_id |
The id of the target vertex. |
end_vertex_type |
The label of the target vertex. |
properties |
Edge properties. Header row must contain property names. |
Example files are located in regress/age_load/data.
LOAD 'age';
SET search_path TO ag_catalog;
SELECT create_graph('agload_test_graph');
Country label and load vertices from a CSV file. Note: This CSV file includes an id column.SELECT create_vlabel('agload_test_graph','Country');
SELECT load_labels_from_file('agload_test_graph',
'Country',
'age/regress/age_load/data/countries.csv');
City label and load vertices from a CSV file. Note: This CSV file includes an id column.SELECT create_vlabel('agload_test_graph','City');
SELECT load_labels_from_file('agload_test_graph',
'City',
'age/regress/age_load/data/cities.csv');
has_city edge label and load edges from a CSV file.SELECT create_elabel('agload_test_graph','has_city');
SELECT load_edges_from_file('agload_test_graph', 'has_city',
'age/regress/age_load/data/edges.csv');
SELECT table_catalog, table_schema, table_name, table_type
FROM information_schema.tables
WHERE table_schema = 'agload_test_graph';
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);
id ColumnCountry2 label and load vertices from a CSV file. Note: This CSV file has no id column.SELECT create_vlabel('agload_test_graph','Country2');
SELECT load_labels_from_file('agload_test_graph',
'Country2',
'age/regress/age_load/data/countries.csv',
false);
City2 label and load vertices from a CSV file. Note: This CSV file has no id column.SELECT create_vlabel('agload_test_graph','City2');
SELECT load_labels_from_file('agload_test_graph',
'City2',
'age/regress/age_load/data/cities.csv',
false);
Country and City use id values from the input file. Country2 and City2 were created without an id column — IDs were auto-assigned.SELECT COUNT(*) FROM agload_test_graph."Country2";
SELECT COUNT(*) FROM agload_test_graph."City2";
SELECT id FROM agload_test_graph."Country" LIMIT 10;
SELECT id FROM agload_test_graph."Country2" LIMIT 10;
SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country {iso2 : 'BE'})
RETURN id(n), n.name, n.iso2 $$) AS ("id(n)" agtype, "n.name" agtype, "n.iso2" agtype);
SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country2 {iso2 : 'BE'})
RETURN id(n), n.name, n.iso2 $$) AS ("id(n)" agtype, "n.name" agtype, "n.iso2" agtype);
SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country {iso2 : 'AT'})
RETURN id(n), n.name, n.iso2 $$) AS ("id(n)" agtype, "n.name" agtype, "n.iso2" agtype);
SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country2 {iso2 : 'AT'})
RETURN id(n), n.name, n.iso2 $$) AS ("id(n)" agtype, "n.name" agtype, "n.iso2" agtype);
SELECT drop_graph('agload_test_graph', true);