--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-develop...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi niphlod,In theory the main advantage of iterselect is to lower the memory footprint, only one row at a time is parsed and in theory 'consumed' by the application. It is a basic iterator and so, in this first version if you want to know the total length or access previous row, then you have to use common select.
Regarding fetchone, do you know any driver that support such streaming operation ?
I agree. We need this and it is not too hard.
--
To be more precise. It should paginate select and loop parse and yield records. Fetch next page as needed.
I disagree. This will only make things slower because of you are fetching you are planning to use them.
To be more precise. It should paginate select and loop parse and yield records. Fetch next page as needed.
--
Regarding iterselect, I'll see how to integrate the fetchone method of the DBAPI, in this case, I don't think it is simple to cache the result.
If the network latency is high, a further option for iterselect could be the use of fetchmany instead of fetchone ?(https://www.python.org/dev/peps/pep-0249/#fetchmany).
--
OK. This makes sense. We should got for it. We can improve it later in order to work on speed.
Looks good to me. There's something that annoys me about _parse as I think it repeats a lot of work for every row, but it's not an iterselect/iterparser specific problem.
--
I think we will want to support more than just compact. I think we should return an IterRows object, a new class that would implement this iterator and would have many of the other Rows methods namely I would like it to have render implemented. I do think the current implementation is ok for now and we can work on its limitations in the future.
--
__item__ is not so common for an iterator. How should you implement it ?lets take an IterRows of 100items.if you do IterRows[50], what happen to the items from 0 up to 49? Should I drop them or I've to save them somewhere.
regarding first(). if I do:IterRows.first()for e in IterRows:# loopThe loop starts from the first or from the second element in the list?
regarding __nonzero__, I'll pre-fetch the first element, and reuse it as first element in the loop.
I don't think that's a good reason. The name clearly indicates it's a generator, people can just make it a list if they want to, no generator ever implements a __getitem__. Even __nonzero__ which I consider useful sort of annoys me as it introduces the overhead of checking for the head to every step and forces the implementation of a custom __iter__.
The reason I wanted an IterRows class was so that it could implement some methods that are useful in Rows like render, as_dict, as_json, etc. Not to make it look like a list. Render would be a prime example of where IterRows would shine since you usually aren't interested in the original Rows if you are rendering.
BTW: The code for Rows.render is quite hard to read thanks to the stupid pep 8 line width limit. I'm all for pep8 but the 80 char line width limit is idiotic if it's going to make things harder for a human to parse.
On Monday, April 13, 2015 at 10:15:00 PM UTC+2, Leonel Câmara wrote:I don't think that's a good reason. The name clearly indicates it's a generator, people can just make it a list if they want to, no generator ever implements a __getitem__. Even __nonzero__ which I consider useful sort of annoys me as it introduces the overhead of checking for the head to every step and forces the implementation of a custom __iter__.
people (me too) are used to do
if result:
blablabla...
with a pure generator, you'd be forced to wrap each time a loop wihin a try:except StopIteration. I don't think the 'overhead' of inspecting _head is that much you'd like to clutter your app's code... or am I missing some way to check it in python with a concise syntax ?
The reason I wanted an IterRows class was so that it could implement some methods that are useful in Rows like render, as_dict, as_json, etc. Not to make it look like a list. Render would be a prime example of where IterRows would shine since you usually aren't interested in the original Rows if you are rendering.
me too. Grid's exporters would enormely benefit from Iterselect, and I made a PR that reduces the calls to database for references records already. That doesn't prevent that a generator with a __getitem__ is NOT a list. Even if you can still do result[5]. The point is that IF you do result[5], you won't be able to do result[4]. But why obscuring the fact that YOU CAN slice with a simple object that masks the raw generator ?
BTW: The code for Rows.render is quite hard to read thanks to the stupid pep 8 line width limit. I'm all for pep8 but the 80 char line width limit is idiotic if it's going to make things harder for a human to parse.
Preaching to a quire, I'm all for NOT following all that pep8 dictates. Still, there are users complaining about their IDE "marking code as red because not pep8 compatible" that sends PR and they get merged...... not sure why.
It's not the first time either that I complain about unreadable-code which I like to call "let's win a contest to make it less LOC possible" (see parse_as_rest() as an example): that goes quite on the opposite direction, but as a general rule I like readable code over pep8 or "less LOC" any time.
Hi all,I've implemented an iterator version for select called iterselect.It basically calls the new iterparse() which parses and yields one row at a time.I've refactored and split the current parse() in order to re-use the common things between parse() and iterparse(); tha new version passed all the current tests, I'll write more later on.The code is here https://github.com/ilvalle/pydal/tree/refactor-parselet me know any comment you might have.Paolo
--