2
votes

I'm query a Neo4j Server with the following Cypher nad it works fine:

GraphDatabaseService neo4j = new RestGraphDatabase("http://my.ip:7474/db/data");
ExecutionEngine engine = new ExecutionEngine(
String myCypher = "START n = node(1234) RETURN n LIMIT 10;"
ExecutionResult result = engine.execute(myCypher);
System.out.println(result);

If I change the first line of the query to START n = node(*) RETURN n LIMIT 10; I get this ugly exception when I try to print the result:

Exception in thread "main" java.lang.UnsupportedOperationException at org.neo4j.rest.graphdb.AbstractRemoteDatabase.getNodeManager(AbstractRemoteDatabase.java:144) at org.neo4j.rest.graphdb.RestGraphDatabase.getNodeManager(RestGraphDatabase.java:33) at org.neo4j.tooling.GlobalGraphOperations.(GlobalGraphOperations.java:39) at org.neo4j.tooling.GlobalGraphOperations.at(GlobalGraphOperations.java:51) at org.neo4j.cypher.internal.executionplan.builders.GraphGlobalStartBuilder$$anonfun$createStartPipe$1.apply(GraphGlobalStartBuilder.scala:51) at org.neo4j.cypher.internal.executionplan.builders.GraphGlobalStartBuilder$$anonfun$createStartPipe$1.apply(GraphGlobalStartBuilder.scala:51) at org.neo4j.cypher.internal.pipes.StartPipe$$anonfun$1.apply(StartPipe.scala:38) at org.neo4j.cypher.internal.pipes.StartPipe$$anonfun$1.apply(StartPipe.scala:37) at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:200) at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:200) at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) at scala.collection.immutable.List.foreach(List.scala:45) at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:200) at scala.collection.immutable.List.flatMap(List.scala:45) at org.neo4j.cypher.internal.pipes.StartPipe.createResults(StartPipe.scala:37) at org.neo4j.cypher.internal.pipes.MatchPipe.createResults(MatchPipe.scala:31) at org.neo4j.cypher.internal.pipes.NamedPathPipe.createResults(NamedPathPipe.scala:26) at org.neo4j.cypher.internal.pipes.FilterPipe.createResults(FilterPipe.scala:28) at org.neo4j.cypher.internal.pipes.ExtractPipe.createResults(ExtractPipe.scala:37) at org.neo4j.cypher.internal.pipes.EagerAggregationPipe.createResults(EagerAggregationPipe.scala:49) at org.neo4j.cypher.internal.pipes.ExtractPipe.createResults(ExtractPipe.scala:37) at org.neo4j.cypher.internal.pipes.ColumnFilterPipe.createResults(ColumnFilterPipe.scala:39) at org.neo4j.cypher.internal.pipes.EagerAggregationPipe.createResults(EagerAggregationPipe.scala:49) at org.neo4j.cypher.internal.pipes.ExtractPipe.createResults(ExtractPipe.scala:37) at org.neo4j.cypher.internal.pipes.ColumnFilterPipe.createResults(ColumnFilterPipe.scala:39) at org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$4$$anonfun$apply$2.apply(ExecutionPlanImpl.scala:95) at org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$4$$anonfun$apply$2.apply(ExecutionPlanImpl.scala:95) at org.neo4j.cypher.PipeExecutionResult.immutableResult(PipeExecutionResult.scala:37) at org.neo4j.cypher.PipeExecutionResult.iterator(PipeExecutionResult.scala:153) at org.neo4j.cypher.PipeExecutionResult.hasNext(PipeExecutionResult.scala:155) at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:334) at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:334) at scala.collection.Iterator$class.toString(Iterator.scala:1030) at scala.collection.Iterator$$anon$19.toString(Iterator.scala:333) at java.lang.String.valueOf(String.java:2826) at scala.collection.mutable.StringBuilder.append(StringBuilder.scala:185) at scala.collection.TraversableOnce$$anonfun$addString$1.apply(TraversableOnce.scala:287) at scala.collection.Iterator$class.foreach(Iterator.scala:660) at scala.Product$$anon$1.foreach(Product.scala:38) at scala.collection.TraversableOnce$class.addString(TraversableOnce.scala:285) at scala.Product$$anon$1.addString(Product.scala:38) at scala.collection.TraversableOnce$class.mkString(TraversableOnce.scala:263) at scala.Product$$anon$1.mkString(Product.scala:38) at scala.runtime.ScalaRunTime$._toString(ScalaRunTime.scala:175) at scala.collection.JavaConversions$IteratorWrapper.toString(JavaConversions.scala:561) at java.lang.String.valueOf(String.java:2826) at java.io.PrintStream.println(PrintStream.java:771)

Also, things like System.out.println(result.columns()) work fine and I can execute everything perfectly from the console... What's going on?

EDIT:

The query seems to return too fast, is there anything that I should do 'to make java wait' for a full response?

2
seems to be odd. what do you get if you execute the query in pure cypher console (via weadmin for example)?ulkas
from the console it works fine, I get 10 nodes backMarsellus Wallace

2 Answers

2
votes

Don't do that!

Use new RestCypherQueryEngine(restGraphDb.getRestAPI()) instead, otherwise all your queries are run on the client and each database access goes over the network.

And make sure to use parameters in your queries.

Use:

QueryResult<Map<String, Object>> query(String statement, Map<String, Object> params)
0
votes

from this post: https://stackoverflow.com/a/6953423/1498109

i guess you are trying to convert an object/array to string at System.out.println(result)