def _sortChunk(records, key, chunkIndex, fields):
 title(additional=('(key=%s, chunkIndex=%d)' % (str(key), chunkIndex)))
 assert (len(records) > 0)
 records.sort(key=itemgetter(*key))
 if (chunkIndex is not None):
  filename = ('chunk_%d.csv' % chunkIndex)
  with FileRecordStream(filename, write=True, fields=fields) as o:
   for r in records:
    o.appendRecord(r)
  assert (os.path.getsize(filename) > 0)
 return records

def _sortChunk ( records , key , chunkIndex , fields ) : title ( additional = ( '(key=%s, chunkIndex=%d)' % ( str ( key ) , chunkIndex ) ) ) assert ( len ( records ) > 0 ) records . sort ( key = itemgetter ( * key ) ) if ( chunkIndex is not None ) : filename = ( 'chunk_%d.csv' % chunkIndex ) with FileRecordStream ( filename , write = True , fields = fields ) as o : for r in records : o . appendRecord ( r ) assert ( os . path . getsize ( filename ) > 0 ) return records
sort in memory chunk of records records - a list of records read from the original dataset key - a list of indices to sort the records by chunkindex - the index of the current chunk the records contain only the fields requested by the user .