Kinda related to my last post, but when I try this call:
MATCH (m:Drug {id: 'A'})-[:CONTAINS*2..2]-(neighbors)
return neighbors.id, collect(r1.weight) as weight order by weight desc
I get this error:
Neo.ClientError.Statement.SyntaxError: Type mismatch: expected Any, Map, Node,
Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime
but was List<Relationship> (line 1, column 86 (offset: 85))
"MATCH (m:Drug {id: 'A'})-[r1:CONTAINS*2..2]-(neighbors)
return neighbors.id, collect(r1.weight) as weight order by weight desc"
Is there a reason why I can't order by weight here?
Thx
Because you're using a variable-length relationship, r1
refers to a 2-element collection, the two relationships traversed between the two nodes.
If you want the sum of those two relationships per row, then you can use:
...
WITH m, neighbors, reduce(sum = 0, rel in r1 | sum + rel.weight) as weight
WITH neighbors, sum(weight) as total
ORDER BY total DESC
RETURN neighbors.id, total
If you want the collection of those sums then do a collect(weight)
in that WITH clause as well.
For reference, reduce()
operates on a list on a row (in this case summing the two weights in the relationships), and you could alternately use apoc.coll.sum()
if you have APOC Procedures to do this.
sum()
and collect()
are aggregation functions that do aggregations across multiple rows per your grouping key.
//create constraint on (c:cashier_id) assert c.cashier_id is unique
LOAD CSV FROM 'file:/walmart.csv' AS line
MERGE(c:Cashier{cashier_id:(line.cashier_id),post_entry_type:(line.post_entry_type),payment_type:(line.payment_type)}) WITH c, line
match(l:Location)
MERGE (c)-[:WORKS]->(l)
return l,c, line limit 10
Type mismatch: expected Any, Map, Node, Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime but was List (line 3, column 29 (offset: 139))
"MERGE(c:Cashier{cashier_id:(line.cashier_id),post_entry_type:(line.post_entry_type),payment_type:(line.payment_type)}) WITH c, line"
^
I apply this code but I got this error. How I can solve this error
While the error text seems similar, this is not the same kind of error or cause as the original issue.
You're seeing this because you're loading the CSV but without headers. This means that line
is not a map of values, but a list of values, and you can't use map access to get values for keys, but must perform index access into the list.
Here's the relevant documentation:
To fix, change your LOAD CSV line to be the following:
LOAD CSV WITH HEADERS FROM 'file:/walmart.csv' AS line
Note the WITH HEADERS
part. This allows line
to be a map of keys and values.
Think you , It's working now