Skip to content

Commit 50efd4b

Browse files
author
Daniel Kinzler
committed
chunked add-arcs
git-svn-id: https://svn.toolserver.org/svnroot/daniel/duesenstuff/trunk/gpClient@616 9f2c43bc-b3c0-43f4-b155-41619b16f219
1 parent a36b0c3 commit 50efd4b

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

python/gp/client.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,17 @@ class ArraySource( DataSource ):
203203
def __init__( self, data ):
204204
""" Initializes a ArraySource from the table contained in data.
205205
206-
@param data: an array of indexed arrays, each representing a
207-
row in the data source.
206+
@param data: a list of lists or tuples, each representing a
207+
row in the data source. If the list contains integers
208+
or strings, they are wrapped and returned as one-tuples.
208209
209210
"""
210211
self.data = data
211212
self.data_length = len(data)
212213
self.index = 0
213214

214215
def next( self ):
215-
"""Return the next row of the array provided to the constructor."""
216+
"""Return the next row of the list provided to the constructor."""
216217
if self.index < self.data_length:
217218
row = self.data[self.index]
218219
self.index = self.index + 1
@@ -229,13 +230,56 @@ def next( self ):
229230
def makeSink(self):
230231
"""Returns a new instance of ArraySink.
231232
232-
The sink can be used to write to and to fill the data array of
233+
The sink can be used to write to and to fill the data list of
233234
this ArraySource.
234235
235236
"""
236237
return ArraySink(self.data)
237238

238239

240+
class LimitedSource( DataSource ): #TODO: PORT to PHP
241+
"""A data source that wraps another data source to limit the number
242+
of rows returned from it.
243+
244+
This is useful to limit the number of arcs transmitted graphserv in
245+
a single command.
246+
"""
247+
248+
def __init__( self, src, limit ):
249+
""" Initializes a LimitedSource using the given original data source.
250+
251+
@param src: a DataSource object
252+
@param limit: the number of rows to return.
253+
"""
254+
255+
self.source = src
256+
self.limit = limit
257+
self.index = 0
258+
259+
def next( self ):
260+
261+
"""Return the next row of the DataSource provided to the constructor."""
262+
263+
if self.index < self.limit:
264+
row = self.source.next()
265+
self.index = self.index + 1
266+
267+
return row
268+
else:
269+
raise StopIteration()
270+
271+
def limit_reached( self ):
272+
""" returns True if next() has already been called sucessfully as many times
273+
as allowed by the limit parameter passed to the constructor. After
274+
iterating over this LimitedSource instance (i.e. after StopIteration()
275+
has been thrown by next()), this method may be used to determine
276+
whether there may be more data in the original data source. If
277+
iteration was terminated but limit_reached() returns false, then the
278+
original source was depleted and there is no more data available from it.
279+
"""
280+
281+
return ( self.index >= self.limit )
282+
239283
class PipeSource( DataSource ):
240284
"""Data source based on a file handle.
241285

0 commit comments

Comments
 (0)