[storm] Compiling python list comprehensions into SQL

Johan Dahlin jdahlin at async.com.br
Thu Aug 9 19:34:04 BST 2007


Hi

I few weeks ago I decided to spend a little time on an small hack which
would make it possible to use python list comprehensions and avoid
the penalty imposed when executing logic on the client side.

Eg, Why shouldn't it be possible to write this kind of code:

   cost = sum(e.salary * e.comission for e in company.employees)

instead of;

   result = company.employees.find(Employee.company_id == Company.id)
   cost = result.sum(Employee.salary * Employee.comission)

The former version is far more readable but unfortunately a lot slower
when the size of the database increases.

Attached is a small proof of concept I wrote which with help of a
decorator and a meta class makes it possible to mark methods which
then will be optimized.

I'm not suggesting that this should be included in Storm itself, it's
pretty hackish as it is right now. I'm just proving that it can be done
and making sure that this can be found by anyone having similar ideas.

Johan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: comp.py
Type: text/x-python
Size: 7361 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/storm/attachments/20070809/26d9828c/attachment-0001.py 


More information about the storm mailing list