Keeping a COLLECTION in a table, even if I want to show individual items per row

8 views
Skip to first unread message

Christoph Pingel

unread,
Jun 4, 2018, 11:17:02 AM6/4/18
to neo4j
Hi, 

I stumbled over an interesting problem. I have a simple tree of items that are part of other items. We need to find out in an efficient manner (and that's why we use neo4j) if some composite item (= has parts) is compliant with a certain norm, depending on the question if all of its parts are compliant.

I want to use a reduce formula for a logical AND connection between all the part's compliance.

So here's the query that *almost* answers all our questions:

match (b:part)-[r:PART_OF*]->(c) where c.num='511164-0890'
with collect(b) as bb, b, c 
return b.name as Part, b.ynum as `Part number`, b.is_compliant as compliant, c.name as Product, reduce(all_compliant=true, bbb in bb | all_compliant=true AND bbb.compliant=1) as `all_compliant`

The only problem is that my collection collects only ONE item, the one that is presented in the row of my table.

If I leave the individual parts out of the return, I get what I want:

match (b:part)-[r:PART_OF*]->(c) where c.num='511164-0890'
with collect(b) as bb, c 
return c.name as Product, reduce(all_compliant=true, bbb in bb | all_compliant=true AND bbb.compliant=1) as `all_compliant`

Is there a way to bind a collection to some variable outside the loop, so that I can display individual parts without reinitializing the collection for each row, and still be able to use the reduce statement for the *general* compliance?

Thanks for any input,
best regards,
Christoph





--
// Christoph Pingel, M.A. • ping...@gmail.com

Kamal Murthy

unread,
Jun 4, 2018, 6:22:02 PM6/4/18
to Neo4j

Hi,

You can use UNWIND to transform any list back into individual rows.

Try this:

match (b:part)-[r:PART_OF*]->(c) where c.num='511164-0890'
with collect(b) as bb, b, c 
UNWIND bb as n1
return n1.name as Part, n1.ynum as `Part number`, n1.is_compliant as compliant, c.name as Product, reduce(all_compliant=true, bbb in bb | all_compliant=true AND bbb.compliant=1) as `all_compliant`

-Kamal

Christoph Pingel

unread,
Jun 5, 2018, 3:06:14 AM6/5/18
to neo4j
Thanks, I'll give it a try!

best regards,
Christoph

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
// Christoph Pingel, M.A. • 0170-5733755 • ping...@gmail.com

Christoph Pingel

unread,
Jun 5, 2018, 4:51:38 AM6/5/18
to neo4j
Thanks, Kamal, it worked like a charm.
So just for the sake of understanding:

If I want to keep a collection while outputting the individual rows, I need to create the collection first and access the individual items by UNWINDing the collection afterwards.

Correct?

thank you and best regards,
Christoph

Sudha Murthy

unread,
Jun 5, 2018, 11:14:45 AM6/5/18
to ne...@googlegroups.com
Hi,

Yes, that's correct. Glad to hear that it worked!
Thanks,
-Kamal


You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/cUGffZ9OaHY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages