Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-05-2018 02:47 AM
Hello everyone, I am having some problems with the Cypher procedures.
I want to return the graph that I get from executing a cypher query but I can't wrap my head around what type I need to return from my procedure method and what GraphDatabaseService method I need to execute to get that object. I am pretty sure it is a stream with a custom type containing the data I want to return but what is that precisely?
As my first try I am trying to return the base Hello World query that is included in the Basic Query scripts.
Here is an extract of my procedure method:
@Procedure("ktk.mytest")
@Description("A test procedure that therurns HELLO WORLD!")
public Stream<MyTestResult> test(){
String query;
query = "CREATE (database:Database {name:"Neo4j"})-[r:SAYS]->(message:Message {name:"Hello World!"}) RETURN database, message, r";Stream<MyTestResult> rStream = db.execute(query).stream().map(MyTestResult::new);
return rStream;
}
Thank you very much and sorry for the very simple question, I am quite a noob at this.
Thanks,
Gustavo.
09-05-2018 03:47 AM
Hi Gustavo,
What error do you have with this code ?
Can you give the code of the MyTestResult
class ?
Cheers
09-05-2018 05:33 AM
Sure, here is the code of the MyResult class:
public class MyTestResult {
public long nodeId;
public MyTestResult(Node node) {this.nodeId = node.getId();
}
}
The error is that it cannot convert to type R.
09-22-2018 08:54 PM
Your cypher query returns a iterable of <Map<String, Object>
. MyTestResult
will need a constructor like,
public MyTestResult(Map<String, Object> onerow) {
...
}
That should resolve your syntax error
Cheers
09-25-2018 01:37 AM
Thank you Aldrin, I missed that detail!
All the sessions of the conference are now available online