Background
I want to create a set (rows) of single users with columns from values from child nodes. But I am not able to understand how to aggregate this (with subqueries?).
Data
- (:UsedMeasure)
/
(:User) -- (:UsedMeasure)
| \
| - (:UsedMeasure)
|
- (:UsedMeasure)
So it is user(1)-measure(n).
We have 19 types of measure and we want to know, which measure has been chosen by a user and which not.
No I want to create a set of rows with exactly 1 row per user, something like (we can ignore the (:Address)
part here):
MATCH (u:User {isBetUser: true})--(a:Address) WHERE (u)-->(:UsedMeasure) WITH u, a CALL { WITH u MATCH (u)-->(m:UsedMeasure) WITH COLLECT(m.name) AS chosen RETURN {LabelAChosen: ('LabelA' IN chosen)} AS map} RETURN ID(u), a.addressCityCode, map.LabelAChosen;
+----------------------------------------------+
| ID(u) | a.addressCityCode | map.LabelAChosen |
+----------------------------------------------+
| 107 | "12345" | FALSE |
| 161 | "32523" | TRUE |
| 402 | "12345" | FALSE |
| 438 | "34567" | FALSE |
| 443 | "48593" | FALSE |
| 493 | "12455" | TRUE |
| 509 | "24211" | FALSE |
| 516 | "45667" | FALSE |
| 528 | "34737" | TRUE |
| 535 | "12345" | FALSE |
+----------------------------------------------+
This would work for all 19 types of these children.
But one more thing makes it complicated:
measure (:UsedMeasure {name: 'LabelA', confirmed ?: 'percent50', confirmExplain ?: 'something'})
where ?:
means optional property, can be NULL.
Now I am trying to do something like this (playing with just 1 out of 19 types of measure):
MATCH (u:User {isBetUser: true})--(a:Address) WHERE (u)-->(:UsedMeasure)
WITH u, a CALL {
WITH u MATCH (u)-->(m:UsedMeasure) // multiple rows for the same user, but I want just 1
WITH COLLECT({n: m.name, c: m.confirmed, ex: m.confirmExplain}) AS maps
RETURN {
LabelAChosen: ('LabelA' IN maps) // here don't know, how to filter in collection of maps / nodes
LabelAConfirmed: // ??
} AS map}
RETURN ID(u), a.addressCityCode, map.LabelAChosen;
Is there any way (some apoc magic) to filter a collected list of maps or the nodes (m:UsedMeasure
) for getting the child measure of a certain type (name
) and putting something like COALESCE(m.confirmed, '')
as {name}Confirmed to the user row?