views:

1308

answers:

3

I'm new to the MDX/OLAP and I'm wondering if there is any ORM similar like Django ORM for Python that would support OLAP.

I'm a Python/Django developer and if there would be something that would have some level of integration with Django I would be much interested in learning more about it.

+3  A: 

Django has some OLAP features that are nearing release.

Read http://www.eflorenzano.com/blog/post/secrets-django-orm/

See http://blog.doughellmann.com/2007/12/using-raw-sql-in-django.html, also

If you have a proper star schema design in the first place, then one-dimensional results can have the following form.

from myapp.models import SomeFact
from collections import defaultdict

facts = SomeFact.objects.filter( dimension1__attribute=this, dimension2__attribute=that )
myAggregates = defaultdict( int )
for row in facts:
    myAggregates[row.dimension3__attribute] += row.someMeasure

If you want to create a two-dimensional summary, you have to do something like the following.

facts = SomeFact.objects.filter( dimension1__attribute=this, dimension2__attribute=that )
myAggregates = defaultdict( int )
for row in facts:
    key = ( row.dimension3__attribute, row.dimension4__attribute )
    myAggregates[key] += row.someMeasure

To compute multiple SUM's and COUNT's and what-not, you have to do something like this.

class MyAgg( object ):
    def __init__( self ):
        self.count = 0
        self.thisSum= 0
        self.thatSum= 0

myAggregates= defaultdict( MyAgg )
for row in facts:
    myAggregates[row.dimension3__attr].count += 1
    myAggregates[row.dimension3__attr].thisSum += row.this
    myAggregates[row.dimension3__attr].thatSum += row.that

This -- at first blush -- seems inefficient. You're trolling through the fact table returning lots of rows which you are then aggregating in your application.

In some cases, this may be faster than the RDBMS's native sum/group_by. Why? You're using a simple mapping, not the more complex sort-based grouping operation that the RDBMS often has to use for this. Yes, you're getting a lot of rows; but you're doing less to get them.

This has the disadvantage that it's not so declarative as we'd like. It has the advantage that it's pure Django ORM.

S.Lott
I wonder how this would be updated to take advantage to Djangos recently included support to multiple databases:http://docs.djangoproject.com/en/dev/topics/db/multi-db/
fccoelho
A: 

I had a similar need - not for a full blown ORM but for a simple OLAP-like data store in Python. After coming up dry searching for existing tools I wrote this little hack:

http://www.structuralknowledge.com/2010/04/20/quick-hack-olap-cube-in-python/

Even if it doesn't solve your exact need, it might be a good starting place for writing something more sophisticated.

kpw
+1  A: 

Same thing as kpw, I write my own stuff, except that it is exclusively for Django :

https://code.google.com/p/django-cube/

sebpiq