Any Python OLAP/MDX ORM engines?

后端 未结 4 732
生来不讨喜
生来不讨喜 2020-12-13 23:12

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 the

4条回答
  •  囚心锁ツ
    2020-12-13 23:45

    Django has some OLAP features that are nearing release.

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

    http://doughellmann.com/2007/12/30/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.

提交回复
热议问题