Active OLAP is a Rails plugin that eases performing OLAP (online analytical processing) queries on your tables. An introduction to OLAP can be found on Wikipedia, with explains some of the basic concepts like dimensions and fact tables.
In Active OLAP, the table corresponding to your ActiveRecord-derived class acts as a fact table. You can define dimensions that categorizes the records (facts) in the table. A dimension can cluster the records in any number of categories. A combination of these dimensions can be used to perform an OLAP query that returns an OLAP cube.
A simple example: For the fact table
people, the dimension gender will categorize the records into two categories: male (m) and female (f). The age dimension might categorize the records in three categories: youth (y), adults (a) and the elderly (e). An OLAP query on these to dimensions will return a [2×3]-cube with 2×3 = 6 different values: m&y, f&y, m&a, f&a, m&e and f&e.
By default, Active OLAP will return the number of records that match the category definitions (using
COUNT(DISTINCT id)). It is possible to “summarize” the results of a set of records using other SQL aggregate functions as well, for example using
SUM(amount) to get the total amount in a category. These summarizing functions are called aggregates in Active OLAP. It is possible to use multiple aggregates in a single OLAP query at the same time.
To install the gem on your system, run:
gem install active_olap -s http://gemcutter.org
Alternatively, you can include them gem into your Rails project by adding it to
the configuration in your
gem.config 'active_olap', :source => 'http://gemcutter.org'
Using Active OLAP for your model basically consists of the following steps:
Active OLAP comes with several helper modules to make it as easy as possible to include Active OLAP functionality to your Rails application:
gchartrbgem is required for accessing the Google Chart API. The gchartrb gem will be loaded automatically when you include this module.
If you want to use any of these helper modules, include them in your controller as a helper:
class OlapController < ActionController::Base helper ActiveRecord::Olap::TableHelper end