mondrian-olap 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/Gemfile +15 -0
- data/LICENSE-Mondrian.html +259 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +219 -0
- data/RUNNING_TESTS.rdoc +41 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/mondrian-olap.rb +1 -0
- data/lib/mondrian/jars/commons-collections-3.1.jar +0 -0
- data/lib/mondrian/jars/commons-dbcp-1.2.1.jar +0 -0
- data/lib/mondrian/jars/commons-logging-1.0.4.jar +0 -0
- data/lib/mondrian/jars/commons-math-1.0.jar +0 -0
- data/lib/mondrian/jars/commons-pool-1.2.jar +0 -0
- data/lib/mondrian/jars/commons-vfs-1.0.jar +0 -0
- data/lib/mondrian/jars/eigenbase-properties.jar +0 -0
- data/lib/mondrian/jars/eigenbase-resgen.jar +0 -0
- data/lib/mondrian/jars/eigenbase-xom.jar +0 -0
- data/lib/mondrian/jars/javacup.jar +0 -0
- data/lib/mondrian/jars/log4j-1.2.8.jar +0 -0
- data/lib/mondrian/jars/log4j.properties +18 -0
- data/lib/mondrian/jars/mondrian.jar +0 -0
- data/lib/mondrian/jars/olap4j.jar +0 -0
- data/lib/mondrian/olap.rb +14 -0
- data/lib/mondrian/olap/connection.rb +122 -0
- data/lib/mondrian/olap/cube.rb +236 -0
- data/lib/mondrian/olap/query.rb +313 -0
- data/lib/mondrian/olap/result.rb +155 -0
- data/lib/mondrian/olap/schema.rb +158 -0
- data/lib/mondrian/olap/schema_element.rb +123 -0
- data/mondrian-olap.gemspec +116 -0
- data/spec/connection_spec.rb +56 -0
- data/spec/cube_spec.rb +259 -0
- data/spec/fixtures/MondrianTest.xml +128 -0
- data/spec/fixtures/MondrianTestOracle.xml +128 -0
- data/spec/query_spec.rb +582 -0
- data/spec/rake_tasks.rb +185 -0
- data/spec/schema_definition_spec.rb +345 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/matchers/be_like.rb +24 -0
- metadata +217 -0
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'nokogiri', '~> 1.5.0.beta.4'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'jruby-openssl'
|
7
|
+
gem 'jeweler', '~> 1.5.2'
|
8
|
+
gem 'rspec', '~> 2.5'
|
9
|
+
gem 'autotest'
|
10
|
+
gem 'jdbc-mysql'
|
11
|
+
gem 'jdbc-postgres'
|
12
|
+
gem 'activerecord', '~> 3.0.5'
|
13
|
+
gem 'activerecord-jdbc-adapter'
|
14
|
+
gem 'activerecord-oracle_enhanced-adapter', :require => false
|
15
|
+
end
|
@@ -0,0 +1,259 @@
|
|
1
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
8
|
+
<title>Eclipse Public License - Version 1.0</title>
|
9
|
+
<style type="text/css">
|
10
|
+
body {
|
11
|
+
size: 8.5in 11.0in;
|
12
|
+
margin: 0.25in 0.5in 0.25in 0.5in;
|
13
|
+
tab-interval: 0.5in;
|
14
|
+
}
|
15
|
+
p {
|
16
|
+
margin-left: auto;
|
17
|
+
margin-top: 0.5em;
|
18
|
+
margin-bottom: 0.5em;
|
19
|
+
}
|
20
|
+
p.list {
|
21
|
+
margin-left: 0.5in;
|
22
|
+
margin-top: 0.05em;
|
23
|
+
margin-bottom: 0.05em;
|
24
|
+
}
|
25
|
+
</style>
|
26
|
+
|
27
|
+
</head><body lang="EN-US">
|
28
|
+
|
29
|
+
<h2>Eclipse Public License - v 1.0</h2>
|
30
|
+
|
31
|
+
<p>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
|
32
|
+
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
|
33
|
+
DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
|
34
|
+
AGREEMENT.</p>
|
35
|
+
|
36
|
+
<p><b>1. DEFINITIONS</b></p>
|
37
|
+
|
38
|
+
<p>"Contribution" means:</p>
|
39
|
+
|
40
|
+
<p class="list">a) in the case of the initial Contributor, the initial
|
41
|
+
code and documentation distributed under this Agreement, and</p>
|
42
|
+
<p class="list">b) in the case of each subsequent Contributor:</p>
|
43
|
+
<p class="list">i) changes to the Program, and</p>
|
44
|
+
<p class="list">ii) additions to the Program;</p>
|
45
|
+
<p class="list">where such changes and/or additions to the Program
|
46
|
+
originate from and are distributed by that particular Contributor. A
|
47
|
+
Contribution 'originates' from a Contributor if it was added to the
|
48
|
+
Program by such Contributor itself or anyone acting on such
|
49
|
+
Contributor's behalf. Contributions do not include additions to the
|
50
|
+
Program which: (i) are separate modules of software distributed in
|
51
|
+
conjunction with the Program under their own license agreement, and (ii)
|
52
|
+
are not derivative works of the Program.</p>
|
53
|
+
|
54
|
+
<p>"Contributor" means any person or entity that distributes
|
55
|
+
the Program.</p>
|
56
|
+
|
57
|
+
<p>"Licensed Patents" mean patent claims licensable by a
|
58
|
+
Contributor which are necessarily infringed by the use or sale of its
|
59
|
+
Contribution alone or when combined with the Program.</p>
|
60
|
+
|
61
|
+
<p>"Program" means the Contributions distributed in accordance
|
62
|
+
with this Agreement.</p>
|
63
|
+
|
64
|
+
<p>"Recipient" means anyone who receives the Program under
|
65
|
+
this Agreement, including all Contributors.</p>
|
66
|
+
|
67
|
+
<p><b>2. GRANT OF RIGHTS</b></p>
|
68
|
+
|
69
|
+
<p class="list">a) Subject to the terms of this Agreement, each
|
70
|
+
Contributor hereby grants Recipient a non-exclusive, worldwide,
|
71
|
+
royalty-free copyright license to reproduce, prepare derivative works
|
72
|
+
of, publicly display, publicly perform, distribute and sublicense the
|
73
|
+
Contribution of such Contributor, if any, and such derivative works, in
|
74
|
+
source code and object code form.</p>
|
75
|
+
|
76
|
+
<p class="list">b) Subject to the terms of this Agreement, each
|
77
|
+
Contributor hereby grants Recipient a non-exclusive, worldwide,
|
78
|
+
royalty-free patent license under Licensed Patents to make, use, sell,
|
79
|
+
offer to sell, import and otherwise transfer the Contribution of such
|
80
|
+
Contributor, if any, in source code and object code form. This patent
|
81
|
+
license shall apply to the combination of the Contribution and the
|
82
|
+
Program if, at the time the Contribution is added by the Contributor,
|
83
|
+
such addition of the Contribution causes such combination to be covered
|
84
|
+
by the Licensed Patents. The patent license shall not apply to any other
|
85
|
+
combinations which include the Contribution. No hardware per se is
|
86
|
+
licensed hereunder.</p>
|
87
|
+
|
88
|
+
<p class="list">c) Recipient understands that although each Contributor
|
89
|
+
grants the licenses to its Contributions set forth herein, no assurances
|
90
|
+
are provided by any Contributor that the Program does not infringe the
|
91
|
+
patent or other intellectual property rights of any other entity. Each
|
92
|
+
Contributor disclaims any liability to Recipient for claims brought by
|
93
|
+
any other entity based on infringement of intellectual property rights
|
94
|
+
or otherwise. As a condition to exercising the rights and licenses
|
95
|
+
granted hereunder, each Recipient hereby assumes sole responsibility to
|
96
|
+
secure any other intellectual property rights needed, if any. For
|
97
|
+
example, if a third party patent license is required to allow Recipient
|
98
|
+
to distribute the Program, it is Recipient's responsibility to acquire
|
99
|
+
that license before distributing the Program.</p>
|
100
|
+
|
101
|
+
<p class="list">d) Each Contributor represents that to its knowledge it
|
102
|
+
has sufficient copyright rights in its Contribution, if any, to grant
|
103
|
+
the copyright license set forth in this Agreement.</p>
|
104
|
+
|
105
|
+
<p><b>3. REQUIREMENTS</b></p>
|
106
|
+
|
107
|
+
<p>A Contributor may choose to distribute the Program in object code
|
108
|
+
form under its own license agreement, provided that:</p>
|
109
|
+
|
110
|
+
<p class="list">a) it complies with the terms and conditions of this
|
111
|
+
Agreement; and</p>
|
112
|
+
|
113
|
+
<p class="list">b) its license agreement:</p>
|
114
|
+
|
115
|
+
<p class="list">i) effectively disclaims on behalf of all Contributors
|
116
|
+
all warranties and conditions, express and implied, including warranties
|
117
|
+
or conditions of title and non-infringement, and implied warranties or
|
118
|
+
conditions of merchantability and fitness for a particular purpose;</p>
|
119
|
+
|
120
|
+
<p class="list">ii) effectively excludes on behalf of all Contributors
|
121
|
+
all liability for damages, including direct, indirect, special,
|
122
|
+
incidental and consequential damages, such as lost profits;</p>
|
123
|
+
|
124
|
+
<p class="list">iii) states that any provisions which differ from this
|
125
|
+
Agreement are offered by that Contributor alone and not by any other
|
126
|
+
party; and</p>
|
127
|
+
|
128
|
+
<p class="list">iv) states that source code for the Program is available
|
129
|
+
from such Contributor, and informs licensees how to obtain it in a
|
130
|
+
reasonable manner on or through a medium customarily used for software
|
131
|
+
exchange.</p>
|
132
|
+
|
133
|
+
<p>When the Program is made available in source code form:</p>
|
134
|
+
|
135
|
+
<p class="list">a) it must be made available under this Agreement; and</p>
|
136
|
+
|
137
|
+
<p class="list">b) a copy of this Agreement must be included with each
|
138
|
+
copy of the Program.</p>
|
139
|
+
|
140
|
+
<p>Contributors may not remove or alter any copyright notices contained
|
141
|
+
within the Program.</p>
|
142
|
+
|
143
|
+
<p>Each Contributor must identify itself as the originator of its
|
144
|
+
Contribution, if any, in a manner that reasonably allows subsequent
|
145
|
+
Recipients to identify the originator of the Contribution.</p>
|
146
|
+
|
147
|
+
<p><b>4. COMMERCIAL DISTRIBUTION</b></p>
|
148
|
+
|
149
|
+
<p>Commercial distributors of software may accept certain
|
150
|
+
responsibilities with respect to end users, business partners and the
|
151
|
+
like. While this license is intended to facilitate the commercial use of
|
152
|
+
the Program, the Contributor who includes the Program in a commercial
|
153
|
+
product offering should do so in a manner which does not create
|
154
|
+
potential liability for other Contributors. Therefore, if a Contributor
|
155
|
+
includes the Program in a commercial product offering, such Contributor
|
156
|
+
("Commercial Contributor") hereby agrees to defend and
|
157
|
+
indemnify every other Contributor ("Indemnified Contributor")
|
158
|
+
against any losses, damages and costs (collectively "Losses")
|
159
|
+
arising from claims, lawsuits and other legal actions brought by a third
|
160
|
+
party against the Indemnified Contributor to the extent caused by the
|
161
|
+
acts or omissions of such Commercial Contributor in connection with its
|
162
|
+
distribution of the Program in a commercial product offering. The
|
163
|
+
obligations in this section do not apply to any claims or Losses
|
164
|
+
relating to any actual or alleged intellectual property infringement. In
|
165
|
+
order to qualify, an Indemnified Contributor must: a) promptly notify
|
166
|
+
the Commercial Contributor in writing of such claim, and b) allow the
|
167
|
+
Commercial Contributor to control, and cooperate with the Commercial
|
168
|
+
Contributor in, the defense and any related settlement negotiations. The
|
169
|
+
Indemnified Contributor may participate in any such claim at its own
|
170
|
+
expense.</p>
|
171
|
+
|
172
|
+
<p>For example, a Contributor might include the Program in a commercial
|
173
|
+
product offering, Product X. That Contributor is then a Commercial
|
174
|
+
Contributor. If that Commercial Contributor then makes performance
|
175
|
+
claims, or offers warranties related to Product X, those performance
|
176
|
+
claims and warranties are such Commercial Contributor's responsibility
|
177
|
+
alone. Under this section, the Commercial Contributor would have to
|
178
|
+
defend claims against the other Contributors related to those
|
179
|
+
performance claims and warranties, and if a court requires any other
|
180
|
+
Contributor to pay any damages as a result, the Commercial Contributor
|
181
|
+
must pay those damages.</p>
|
182
|
+
|
183
|
+
<p><b>5. NO WARRANTY</b></p>
|
184
|
+
|
185
|
+
<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
|
186
|
+
PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
|
187
|
+
OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
|
188
|
+
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
|
189
|
+
OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
|
190
|
+
responsible for determining the appropriateness of using and
|
191
|
+
distributing the Program and assumes all risks associated with its
|
192
|
+
exercise of rights under this Agreement , including but not limited to
|
193
|
+
the risks and costs of program errors, compliance with applicable laws,
|
194
|
+
damage to or loss of data, programs or equipment, and unavailability or
|
195
|
+
interruption of operations.</p>
|
196
|
+
|
197
|
+
<p><b>6. DISCLAIMER OF LIABILITY</b></p>
|
198
|
+
|
199
|
+
<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
|
200
|
+
NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
|
201
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
|
202
|
+
WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
|
203
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
204
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
|
205
|
+
DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
|
206
|
+
HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p>
|
207
|
+
|
208
|
+
<p><b>7. GENERAL</b></p>
|
209
|
+
|
210
|
+
<p>If any provision of this Agreement is invalid or unenforceable under
|
211
|
+
applicable law, it shall not affect the validity or enforceability of
|
212
|
+
the remainder of the terms of this Agreement, and without further action
|
213
|
+
by the parties hereto, such provision shall be reformed to the minimum
|
214
|
+
extent necessary to make such provision valid and enforceable.</p>
|
215
|
+
|
216
|
+
<p>If Recipient institutes patent litigation against any entity
|
217
|
+
(including a cross-claim or counterclaim in a lawsuit) alleging that the
|
218
|
+
Program itself (excluding combinations of the Program with other
|
219
|
+
software or hardware) infringes such Recipient's patent(s), then such
|
220
|
+
Recipient's rights granted under Section 2(b) shall terminate as of the
|
221
|
+
date such litigation is filed.</p>
|
222
|
+
|
223
|
+
<p>All Recipient's rights under this Agreement shall terminate if it
|
224
|
+
fails to comply with any of the material terms or conditions of this
|
225
|
+
Agreement and does not cure such failure in a reasonable period of time
|
226
|
+
after becoming aware of such noncompliance. If all Recipient's rights
|
227
|
+
under this Agreement terminate, Recipient agrees to cease use and
|
228
|
+
distribution of the Program as soon as reasonably practicable. However,
|
229
|
+
Recipient's obligations under this Agreement and any licenses granted by
|
230
|
+
Recipient relating to the Program shall continue and survive.</p>
|
231
|
+
|
232
|
+
<p>Everyone is permitted to copy and distribute copies of this
|
233
|
+
Agreement, but in order to avoid inconsistency the Agreement is
|
234
|
+
copyrighted and may only be modified in the following manner. The
|
235
|
+
Agreement Steward reserves the right to publish new versions (including
|
236
|
+
revisions) of this Agreement from time to time. No one other than the
|
237
|
+
Agreement Steward has the right to modify this Agreement. The Eclipse
|
238
|
+
Foundation is the initial Agreement Steward. The Eclipse Foundation may
|
239
|
+
assign the responsibility to serve as the Agreement Steward to a
|
240
|
+
suitable separate entity. Each new version of the Agreement will be
|
241
|
+
given a distinguishing version number. The Program (including
|
242
|
+
Contributions) may always be distributed subject to the version of the
|
243
|
+
Agreement under which it was received. In addition, after a new version
|
244
|
+
of the Agreement is published, Contributor may elect to distribute the
|
245
|
+
Program (including its Contributions) under the new version. Except as
|
246
|
+
expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
|
247
|
+
rights or licenses to the intellectual property of any Contributor under
|
248
|
+
this Agreement, whether expressly, by implication, estoppel or
|
249
|
+
otherwise. All rights in the Program not expressly granted under this
|
250
|
+
Agreement are reserved.</p>
|
251
|
+
|
252
|
+
<p>This Agreement is governed by the laws of the State of New York and
|
253
|
+
the intellectual property laws of the United States of America. No party
|
254
|
+
to this Agreement will bring a legal action under this Agreement more
|
255
|
+
than one year after the cause of action arose. Each party waives its
|
256
|
+
rights to a jury trial in any resulting litigation.</p>
|
257
|
+
|
258
|
+
</body></html>
|
259
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2010 Raimonds Simanovskis
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
= mondrian-olap
|
2
|
+
|
3
|
+
JRuby gem for performing multidimensional queries of relational database data using Mondrian OLAP Java library.
|
4
|
+
|
5
|
+
== DESCRIPTION
|
6
|
+
|
7
|
+
SQL language is good for doing ad-hoc queries from relational databases but it becomes very complicated when doing more complex analytical queries to get summary results. Alternative approach is OLAP (On-Line Analytical Processing) databases and engines that provide easier multidimensional analysis of data at different summary levels.
|
8
|
+
|
9
|
+
One of the most popular open-source OLAP engines is Mondrian (http://mondrian.pentaho.com). Mondrian OLAP engine can be put in front of relational SQL database and it provides MDX multidimensional query language which is much more suited for analytical purposes.
|
10
|
+
|
11
|
+
mondrian-olap is JRuby gem which includes Mondrian OLAP engine and provides Ruby DSL for creating OLAP schemas on top of relational database schemas and provides MDX query language and query builder Ruby methods for making analytical queries.
|
12
|
+
|
13
|
+
== USAGE
|
14
|
+
|
15
|
+
=== Schema definition
|
16
|
+
|
17
|
+
At first you need to define OLAP schema mapping to relational database schema tables and columns. OLAP schema consists of:
|
18
|
+
|
19
|
+
* Cubes
|
20
|
+
|
21
|
+
Multidimensional cube is a collection of measures that can be accessed by dimensions. In relational database cubes are stored in fact tables with measure columns and dimension foreign key columns.
|
22
|
+
|
23
|
+
* Dimensions
|
24
|
+
|
25
|
+
Dimension can be used in one cube (private) or in many cubes (shared). In relational database dimensions are stored in dimension tables.
|
26
|
+
|
27
|
+
* Hierarchies and levels
|
28
|
+
|
29
|
+
Dimension has at least one primary hierarchy and optional additional hierarchies and each hierarchy has one or more levels. In relational database all levels can be stored in the same dimension table as different columns or can be stored also in several tables.
|
30
|
+
|
31
|
+
* Members
|
32
|
+
|
33
|
+
Dimension hierarchy level values are called members.
|
34
|
+
|
35
|
+
* Measures
|
36
|
+
|
37
|
+
Measures are values which can be accessed at detailed level or aggregated (e.g. as sum or average) at higher dimension hierarchy levels. In relational database measures are stored as columns in cube table.
|
38
|
+
|
39
|
+
* Calculated measures
|
40
|
+
|
41
|
+
Calculated measures are not stored in database but calculated using specified formula from other measures.
|
42
|
+
|
43
|
+
Read more about about defining Mondrian OLAP schema at http://mondrian.pentaho.com/documentation/schema.php.
|
44
|
+
|
45
|
+
Here is example how to define OLAP schema and its mapping to relational database tables and columns using mondrian-olap:
|
46
|
+
|
47
|
+
require "rubygems"
|
48
|
+
require "mondrian-olap"
|
49
|
+
|
50
|
+
schema = Mondrian::OLAP::Schema.define do
|
51
|
+
cube 'Sales' do
|
52
|
+
table 'sales'
|
53
|
+
dimension 'Customers', :foreign_key => 'customer_id' do
|
54
|
+
hierarchy :has_all => true, :all_member_name => 'All Customers', :primary_key => 'id' do
|
55
|
+
table 'customers'
|
56
|
+
level 'Country', :column => 'country', :unique_members => true
|
57
|
+
level 'State Province', :column => 'state_province', :unique_members => true
|
58
|
+
level 'City', :column => 'city', :unique_members => false
|
59
|
+
level 'Name', :column => 'fullname', :unique_members => true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
dimension 'Products', :foreign_key => 'product_id' do
|
63
|
+
hierarchy :has_all => true, :all_member_name => 'All Products',
|
64
|
+
:primary_key => 'id', :primary_key_table => 'products' do
|
65
|
+
join :left_key => 'product_class_id', :right_key => 'id' do
|
66
|
+
table 'products'
|
67
|
+
table 'product_classes'
|
68
|
+
end
|
69
|
+
level 'Product Family', :table => 'product_classes', :column => 'product_family', :unique_members => true
|
70
|
+
level 'Brand Name', :table => 'products', :column => 'brand_name', :unique_members => false
|
71
|
+
level 'Product Name', :table => 'products', :column => 'product_name', :unique_members => true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
dimension 'Time', :foreign_key => 'time_id', :type => 'TimeDimension' do
|
75
|
+
hierarchy :has_all => false, :primary_key => 'id' do
|
76
|
+
table 'time'
|
77
|
+
level 'Year', :column => 'the_year', :type => 'Numeric', :unique_members => true, :level_type => 'TimeYears'
|
78
|
+
level 'Quarter', :column => 'quarter', :unique_members => false, :level_type => 'TimeQuarters'
|
79
|
+
level 'Month', :column => 'month_of_year', :type => 'Numeric', :unique_members => false, :level_type => 'TimeMonths'
|
80
|
+
end
|
81
|
+
hierarchy 'Weekly', :has_all => false, :primary_key => 'id' do
|
82
|
+
table 'time'
|
83
|
+
level 'Year', :column => 'the_year', :type => 'Numeric', :unique_members => true, :level_type => 'TimeYears'
|
84
|
+
level 'Week', :column => 'weak_of_year', :type => 'Numeric', :unique_members => false, :level_type => 'TimeWeeks'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
measure 'Unit Sales', :column => 'unit_sales', :aggregator => 'sum'
|
88
|
+
measure 'Store Sales', :column => 'store_sales', :aggregator => 'sum'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
=== Connection creation
|
93
|
+
|
94
|
+
When schema is defined it is necessary to establish OLAP connection to database. Here is example how to connect to MySQL database using the schema object that was defined previously:
|
95
|
+
|
96
|
+
require "jdbc/mysql"
|
97
|
+
|
98
|
+
olap = Mondrian::OLAP::Connection.create(
|
99
|
+
:driver => 'mysql',
|
100
|
+
:host => 'localhost,
|
101
|
+
:database => 'mondrian_test',
|
102
|
+
:username => 'mondrian_user',
|
103
|
+
:password => 'secret'
|
104
|
+
:schema => schema
|
105
|
+
)
|
106
|
+
|
107
|
+
=== MDX queries
|
108
|
+
|
109
|
+
Mondrian OLAP provides MDX query language. Read more about MDX at http://mondrian.pentaho.com/documentation/mdx.php.
|
110
|
+
mondrian-olap allows executing of MDX queries, for example query for "Get sales amount and number of units (on columns) of all product families (on rows) sold in California during Q1 of 2010":
|
111
|
+
|
112
|
+
result = olap.execute <<-MDX
|
113
|
+
SELECT {[Measures].[Unit Sales], [Measures].[Store Sales]} ON COLUMNS,
|
114
|
+
{[Product].children} ON ROWS
|
115
|
+
FROM [Sales]
|
116
|
+
WHERE ([Time].[2010].[Q1], [Customers].[USA].[CA])
|
117
|
+
MDX
|
118
|
+
|
119
|
+
which would correspond to the following SQL query:
|
120
|
+
|
121
|
+
SELECT SUM(unit_sales) unit_sales_sum, SUM(store_sales) store_sales_sum
|
122
|
+
FROM sales
|
123
|
+
LEFT JOIN products ON sales.product_id = products.id
|
124
|
+
LEFT JOIN product_classes ON products.product_class_id = product_classes.id
|
125
|
+
LEFT JOIN time ON sales.time_id = time.id
|
126
|
+
LEFT JOIN customers ON sales.customer_id = customers.id
|
127
|
+
WHERE time.the_year = 2010 AND time.quarter = 'Q1'
|
128
|
+
AND customers.country = 'USA' AND customers.state_province = 'CA'
|
129
|
+
GROUP BY product_classes.product_family
|
130
|
+
ORDER BY product_classes.product_family
|
131
|
+
|
132
|
+
and then get axis and cells of result object:
|
133
|
+
|
134
|
+
result.axes_count # => 2
|
135
|
+
result.column_names # => ["Unit Sales", "Store Sales"]
|
136
|
+
result.column_full_names # => ["[Measures].[Unit Sales]", "[Measures].[Store Sales]"]
|
137
|
+
result.row_names # => e.g. ["Drink", "Food", "Non-Consumable"]
|
138
|
+
result.row_full_names # => e.g. ["[Product].[Drink]", "[Product].[Food]", "[Product].[Non-Consumable]"]
|
139
|
+
result.values # => [[..., ...], [..., ...], [..., ...]]
|
140
|
+
# (three rows, each row containing value for "unit sales" and "store sales")
|
141
|
+
|
142
|
+
=== Query builder methods
|
143
|
+
|
144
|
+
MDX queries could be built and executed also using Ruby methods in a similar way as ActiveRecord/Arel queries are made.
|
145
|
+
Previous MDX query can be executed as:
|
146
|
+
|
147
|
+
olap.from('Sales').
|
148
|
+
columns('[Measures].[Unit Sales]', '[Measures].[Store Sales]').
|
149
|
+
rows('[Product].children').
|
150
|
+
where('[Time].[2010].[Q1]', '[Customers].[USA].[CA]')
|
151
|
+
|
152
|
+
Here is example of more complex query "Get sales amount and profit % of top 50 products cross-joined with USA and Canada country sales during Q1 of 2010":
|
153
|
+
|
154
|
+
olap.from('Sales').
|
155
|
+
with_member('[Measures].[ProfitPct]').
|
156
|
+
as('Val((Measures.[Store Sales] - Measures.[Store Cost]) / Measures.[Store Sales])',
|
157
|
+
:format_string => 'Percent').
|
158
|
+
columns('[Measures].[Store Sales]', '[Measures].[ProfitPct]').
|
159
|
+
rows('[Product].children').crossjoin('[Customers].[Canada]', '[Customers].[USA]').
|
160
|
+
top_count(50, '[Measures].[Store Sales]')
|
161
|
+
where('[Time].[2010].[Q1]')
|
162
|
+
|
163
|
+
See more examples of queries in spec/query_spec.rb.
|
164
|
+
|
165
|
+
Currently there are query builder methods just for most frequently used MDX functions, there will be new query builder methods in next releases of mondrian-olap gem.
|
166
|
+
|
167
|
+
=== Cube dimension and member queries
|
168
|
+
|
169
|
+
mondrian-olap provides also methods for querying dimensions and members:
|
170
|
+
|
171
|
+
cube = olap.cube('Sales')
|
172
|
+
cube.dimension_names # => ['Measures', 'Customers', 'Products', 'Time']
|
173
|
+
cube.dimensions # => array of dimension objects
|
174
|
+
cube.dimension('Customers') # => customers dimension object
|
175
|
+
cube.dimension('Time').hierarchy_names # => ['Time', 'Time.Weekly']
|
176
|
+
cube.dimension('Time').hierarchies # => array of hierarchy objects
|
177
|
+
cube.dimension('Customers').hierarchy # => default customers dimension hierarchy
|
178
|
+
cube.dimension('Customers').hierarchy.level_names
|
179
|
+
# => ['(All)', 'Country', 'State Province', 'City', 'Name']
|
180
|
+
cube.dimension('Customers').hierarchy.levels
|
181
|
+
# => array of hierarchy level objects
|
182
|
+
cube.dimension('Customers').hierarchy.level('Country').members
|
183
|
+
# => array of all level members
|
184
|
+
cube.member('[Customers].[USA].[CA]') # => lookup member by full name
|
185
|
+
cube.member('[Customers].[USA].[CA]').children
|
186
|
+
# => get all children of member in deeper hierarchy level
|
187
|
+
cube.member('[Customers].[USA]').descendants_at_level('City')
|
188
|
+
# => get all descendants of member in specified hierarchy level
|
189
|
+
|
190
|
+
See more examples of dimension and member queries in spec/cube_spec.rb.
|
191
|
+
|
192
|
+
== REQUIREMENTS
|
193
|
+
|
194
|
+
mondrian-olap gem is compatible with JRuby versions 1.5 and 1.6 (have not been tested with earlier versions). mondrian-olap works only with JRuby and not with other Ruby implementations as it includes Mondrian OLAP Java libraries.
|
195
|
+
|
196
|
+
mondrian-olap currently supports MySQL, PostgreSQL and Oracle databases. When using MySQL or PostgreSQL databases then install jdbc-mysql or jdbc-postgres gem and require "jdbc/mysql" or "jdbc/postgres" to load corresponding JDBC database driver. When using Oracle then include Oracle JDBC driver (ojdbc14.jar or ojdbc6.jar) in CLASSPATH or copy to JRUBY_HOME/lib.
|
197
|
+
|
198
|
+
== INSTALL
|
199
|
+
|
200
|
+
Install gem with:
|
201
|
+
|
202
|
+
gem install mondrian-olap
|
203
|
+
|
204
|
+
or include in your project's Gemfile:
|
205
|
+
|
206
|
+
gem "mondrian-olap"
|
207
|
+
|
208
|
+
== LINKS
|
209
|
+
|
210
|
+
* Source code: http://github.com/rsim/mondrian-olap
|
211
|
+
* Bug reports / Feature requests: http://github.com/rsim/mondrian-olap/issues
|
212
|
+
* General discussions and questions at: http://groups.google.com/group/mondrian-olap
|
213
|
+
|
214
|
+
== LICENSE
|
215
|
+
|
216
|
+
mondrian-olap is released under the terms of MIT license; see LICENSE.txt.
|
217
|
+
|
218
|
+
Mondrian OLAP Engine is released under the terms of the Eclipse Public
|
219
|
+
License v1.0 (EPL); see LICENSE-Mondrian.html.
|