Rubiks
Rubiks is a Online Analytical Processing ( OLAP ) library written in JRuby. It runs on top of Mondrian (an Open-source OLAP server written in Java) and provides the ability to:
- define a OLAP schema in Ruby
- generate a Mondrian XML schema from this definition
- execute MultiDimensional eXpressions ( MDX ) queries against the OLAP server
Assumptions
- You are using JRuby
- You are using PostgreSQL
- You have designed and populated your Data Warehouse (see Dimensional Modeling and Star Schema)
- You are using Ruby on Rails database naming conventions
Installation
Run gem install rubiks
to install the gem on its own.
Or you can add the following to your Gemfile and run the bundle
command to install it.
gem 'rubiks'
Schema Example
After installing the gem, fire up an IRB session with irb
or bundle exec irb
if you are using Bundler, and follow this (or even paste it into your session):
require 'rubiks'
schema = ::Rubiks::Schema.define :banking do
cube :transactions do
dimension :date, :type => 'TimeDimension' do
hierarchy :yqmwd, :caption => 'YQMWD' do
level :year, :level_type => 'TimeYears', :type => :numeric, :contiguous => true
level :quarter, :level_type => 'TimeQuarters', :type => :numeric, :contiguous => true, :cardinality => :low
level :month, :level_type => 'TimeMonths', :type => :numeric, :contiguous => true
level :week, :level_type => 'TimeWeeks', :type => :numeric, :column => :week_of_month, :contiguous => true, :cardinality => :low
level :day, :level_type => 'TimeDays', :type => :numeric, :contiguous => true
end
end
dimension :account do
hierarchy :account_type do
level :asset_liability, :cardinality => :low
level :account_type
end
end
measure :count, :column => :quantity
measure :amount, :aggregator => :sum, :format_string => '$#,###'
end
end
puts schema.to_xml
You should see this XML:
<?xml version="1.0" encoding="UTF-8"?>
<schema name="Banking">
<cube name="Transactions">
<table name="view_transactions"/>
<dimension name="Date" foreignKey="date_id" type="TimeDimension">
<hierarchy name="YQMWD" hasAll="true" primaryKey="id">
<table name="view_dates"/>
<level name="Year" column="year" levelType="TimeYears" type="Numeric"/>
<level name="Quarter" column="quarter" levelType="TimeQuarters" type="Numeric"/>
<level name="Month" column="month" levelType="TimeMonths" type="Numeric"/>
<level name="Week" column="week_of_month" levelType="TimeWeeks" type="Numeric"/>
<level name="Day" column="day" levelType="TimeDays" type="Numeric"/>
</hierarchy>
</dimension>
<dimension name="Account" foreignKey="account_id">
<hierarchy name="Account Type" hasAll="true" primaryKey="id">
<table name="view_accounts"/>
<level name="Asset Liability" column="asset_liability"/>
<level name="Account Type" column="account_type"/>
</hierarchy>
</dimension>
<measure name="Count" column="quantity" aggregator="count"/>
<measure name="Amount" column="amount" aggregator="sum" formatString="$#,###"/>
</cube>
</schema>
Similar projects
Check out these projects (which have been super helpful in working on Rubiks):
- Mondrian (git) - source code for Mondrian on GitHub
- mondrian-olap - a RubyGem wrapping Mondrian
- Saiku (Saiku on GitHub) - a modular open-source analysis suite offering lightweight OLAP which remains easily embeddable, extendable and configurable.
Contributing
If you'd like to contribute to Rubiks, that's awesome, and we <3 you. There's a guide to contributing (both code and general help) over in CONTRIBUTING.md
Development
To see what has changed in recent versions, see the CHANGELOG.md.