+ 1 for changing dal.py:8359  in
fields = colnames or [f[0] for f in columns]

This will allow us to change the columns name even when as_dict=True. 
Example:
sql  = db(db.coordinate.is_active == True)._select(db.coordinate.point2d.
count(), db.coordinate.point3d.count())
rows = db.executesql(sql, colnames=['count_point2d', 'count_point3d'],as_dict
=True)
print sql, rows[0:1]
will print:
SELECT  COUNT(coordinate.point2d), COUNT(coordinate.point3d) FROM 
coordinate WHERE (coordinate.is_active = 'T');
[{'count_point2d': 35148L, 'count_point3d': 35148L}]

while without the proposed change, I get:
 sql  = db(db.coordinate.is_active == True)._select(db.coordinate.point2d.
count(), db.coordinate.point3d.count())
 rows = db.executesql(sql, as_dict=True)
 print sql, rows[0:1]

will print:

    SELECT  COUNT(coordinate.point2d), COUNT(coordinate.point3d) FROM 
coordinate WHERE (coordinate.is_active = 'T');
   [{'count': 35148L}]

The dict has only one element instead of two! This is because the key 
called 'count' can appear only once.
A workaround I found is to use an alias

count2d = db.coordinate.point2d.count().with_alias('count2d')
count3d = db.coordinate.point2d.count().with_alias('count3d')
sql  = db(db.coordinate)._select(count2d, count3d)
print sql
print db.executesql(sql,as_dict=True)
the output
SELECT  COUNT(coordinate.point2d) AS count2d, COUNT(coordinate.point2d) AS 
count3d FROM coordinate WHERE (coordinate.id IS NOT NULL);
[{'count2d': 60480L, 'count3d': 60480L}]
Now the dict has the two elements I was looking for. 
Beside the fact that this workaround is really less intuitive, it doesn't 
work with point2d and point3d since they're geometry() and alias at the 
moment doesn't work with them: see 
https://code.google.com/p/web2py/issues/detail?id=1789&sort=-id

If there are no objections I will make a PR later today.
Paolo

On Thursday, November 21, 2013 1:28:34 AM UTC+1, Arnon Marcus wrote:
>
> My guess about .select(processor=..) when compared to having a separate 
> "flat" function, is that the additional layer of indirection (function 
> invocation) incurs a small penalty that shows-up.
>
> I did a non-web2py-related test earlier, that showed consisant x2.2 
> penalty of adding a single-layer of indirection, by re-factoring-out a line 
> into a single-liner function
>
> Was something like this:
>
> amount = 100
>
>
> def doWorkDirectly():
>     List = []
>     for i in range(amount):
>         List.appent('a')
>
>
>
>
> def doWork(List): List.append('a')
>
>
> def doWorkIndirectly():
>     List = []
>     for i in range(amount):
>         doWork(List)
>
>
>  
> if you bench doWorkDirectly against doWorkIndirecty, you would get a very 
> solid and sonsistant x2.2 penalty in favor of doWorkDirectly - regardless 
> of the order-of-magnitude of 'amount' (same gap for 10, 1000 and 100000)...
>
> So this is a c-python implementation detail.
>
> Granted, it would show-up more in very simple processing-payload, as there 
> the invocation-overhead overshadows the actual computation expense - in 
> more expensive procedures,  there would still be the same penalty, but it 
> would be less noticeable.
>
> So, passing a one-liner callback (or a lambda, though I havent tried 
> that...) into ".select(processor=...)", for a computationally-simple 
> expense such as zipping a list into a dictionary, .may fall into that 
> category - you may loose more than you gain by it...
>
> As for the parsing logic - that's beyond me, personally...
> Shouldn't that move into the web2py-devs group?
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to