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.
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?
On Mon, Oct 15, 2012 at 3:18 PM, Wujek Srujek <wujek.sru...@gmail.com> wrote:
> 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.
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?
On Tuesday, October 16, 2012 3:39:07 PM UTC+2, Peter Neubauer wrote:
> 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?
> On Mon, Oct 15, 2012 at 3:18 PM, Wujek Srujek <wujek....@gmail.com<javascript:>> > wrote: > > 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.
> 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
> On Tuesday, October 16, 2012 3:39:07 PM UTC+2, Peter Neubauer wrote:
>> 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?
>> On Mon, Oct 15, 2012 at 3:18 PM, Wujek Srujek <wujek....@gmail.com> wrote:
>> > 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.