Skip to content

Commit

Permalink
[NiLGknLU] add boolean example to apoc.refactor.normalizeAsBoolean (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nadja-muller authored Oct 8, 2023
1 parent 03f19a1 commit 94650f6
Showing 1 changed file with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ The examples in this section are based on the following sample graph:
CREATE (:Person {prop: 'Y', name:'A'}),
(:Person {prop: 'Yes', name:'B'}),
(:Person {prop: 'NO', name:'C'}),
(:Person {prop: 'X', name:'D'});
(:Person {prop: 'X', name:'D'}),
(:Person {prop: true, name:'E'}),
(:Person {prop: false, name:'F'});
----

We want to transform some properties into a boolean, `Y`, `Yes` into true and the properties `NO` into false.
The other properties that don't match these possibilities will be set as `null`.
The other properties that don't match these possibilities will be set as `null`. This includes `BOOLEAN` values as well.

.The following normalizes all applicable boolean values for all nodes that have the `prop` property:
[source,cypher]
Expand All @@ -25,8 +27,31 @@ RETURN n.name AS name, n.prop AS prop;
[opts="header"]
|===
| name | prop
| "A" | TRUE
| "B" | TRUE
| "C" | FALSE
| "D" | NULL
| "A" | true
| "B" | true
| "C" | false
| "D" | null
| "E" | null
| "F" | null
|===

If you want to keep `BOOLEAN` values as they are, include them in the parameters `trueValues` and `falseValues`:
----
MATCH (n)
CALL apoc.refactor.normalizeAsBoolean(n,'prop',['Y','Yes', true],['NO', false])
WITH n
ORDER BY n.id
RETURN n.name AS name, n.prop AS prop;
----

.Results
[opts="header"]
|===
| name | prop
| "A" | true
| "B" | true
| "C" | false
| "D" | null
| "E" | true
| "F" | false
|===

0 comments on commit 94650f6

Please sign in to comment.