Aggregation framework as stored-procedure in Azure DocumentDB

Aggregation framework as stored-procedure in Azure DocumentDB

The bad news: DocumentDB does not include aggregation capability.

The good news: DocumentDB includes stored procedures and documentdb-lumenize uses this to add aggregation capability that far exceeds that which you are used to with SQL.

As Michael Stonbraker, genius creator of not one but three wildly successful databases (Postgres, Vertica, and VoltDB) said, "It's better to move the code to the data than the other way around." VoltDB was designed to execute Java-language ACID transactional stored procedures running in the same memory space as the data with huge performance and consistency benefits. Well, Microsoft Azure's DocumentDB takes a similar approach except that it's a NoSQL data store using JSON and you write your stored-procedures in JavaScript (or CoffeeScript in my case).

Using this power, I've ported the aggregation engine of the Lumenize library, which I created while working on my PhD at Carnegie Mellon over to run inside of DocumentDB. This instantly upgrades DocumentDB with more powerful declarative aggregation (including full OLAP cube) capability than even the most advanced databases.

A simple groupBy example

Let's assume this is the only data in your collection.

[

  {id1value10}

  {id1value100}

  {id2value20}

  {id3value30}

]

Now, let's call the cube with the following:

{cubeConfig{groupBy'id'field"value"f"sum"}}

After you call the cube stored procedure, you should expect this to be in the  parameter of the response. Note, the _count metric is always calculated even when not specified.

[

  ['id''_count''value_sum'],

  [12110],

  [2120],

  [3130]

]

Full OLAP cube capability

A groupBy is just a one-dimensional OLAP cube and the example above just uses a bit of syntactic sugar to quickly configure this one-dimensional OLAP cube. However, the underlying engine is a fast, light, flexible, declaratively-configured OLAP Cube with powerful hierarchical rollup support. It can be used from node.js projects as well as .NET projects or any other platform using DocumentDB's REST API.

You can read all about this capability as well as all the details on how to use it on theGitHub page for documentdb-lumenize.

This is still a work in progress, so please give me your feedback.

Gulam Mohamed

CTO at Bucca Solutions

8 年

Hi Larry, My apologies for posting this here, how could we do this grouping using documentdb-lumenize? "{ $match:{$and:[{'Id':'" + deviceId + "'}, {$or:[ {$and:[{'dw." + archiveField + "':null}, {T1:{'$lt':" + dateStart.ToString() + "}} ]}, {$and:[{'dw." + archiveField + "':null}, {T1:{'$gte':" + dateStart.ToString() + ", '$lte':" + dateEnd.ToString() + "}} ]} ]} ]} }"

回复

要查看或添加评论,请登录

Larry Maccherone的更多文章

社区洞察

其他会员也浏览了