diff --git a/mage/query-modules/python/export-util.md b/mage/query-modules/python/export-util.md index 1f7cb7b09e5..6b76f7fc911 100644 --- a/mage/query-modules/python/export-util.md +++ b/mage/query-modules/python/export-util.md @@ -36,11 +36,19 @@ module supports [**exporting database to a JSON file format**](#jsonpath) and [* -### `json(path)` +### `json(path, config)` #### Input: -* `path: string` ➡ Path to the JSON file containing the exported graph database. +* `path: string = ""` ➡ Path to the JSON file containing the exported graph database. +* `config: Map` ➡ Map of the configuration with the following keys: + - `stream (bool) = False:` ➡ Flag to export the graph data to a stream. By default, set to `false`. + - `write_properties (bool) = True:` ➡ Flag to keep node and relationship properties. By default, set to `true`. + +#### Output: + +* `path: string` ➡ the path to the exported file. +* `data: string` ➡ exported data if the stream flag was set to `true`. #### Usage: @@ -54,7 +62,7 @@ Memgraph. {label: 'Docker', value: 'docker'}, {label: 'Linux', value: 'linux'}, ] -}> +}> @@ -97,6 +105,43 @@ where `path` is the path to a local JSON file that will be created inside the +### `json_graph(nodes, relationships, path, config)` + +Exports the given nodes and relationships to the JSON format. All nodes from the relationships have to be contained in the nodes as well. + +#### Input: + +* `nodes: List[Node]` ➡ list of nodes to export. +* `relationships: List[Relationship]` ➡ list of relationships to export. +* `path: string` ➡ Path to the JSON file containing the exported graph database. +* `config: Map` ➡ Map of the configuration with the following keys: + - `stream (bool) = False:` ➡ Flag to export the graph data to a stream. By default, set to `false`. + - `write_properties (bool) = True:` ➡ Flag to keep node and relationship properties. By default, set to `true`. + +#### Output: + +* `path: string` ➡ the path to the exported file. +* `data: string` ➡ exported data if the stream flag was set to `true`. + +### `cypher_all(path, config)` + +Exports the graph to the Cypher query language in the specified file or stream. + +#### Input: + +* `path: string = ""` ➡ path to the Cypher file containing the exported graph database. +* `config: Map` ➡ map of the configuration with the following keys: + - `stream (bool) = False:` ➡ flag to export the graph data to a stream. By default, set to `false`. + - `write_properties (bool) = True:` ➡ flag to keep node and relationship properties. By default, set to `true`. + - `write_triggers (bool) = True:` ➡ flag to export graph triggers. + - `write_indexes (bool) = True:` ➡ flag to export indexes. + - `write_constraints (bool) = True:` ➡ flag to export constraints. + +#### Output: + +* `path: string` ➡ the path to the exported file. +* `data: string` ➡ exported data if the stream flag was set to true. + ### `csv_query(query, file_path, stream)` #### Input: @@ -122,7 +167,7 @@ Memgraph. {label: 'Docker', value: 'docker'}, {label: 'Linux', value: 'linux'}, ] -}> +}> @@ -194,7 +239,7 @@ CREATE (n)-[:IS_FRIENDS_WITH]->(m), (n)-[:IS_FRIENDS_WITH]->(k), (m)-[:IS_MARRIE The image below shows the above data as a graph: - + @@ -340,7 +385,7 @@ CREATE The image below shows the above data as a graph: - + @@ -392,3 +437,41 @@ Erica Sinclair,Priah Ferguson,Stranger Things,2016,"['Matt Duffer', 'Ross Duffer + +## Example - Exporting query results to a Cypher file + +Running the following on the graph above: +```cypher +CALL export_util.cypher_all("export.cyp") YIELD path RETURN path; +``` +will produce the following `export.cyp` file: +```plaintext +CREATE (n:TVShow:_IMPORT_ID {title: 'Stranger Things', released: 2016, program_creators: ['Matt Duffer', 'Ross Duffer'], _IMPORT_ID: 0}); +CREATE (n:Character:_IMPORT_ID {name: 'Eleven', portrayed_by: 'Millie Bobby Brown', _IMPORT_ID: 1}); +CREATE (n:Character:_IMPORT_ID {name: 'Joyce Byers', portrayed_by: 'Millie Bobby Brown', _IMPORT_ID: 2}); +CREATE (n:Character:_IMPORT_ID {name: 'Jim Hopper', portrayed_by: 'Millie Bobby Brown', _IMPORT_ID: 3}); +CREATE (n:Character:_IMPORT_ID {name: 'Mike Wheeler', portrayed_by: 'Finn Wolfhard', _IMPORT_ID: 4}); +CREATE (n:Character:_IMPORT_ID {name: 'Dustin Henderson', portrayed_by: 'Gaten Matarazzo', _IMPORT_ID: 5}); +CREATE (n:Character:_IMPORT_ID {name: 'Lucas Sinclair', portrayed_by: 'Caleb McLaughlin', _IMPORT_ID: 6}); +CREATE (n:Character:_IMPORT_ID {name: 'Nancy Wheeler', portrayed_by: 'Natalia Dyer', _IMPORT_ID: 7}); +CREATE (n:Character:_IMPORT_ID {name: 'Jonathan Byers', portrayed_by: 'Charlie Heaton', _IMPORT_ID: 8}); +CREATE (n:Character:_IMPORT_ID {name: 'Will Byers', portrayed_by: 'Noah Schnapp', _IMPORT_ID: 9}); +CREATE (n:Character:_IMPORT_ID {name: 'Steve Harrington', portrayed_by: 'Joe Keery', _IMPORT_ID: 10}); +CREATE (n:Character:_IMPORT_ID {name: 'Max Mayfield', portrayed_by: 'Sadie Sink', _IMPORT_ID: 11}); +CREATE (n:Character:_IMPORT_ID {name: 'Robin Buckley', portrayed_by: 'Maya Hawke', _IMPORT_ID: 12}); +CREATE (n:Character:_IMPORT_ID {name: 'Erica Sinclair', portrayed_by: 'Priah Ferguson', _IMPORT_ID: 13}); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 1}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [1, 2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 2}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [1, 2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 3}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [1, 2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 4}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [1, 2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 5}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [1, 2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 6}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [1, 2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 7}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [1, 2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 8}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [1, 2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 9}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [1, 2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 10}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [1, 2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 11}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 12}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [3, 4]}]->(m); +MATCH (n:_IMPORT_ID {_IMPORT_ID: 13}) MATCH (m:_IMPORT_ID {_IMPORT_ID: 0}) CREATE (n)-[:ACTED_IN {seasons: [2, 3, 4]}]->(m); +MATCH (n:_IMPORT_ID) REMOVE n:`_IMPORT_ID` REMOVE n._IMPORT_ID; +``` \ No newline at end of file diff --git a/mage/query-modules/python/import-util.md b/mage/query-modules/python/import-util.md index 589c53fe47a..89a2edc5e6f 100644 --- a/mage/query-modules/python/import-util.md +++ b/mage/query-modules/python/import-util.md @@ -36,6 +36,16 @@ supports only the import of JSON file format. +### `cypher(path)` + +Imports the Cypher queries from the given path by just running the queries. + +#### Input: + +* `path: string` ➡ path to the Cypher file that needs to be imported. + +This procedure is not fully functional and was created for testing. If you want to import Cypher, use the Memgraph Lab import feature, which is fully functional and faster. + ### `json(path)` #### Input: @@ -62,7 +72,7 @@ nodes or relationships. If the object is node, then it looks like this: "type": "node" } ``` - + The `id` key has the value of the Memgraph's internal node ide. The `labels` key holds the information about node labels in a list. The `properties` are key-value pairs representing properties of the certain node. Each node needs to @@ -101,7 +111,7 @@ Memgraph. {label: 'Docker', value: 'docker'}, {label: 'Linux', value: 'linux'}, ] -}> +}> @@ -119,7 +129,7 @@ where `path` is the path to the JSON file inside the `/usr/lib/memgraph/query_modules/import.json`). :::info -You can copy the JSON file to the running Docker container with the [`docker cp`](https://docs.docker.com/engine/reference/commandline/cp/) command: +You can copy the JSON file to the running Docker container with the [`docker cp`](https://docs.docker.com/engine/reference/commandline/cp/) command: ``` docker cp /path_to_local_folder/import.json :/usr/lib/memgraph/query_modules/import.json ``` @@ -152,11 +162,11 @@ where `path` is the path to a local JSON file that will be created inside the }> -Below is the content of the `import.json` file. +Below is the content of the `import.json` file. - If you're using **Memgraph with Docker**, then you have to save the `import.json` file in the `/usr/lib/memgraph/query_modules` directory inside - the running Docker container. + the running Docker container. - If you're using **Memgraph on Ubuntu, Debian, RPM package or WSL**, then you have to save the `import.json` file in the local