cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Return maps in map possible?

rob2
Node Clone

HI

i have the following query working basd on

MATCH 
	(NodeStatusLeft: status)
		<-[ :current_status {status: "active"} ]-
	(NodeLeft: person)
			-[ :has_mail {status: "active"} ]->
		(NodeRight: mail)
			-[ :current_status {status: "active"} ]->
		(NodeStatusRight)
RETURN
	NodeLeft { .*, ListMail: collect(NodeRight{.*})} as NodeLeft_Mails, NodeStatusLeft

But would like to have INFO about NodeStatusRight al least NodeStatusRight.name, NodeStatusRight.guid in the response.

But I cannot figure out how this is done
any Ideas would be very cool

Thanks rob

5 REPLIES 5

rob2
Node Clone

I have another solution ...

MATCH 
	(NodeStatusLeft: status)
		<-[ :current_status {status: "active"} ]-
	(NodeLeft: person {firstname:"Isabelle"})
			-[ :has_mail {status: "active"} ]->
		(NodeRight: mail)
				-[ :current_status {status: "active"} ]->
					(NodeStatusRight)
	Return
	NodeLeft, NodeRight { .*, ListStatus: collect(NodeStatusRight{.*})}
	;

This gives me

[{"sevsons"}]  [{"name":"third_of_Isabelle@vv.de","ListStatus":[{"name":"use - Mail"}]}]                                                                 
[{"sevsons"}]  [{"name":"first@av.de","ListStatus":[{"name":"use - Mail"}]}]         
[{"sevsons"}]  [{"name":"second_of_Isabelle@vd.de","ListStatus":[{"name":"use - Mail"}]}]

but i would like to have a Group Distinct by

[{"sevsons"}]
         [
         {"name":"third_of_Isabelle@vv.de","ListStatus":[{"name":"use - Mail"}]}                                                                  
         {"name":"first@v.de","ListStatus":[{"name":"use - Mail"}]}           
         {"name":"second_of_Isabelle@v.de","ListStatus":[{"name":"use - Mail"}]}   
         ]

should be simple but I don't get it

Any idea? thanks rob

collect in collect is not allowed ?

Can't use aggregate functions inside of aggregate functions.


MATCH 
	(NodeStatusLeft: status)
		<-[ :current_status {status: "active"} ]-
	(NodeLeft: person {firstname:"Isabelle"})
			-[ :has_mail {status: "active"} ]->
		(NodeRight: mail)
				-[ :current_status {status: "active"} ]->
					(NodeStatusRight)
	Return
	NodeLeft.name, collect(NodeRight { .name, ListStatus: collect(NodeStatusRight{.name})}), NodeStatusLeft;

Provided that your NodeRight nodes only have a single NodeStatusRight, you can just include the NodeStatusRight.name in your map projection

MATCH 
	(NodeStatusLeft: status)
		<-[ :current_status {status: "active"} ]-
	(NodeLeft: person)
			-[ :has_mail {status: "active"} ]->
		(NodeRight: mail)
			-[ :current_status {status: "active"} ]->
		(NodeStatusRight)
RETURN
	NodeLeft { .*, ListMail: collect(NodeRight{.*, statusName:NodeStatusRight.name, statusGuid:NodeStatusRight.guid})} as NodeLeft_Mails, NodeStatusLeft

HI Andrew

Thank you. it works but just under the assumption - which is also correct in this case
that there is only ONE active current status.

But if I want to display the next level and I would like to
the are several possible next status and your solution would no longer work

Anyway first of all thank you very much!

My solution (not working yet)

Could I work with a "CALL in CALL" like double nesting?
But I'm somehwo lost in the return part
any help for me ?

Thanks rob

MATCH 
    (NodeStatusNextLeft: status)
      <-[ :next_status {status: "active"} ]-
      (NodeCurrentStatusLeft: status)
        <-[ :current_status {status: "active"} ]-
        (NodeLeft: person)
          -[ :has_mail {status: "active"} ]->
          (NodeRight)
//##          -[ :current_status {status: "active"} ]->
//##          (NodeCurrentStatusRight)
//##             -[ :next_status {status: "active"} ]->
//##             (NodeStatusNextRight: status)

CALL { WITH NodeRight
        MATCH
        (NodeRight)
          -[ :current_status {status: "active"} ]->
          (NodeCurrentStatusRight)
            CALL { WITH NodeCurrentStatusRight
            MATCH
            ((NodeCurrentStatusRight)-[ :next_status {status: "active"}]->(NodeStatusNextRight))
            WITH distinct NodeStatusNextRight
            RETURN collect(DISTINCT NodeStatusNextRight { .guid, .name}) AS NextStatusListRight
			}
	WITH distinct NodeCurrentStatusRight, NextStatusListRight
    RETURN collect(NodeCurrentStatusRight { .guid, .name}), collect(NextStatusListRight) AS Node_X_StatusRight
}

  Return
  NodeLeft AS LeftNode,
  collect(NodeRight, Node_X_StatusRight) AS RightNodeNEST,
  collect(DISTINCT NodeCurrentStatusLeft { .guid, .name}) AS LeftCurrentNodeStatus,
  collect(DISTINCT NodeStatusNextLeft { .guid, .name}) AS LeftNextNodeStatus

error messaages at the moment is

Too many parameters for function 'collect' (line 32, column 3 (offset: 1096))
"  collect(NodeRight, Node_X_StatusRight) AS RightNodeALL,"
   ^

but i think the error for the nesting begins bevor

mhh almost - get still 3 rows for `sevsons since she has 3 mails but get the next level (After current level) in the second colomn

 MATCH 
    (NodeStatusNextLeft: status)
      <-[ :next_status {status: "active"} ]-
      (NodeCurrentStatusLeft: status)
        <-[ :current_status {status: "active"} ]-
        (NodeLeft: person {firstname: "sevsons"})
          -[ :has_mail {status: "active"} ]->
          (NodeRight)
//##          -[ :current_status {status: "active"} ]->
//##          (NodeCurrentStatusRight)
//##             -[ :next_status {status: "active"} ]->
//##             (NodeStatusNextRight: status)

CALL { WITH NodeRight 
        MATCH
        (NodeRight) 
          -[ :current_status {status: "active"} ]->
          (NodeCurrentStatusRight)
            CALL { WITH NodeCurrentStatusRight
            MATCH
            ((NodeCurrentStatusRight)-[ :next_status {status: "active"}]->(NodeStatusNextRight))
            WITH distinct NodeStatusNextRight, NodeCurrentStatusRight
            RETURN 
			collect(DISTINCT NodeCurrentStatusRight { .name, .guid})+collect(NodeStatusNextRight{ .name, .guid}) AS Node_X_StatusRight
			}
    RETURN
	collect(DISTINCT NodeRight { .name})+collect(Node_X_StatusRight) AS NodeRightNest
}


//################################################################

  Return
  NodeLeft AS LeftNode,
  NodeRightNest,
  collect(DISTINCT NodeCurrentStatusLeft { .guid, .name}) AS LeftCurrentNodeStatus,
  collect(DISTINCT NodeStatusNextLeft { .guid, .name}) AS LeftNextNodeStatus