Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-23-2020 10:46 PM
I'm trying to divide different short chains according to the head and tail I want in a long chain, and find the max duration in the short chains.
E.g..
Long chain:
NA1 -> NA2 -> NA3 -> NA4 -> NB1 -> NB2 -> NB3 -> NB4 ->...
I want to check whether the max duration in each chain is the second node.
NA1 -> NA2 -> NA3 -> NA4
NB1 -> NB2 -> NB3 -> NB4
( N means node, A,b and the number are the attribute and each node has its own duration )
MATCH p = (A:Task{FROMLOCTYPE:"1"})-[:path*]->(b:Task{TOLOCTYPE:"4"})
WITH reduce(output = , n IN nodes(p) | output + n ) as tasks
But I'm stuck here and don't know how to check the maximum duration in each list.
Or do any operation in each list.
Solved! Go to Solution.
02-25-2020 08:41 AM
I am not very sure if below query is what you looking for
Dynamic type can be coded as below
match (from:Chain)-[rel:CALLED]->(to:Chain) with distinct rel.type as xyz unwind xyz as typeOf match p= (from:Chain)-[rel:CALLED{type:typeOf}]->(to:Chain) with rel.type as type, max(tointeger(rel.duration)) as maxDur return type, maxDur
If your requirement is different, then please frame your output and I will see if I am able to help you
02-24-2020 06:55 AM
Hi,
Could you please provide small dataset and the logic to break the big chain to smaller ones.
Regards
Vivek
02-24-2020 09:22 AM
This is the sample for my data.
I want to confirm that all nodes under the same program control, its longest time is in the second position (from B to C).
Thanks again for your reply.
02-24-2020 10:10 AM
I inserted your sample data as below
A | B | 10 | typeA |
---|---|---|---|
B | C | 12 | typeA |
C | D | 9 | typeA |
D | A | 2 | typeA |
A | B | 11 | typeB |
B | C | 19 | typeB |
C | D | 10 | typeB |
D | A | 5 | typeB |
A | B | 2 | typeC |
![image | 690x282](upload://2QZQci5kzESaOhSTVpIZtkxivfr.png) |
**and applied Query as **
unwind ["typeA","typeB","typeC"] as typeOf match p= (from:Chain)-[rel:CALLED{type:typeOf}]->(to:Chain) with rel.type as type, max(tointeger(rel.duration)) as maxDur return type, maxDur
**Output **
02-24-2020 11:14 AM
Hi, thank for your apply again.
Sorry my previous description was not clear enough.
I know how to find the max duration in one path.
By using
with max(n.attribute) as max_d
return (n.attribute:max_d)
But when I match to multiple path and try to find the max duration on each path.
I don't know how to find.
This is the data I use.
MATCH p = (A:Task{FROMLOCTYPE:"LOAD_PORT"})-[:wafer_path*]->(b:Task{TOLOCTYPE:"LOAD_PORT"})
return p limit 3
I can group nodes according to the classification I want.
But I ’m not sure how to query for the max duration in each group with cypher.
MATCH p = (A:Task{FROMLOCTYPE:"LOAD_PORT"})-[:wafer_path*]->(b:Task{TOLOCTYPE:"LOAD_PORT"})
WITH reduce(output = , n IN nodes(p) | output + n ) as nodeCollection
Sorry my previous description was not clear enough.
Thank you again for your reply
02-25-2020 04:37 AM
Hi,
So you can see that my code is performing based on the type of relationship..
Do you want to find the query dynamically?
02-25-2020 07:34 AM
Hi, thank for your apply again.
Yes I want to find the query dynamically.
I think my problem should be when I find a bunch of lists.
How do I search these nodes at the same time.
A bit like how to find the maximum value of an array in a two-dimensional array.
I want to find the max number in each list I find.
Sorry my previous description was not clear enough.
Thank you again for your reply
02-25-2020 08:41 AM
I am not very sure if below query is what you looking for
Dynamic type can be coded as below
match (from:Chain)-[rel:CALLED]->(to:Chain) with distinct rel.type as xyz unwind xyz as typeOf match p= (from:Chain)-[rel:CALLED{type:typeOf}]->(to:Chain) with rel.type as type, max(tointeger(rel.duration)) as maxDur return type, maxDur
If your requirement is different, then please frame your output and I will see if I am able to help you
02-25-2020 10:51 PM
Thanks for your reply.
This is helpful for me.
But if I don't want to use unwind ["typeA","typeB","typeC"] as typeOf.
How can I match the all type of the relation and unwind it?
All the sessions of the conference are now available online