Cypher ExecutionResult traversable only once?

44 views
Skip to first unread message

Wujek Srujek

unread,
Oct 15, 2012, 9:18:49 AM10/15/12
to ne...@googlegroups.com
Hi. I have the following (Groovy) code:

        ExecutionResult res = new ExecutionEngine(graphDb).execute('start from = node({from}) match from-[:IS_PART_OF]->t return t', [from: node])
        println '> first traversal start'
        for (def o : res) {
            println o['t']
        }
        println '> first traversal end'
        println '> second traversal start'
        for (def o : res) {
            println o['t']
        }
        println '> second traversal end'

The results are:
> first traversal start
Node[3]
> first traversal end
> second traversal start
> second traversal end

The output and my debugging results show that somehow I can only traverse the results once. ExecutionResult.iterator first returns an internal Scala iterator whose toString says 'non-empty iterator', but the second time I get an 'empty iterator'.
Is this expected behavior, or am I doing something wrong? I am using the javacompat classes. If this is expected, I think this could be documented, as normally when people see Iterable they think they can traverse the thing multiple times.

Regards,
wujek

Peter Neubauer

unread,
Oct 16, 2012, 9:38:34 AM10/16/12
to ne...@googlegroups.com
Hi Wujek,
yes, this is expected behaviour. Cypher is lazily fetching the results
and will per default not cache the result set. You are right in
documenting this. Could you please raise an issue on that?

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html
> --
>
>

wujek

unread,
Oct 17, 2012, 4:24:00 AM10/17/12
to ne...@googlegroups.com
Hi. Done: https://github.com/neo4j/community/issues/928

One question - if its traversable only once, why the decision to return an Iterable, not an Iterator? This would be very clear. Or does it have something to do with the fact that one needs an Iterable to use the Java for-each loop?

wujek

Peter Neubauer

unread,
Oct 17, 2012, 5:26:12 AM10/17/12
to ne...@googlegroups.com
Thank you Wujek,
I actually marked it as a bug, even if it might not be :)

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html


> --
>
>
Reply all
Reply to author
Forward
0 new messages