如何在Apache AGE中导出和导入图形以进行数据库迁移?

huangapple go评论112阅读模式
英文:

How to export and import a graph in Apache AGE for database migration?

问题

如何在Apache AGE中导出和导入图形?

我有一个位于一个数据库中的图形需要移动到另一个数据库中。在Apache AGE中是否有一种方法或工具可用于从源数据库导出图形,然后将其导入目标数据库?

我将非常感谢任何关于如何高效执行此数据传输的见解、指导或建议。

英文:

How can I export and import a graph in Apache AGE?

I have a graph in one database that I need to move to another. Is there a method or tool available in Apache AGE that allows for exporting the graph from the source database and importing it into the target database?

I would greatly appreciate any insights, guidance, or recommendations on how to efficiently perform this data transfer.

答案1

得分: 1

只返回翻译好的部分:

将图导出为CSV,然后将CSV图导入到另一个数据库中。

请参考Neo4j文档以了解如何导出到CSV,以及要导入到AGE中,请参考此链接

英文:

Simply export the graph to CSV and import the CSV graph into AGE in another database.

Refer to the Neo4j documentation on how to export to CSV and to import into AGE, refer to this.

答案2

得分: 1

你可以使用 COPY 命令导出 PostgreSQL 表格,使用以下命令可以将边导出到 CSV 文件:

COPY (SELECT * FROM cypher('graph_name', $$
    MATCH (a)-[e]->(b)
    RETURN start_id(e), label(a), end_id(e), label(b) $$)
    AS (start_id agtype, start_vertex_type agtype, end_id agtype, end_vertex_type agtype)
) TO '/path_to_csv/edges_graph.csv' DELIMITER ',' CSV HEADER;

要导出节点,您需要手动检索属性并使用列列表定义作为标头。例如,如果您有一个带有属性如 id、name 和 age 的 person 顶点,代码会如下所示:

COPY (SELECT * FROM cypher('graph_name', $$
    MATCH (a)
    RETURN a.id, a.name, a.age $$)
    AS (id agtype, name agtype, age agtype)
) TO '/path_to_csv/person_vertex_graph.csv' DELIMITER ',' CSV HEADER;

有关如何执行此操作的更多信息,请查看这里

最后,您可以使用文档从 CSV 文件导入。以下是从 CSV 导入 Person 节点的示例:

SELECT create_vlabel('graph_name','Person');
SELECT load_labels_from_file('graph_name',
                             'Person',
                             'path_to_csv/person_vertex_graph.csv');
英文:

You can export the postgres table using COPY, using this command you can export the edges to a csv file:

COPY (SELECT * FROM cypher('graph_name', $$
    MATCH (a)-[e]->(b)
    RETURN start_id(e), label(a), end_id(e), label(b) $$)
    AS (start_id agtype, start_vertex_type agtype, end_id agtype, end_vertex_type agtype)
) TO '/path_to_csv/edges_graph.csv' DELIMITER ',' CSV HEADER;

To export nodes, you need to manually retrieve the properties and use the column list definition as the header. For example, if you have a person vertex with properties like id, name, and age, the code would look like this:

COPY (SELECT * FROM cypher('graph_name', $$
    MATCH (a)
    RETURN a.id, a.name, a.age $$)
    AS (id agtype, name agtype, age agtype)
) TO '/path_to_csv/person_vertex_graph.csv' DELIMITER ',' CSV HEADER;

More information about how to do it on here.

Finally, you can import from the csv file using the documentation. Here is an example for importing the Person nodes from csv:

SELECT create_vlabel('graph_name','Person');
SELECT load_labels_from_file('graph_name',
                             'Person',
                             'path_to_csv/person_vertex_graph.csv');

答案3

得分: 1

你可以使用Neo4j的Apoc工具从数据库中提取数据并以CSV文件的形式导出。然后,你可以将导出的数据导入到Apache Age中。

假设我们有以下电影数据集:

CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
CREATE (Carrie:Person {name:'Carrie-Anne Moss', born:1967})
CREATE (Laurence:Person {name:'Laurence Fishburne', born:1961})
CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})
CREATE (LillyW:Person {name:'Lilly Wachowski', born:1967})
CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})
CREATE (JoelS:Person {name:'Joel Silver', born:1952})
CREATE
(Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
(Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
(Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
(Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
(LillyW)-[:DIRECTED]->(TheMatrix),
(LanaW)-[:DIRECTED]->(TheMatrix),
(JoelS)-[:PRODUCED]->(TheMatrix);

现在,要将此数据以CSV格式导出:

CALL apoc.export.csv.all("movies.csv", {})

我们可以使用Neo4j的不同函数,如**"apoc.export.csv.data""apoc.export.csv.query"**,将数据导出为单独的标签和边文件。一旦我们将数据以标签和边的形式导出,就可以将其导入Apache Age中。

在Apache Age中导入数据:

我们可以使用以下命令从文件加载标签:

load_labels_from_file('<graph name>', 
                      '<label name>',
                      '<file path>', 
                      false)
#第四个参数是可选的,仅在文件中没有id字段时使用。

该文件的CSV格式如下:

id - properties

如果我们已经提供了第四个参数并且为false,id列将被排除在外。

要加载关系,请使用以下函数:

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

该文件的CSV格式如下:

start_id - start_vertex_type - end_id - end_vertex_type - properties

英文:

You can use the Apoc from neo4j to extract the data in the form of CSV file. and after you have exported you can import the data into the apache age.

Let's assume we have this movies dataset:

CREATE (TheMatrix:Movie {title:&#39;The Matrix&#39;, released:1999, tagline:&#39;Welcome to the Real World&#39;})
CREATE (Keanu:Person {name:&#39;Keanu Reeves&#39;, born:1964})
CREATE (Carrie:Person {name:&#39;Carrie-Anne Moss&#39;, born:1967})
CREATE (Laurence:Person {name:&#39;Laurence Fishburne&#39;, born:1961})
CREATE (Hugo:Person {name:&#39;Hugo Weaving&#39;, born:1960})
CREATE (LillyW:Person {name:&#39;Lilly Wachowski&#39;, born:1967})
CREATE (LanaW:Person {name:&#39;Lana Wachowski&#39;, born:1965})
CREATE (JoelS:Person {name:&#39;Joel Silver&#39;, born:1952})
CREATE
(Keanu)-[:ACTED_IN {roles:[&#39;Neo&#39;]}]-&gt;(TheMatrix),
(Carrie)-[:ACTED_IN {roles:[&#39;Trinity&#39;]}]-&gt;(TheMatrix),
(Laurence)-[:ACTED_IN {roles:[&#39;Morpheus&#39;]}]-&gt;(TheMatrix),
(Hugo)-[:ACTED_IN {roles:[&#39;Agent Smith&#39;]}]-&gt;(TheMatrix),
(LillyW)-[:DIRECTED]-&gt;(TheMatrix),
(LanaW)-[:DIRECTED]-&gt;(TheMatrix),
(JoelS)-[:PRODUCED]-&gt;(TheMatrix);

Now for exporting this data in csv format:

CALL apoc.export.csv.all(&quot;movies.csv&quot;, {})

We can use different functions from Neo4j like "apoc.export.csv.data" or "apoc.export.csv.query" to export data in the form of separate labels and edges files. Once we have the data in labels and edges form we can use that to import it in Apache Age.

Importing data in Apache Age:

We can load the labels from file using this command:

load_labels_from_file(&#39;&lt;graph name&gt;&#39;, 
                  &#39;&lt;label name&gt;&#39;,
                  &#39;&lt;file path&gt;&#39;, 
                  false)
#The fourth parameter is optional, use this only when you have no id field in file.

The CSV format for this file is as follows:

id - properties

The id column will be exempted if we have given the fourth parameter and it's false.

For loading relationships, this function will be used:

load_edges_from_file(&#39;&lt;graph name&gt;&#39;,
                &#39;&lt;label name&gt;&#39;,
                &#39;&lt;file path&gt;&#39;);

The CSV format for this file is as follows:

start_id - start_vertex_type - end_id - end_vertex_type - properties

答案4

得分: 1

要将图导出到另一个数据库,您可以将它导出到CSV文件中,可以使用Postgres的COPY命令。其语法如下。

COPY ( SELECT * FROM <表名> ) TO '绝对路径/导出.csv' WITH CSV HEADER;

您可以参考GitHub上的类似问题以获取更多上下文信息。

要导入CSV文件,Apache AGE的官方文档提供了详细的说明。

英文:

To export a graph to another database, You can export it to a CSV file the postgres COPY command can be used. Its syntax is like this.

COPY ( SELECT * FROM &lt;table name&gt; ) TO &#39;absolute/path/to/export.csv&#39; WITH CSV HEADER;

You can refer to this similar issue on GitHub for more context.

To import a CSV file, the Apache AGE official documentation provides a detailed description.

答案5

得分: 1

GraphML是一种众所周知的基于XML的格式,可用于表示图形。它也可以轻松用于Apache AGE。

将数据传输到Apache AGE使用GraphML的步骤如下:

  1. 使用Apache AGE CLI使用以下命令将图数据连接到源数据库:'age-sh'。

  2. 运行以下Cypher查询将图数据保存到文件中:

    EXPORT GRAPH TO 'graph_export.graphml';

英文:

GraphML is a well-known XML based format and can be used for representing graphs. It can be easily used in Apache AGE as well.

The steps to transfer data to Apache AGE using graphML are as follows:

  1. Use the Apache AGE CLI to connect the graph data to the source database using the command: ‘age-sh’.

  2. The graph data will be saved in a file by running the following cypher query:

    EXPORT GRAPH TO 'graph_export.graphml';

答案6

得分: 0

你必须将数据库导出并导入为CSV格式。请在AGE网站上查看完整的教程。

英文:

you have to export and import the database as the CSV format. Follow a complete tutorial on the AGE WEBSITE.

答案7

得分: 0

使用pg_dump和pg_restore导出和导入整个数据库,包括图形数据,在不同数据库之间。

英文:

use pg_dump and pg_restore to export and import the entire database, including the graph data, between databases

huangapple
  • 本文由 发表于 2023年6月5日 04:23:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76402266.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定