Search code examples
neo4jcypher

errors calling procedures when using the official "Neo4j Procedure Template"


I am using this official neo4j template to understand how to write customized procedures https://github.com/neo4j-examples/neo4j-procedure-template

I have loaded the compiled JAR file into the plugins directory on a neo4j container (community verison 4.4.4)

The customized function and aggregated function both works as expected. But when I call the customized procedure

MATCH (n:Person)
CALL example.getRelationshipTypes(n);

I got an error

Procedure call inside a query does not support naming results implicitly (name explicitly using `YIELD` instead) (line 2, column 1 (offset: 17))
"CALL example.getRelationshipTypes(n);"
 ^

so I added yield, then i call

MATCH (n:Person)
CALL example.getRelationshipTypes(n)
yield result
return result

then i got another error

Unknown procedure output: `result` (line 3, column 7 (offset: 60))
"yield result"
       ^

How can I call the customized procedure?


Solution

  • If you look at the code of that procedure, you will see that the procedure returns a stream of two variables, outgoing and incoming.

    https://github.com/neo4j-examples/neo4j-procedure-template/blob/4.4/src/main/java/example/GetRelationshipTypes.java

    MATCH (n:Person) 
    CALL example.getRelationshipTypes(n) YIELD outgoing, incoming 
    RETURN n.name as name, outgoing, incoming 
    

    Sample:

    ╒═════════╤══════════╤══════════╕
    │"name"   │"outgoing"│"incoming"│
    ╞═════════╪══════════╪══════════╡
    │"Alice"  │["KNOWS"] │[]        │
    ├─────────┼──────────┼──────────┤
    │"Charlie"│["KNOWS"] │["KNOWS"] │
    ├─────────┼──────────┼──────────┤
    │"Bob"    │["KNOWS"] │["KNOWS"] │
    └─────────┴──────────┴──────────┘