From cb0c0119684b6036e127045a62b59b45ae2553d7 Mon Sep 17 00:00:00 2001 From: imilinovic Date: Wed, 6 Sep 2023 20:21:06 +0200 Subject: [PATCH] refactor functions draft --- mage/query-modules/cpp/refactor.md | 87 ++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/mage/query-modules/cpp/refactor.md b/mage/query-modules/cpp/refactor.md index c0713026d8e..dec5976df83 100644 --- a/mage/query-modules/cpp/refactor.md +++ b/mage/query-modules/cpp/refactor.md @@ -31,3 +31,90 @@ The `refactor` module provides utilities for changing nodes and relationships. | **Parallelism** | **sequential** | ### Procedures + +### `from(relationship, new_from)` + +Redirect the relationship to use a new start (from) node. + +#### Input: + +- `relationship: Relationship` ➡ the relationship to be modified. +- `new_from: Node` ➡ new start (from) node. + +#### Usage: + +```cypher +MERGE (ivan:Person {name: "Ivan"}) MERGE (matija:Person {name: "Matija"}) MERGE (diora:Person {name:"Idora"}) CREATE (ivan)-[:Friends]->(matija); +``` +The following query changes the the relationship `Ivan ➡ Matija` to `Idora ➡ Matija`. +```cypher +MATCH (:Person {name: "Ivan"})-[rel:Friends]->(:Person {name: "Matija"}) MATCH (idora: Person {name:"Idora"}) CALL refactor.from(rel, idora); +``` + +### `to(relationship, new_to)` + +Redirect the relationship to use a new end (to) node. + +#### Input: + +- `relationship: Relationship` ➡ the relationship to be modified. +- `new_to: Node` ➡ new end (to) node. + +#### Usage: + +```cypher +MERGE (ivan:Person {name: "Ivan"}) MERGE (matija:Person {name: "Matija"}) MERGE (diora:Person {name:"Idora"}) CREATE (ivan)-[:Friends]->(matija); +``` +The following query changes the the relationship `Ivan ➡ Matija` to `Ivan ➡ Idora`. +```cypher +MATCH (:Person {name: "Ivan"})-[rel:Friends]->(:Person {name: "Matija"}) MATCH (idora: Person {name:"Idora"}) CALL refactor.to(rel, idora); +``` + +### `rename_label(old_label, new_label, nodes)` + +Rename a label from `old_label` to `new_label` for all nodes. If `nodes` is provided renaming is applied only to the given nodes. If a node doesn't contain the `old_label` the procedure doesn't modify it. + +#### Input: + +- `old_label: str` ➡ old label name. +- `new_label: str` ➡ new label name. +- `nodes: List[Node]` ➡ list of nodes to be modified. + +### Output: + +- `nodes_changed: int` ➡ number of modified nodes. + +#### Usage: + +```cypher +CREATE (:Node1 {title: "Node1"}) CREATE (:Node2 {title: "Node2"}) CREATE (:Node1); +``` +The following query changes the label of the first node to `Node` +```cypher +MATCH(n) WHERE n.title = 'name' WITH collect(n) AS nodes CALL refactor.rename_label("Node1", "Node3", nodes) YIELD nodes_changed RETURN nodes_changed; +``` +```plaintext ++----------------------------+ +| nodes_changed | ++----------------------------+ +| 1 | ++----------------------------+ +``` + +### `rename_node_property(old_property, new_property, nodes)` + +Rename a property from `old_property` to `new_property` for all nodes. If `nodes` is provided renaming is applied only to the given nodes. If a node doesn't contain the `old_property` the procedure doesn't modify it. + +#### Input: + +- `old_property: str` ➡ old property name. +- `new_label: str` ➡ new property name. +- `nodes: List[Node]` ➡ list of nodes to be modified. + +### Output: + +- `nodes_changed: int` ➡ number of modified nodes. + +#### Usage: + +TODO \ No newline at end of file