mondrian-olap 0.4.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.rspec +2 -0
  2. data/Changelog.md +60 -0
  3. data/Gemfile +21 -0
  4. data/LICENSE-Mondrian.html +259 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +302 -0
  7. data/RUNNING_TESTS.rdoc +66 -0
  8. data/Rakefile +48 -0
  9. data/VERSION +1 -0
  10. data/lib/mondrian-olap.rb +1 -0
  11. data/lib/mondrian/jars/commons-collections-3.1.jar +0 -0
  12. data/lib/mondrian/jars/commons-dbcp-1.2.1.jar +0 -0
  13. data/lib/mondrian/jars/commons-logging-1.0.4.jar +0 -0
  14. data/lib/mondrian/jars/commons-math-1.0.jar +0 -0
  15. data/lib/mondrian/jars/commons-pool-1.2.jar +0 -0
  16. data/lib/mondrian/jars/commons-vfs-1.0.jar +0 -0
  17. data/lib/mondrian/jars/eigenbase-properties.jar +0 -0
  18. data/lib/mondrian/jars/eigenbase-resgen.jar +0 -0
  19. data/lib/mondrian/jars/eigenbase-xom.jar +0 -0
  20. data/lib/mondrian/jars/javacup.jar +0 -0
  21. data/lib/mondrian/jars/log4j-1.2.8.jar +0 -0
  22. data/lib/mondrian/jars/log4j.properties +5 -0
  23. data/lib/mondrian/jars/mondrian.jar +0 -0
  24. data/lib/mondrian/jars/olap4j.jar +0 -0
  25. data/lib/mondrian/olap.rb +17 -0
  26. data/lib/mondrian/olap/connection.rb +201 -0
  27. data/lib/mondrian/olap/cube.rb +297 -0
  28. data/lib/mondrian/olap/error.rb +57 -0
  29. data/lib/mondrian/olap/query.rb +342 -0
  30. data/lib/mondrian/olap/result.rb +264 -0
  31. data/lib/mondrian/olap/schema.rb +378 -0
  32. data/lib/mondrian/olap/schema_element.rb +153 -0
  33. data/lib/mondrian/olap/schema_udf.rb +282 -0
  34. data/mondrian-olap.gemspec +128 -0
  35. data/spec/connection_role_spec.rb +130 -0
  36. data/spec/connection_spec.rb +72 -0
  37. data/spec/cube_spec.rb +318 -0
  38. data/spec/fixtures/MondrianTest.xml +134 -0
  39. data/spec/fixtures/MondrianTestOracle.xml +134 -0
  40. data/spec/mondrian_spec.rb +53 -0
  41. data/spec/query_spec.rb +807 -0
  42. data/spec/rake_tasks.rb +260 -0
  43. data/spec/schema_definition_spec.rb +1249 -0
  44. data/spec/spec_helper.rb +134 -0
  45. data/spec/support/matchers/be_like.rb +24 -0
  46. metadata +278 -0
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --backtrace
@@ -0,0 +1,60 @@
1
+ ### 0.4.0 / 2012-12-03
2
+
3
+ * New features
4
+ * upgraded to latest Mondrian 3.5 version (build from 2012-11-29)
5
+ as well as corresponding olap4j 1.0.1 version
6
+ * support for JRuby 1.7 and Java 7 VM
7
+ * user defined functions and formatters in JavaScript, CoffeeScript and Ruby
8
+ * shared user defined functions in Ruby
9
+ * all exceptions are wrapped in Mondrian::OLAP::Error exception with root_cause_message method
10
+ * drill through from result cell to source measure and dimension table rows
11
+ * support for Mondrian schema roles to limit cube data access
12
+ * Improvements
13
+ * get description of cube, dimension, hierarchy and level from schema definition
14
+ * visible? method for measures and calculated members
15
+ * nonempty_crossjoin query builder method
16
+ * schema definition with nested table joins
17
+ * added approx_row_count schema level attribute
18
+
19
+ ### 0.3.0 / 2011-11-12
20
+
21
+ * New features
22
+ * upgraded to Mondrian 3.3.0 version (latest shapshot with additional bug fixes)
23
+ as well as corresponding olap4j 1.0.0 version
24
+ * support for SQL Server (jTDS and Microsoft drivers)
25
+ * aggregates definition in schema
26
+ * possibility to include XML fragments in schema
27
+ (e.g. to paste XML for aggregates that is generated by Mondrian aggregation designer)
28
+ * define level properties in schema
29
+ * `sql` element for `table` element in schema
30
+ (to define custom WHERE conditions for dimensions or fact table)
31
+ * `view` element in schema
32
+ (to define custom SQL SELECT statements instead of existing table)
33
+ * `measure_expression` element in schema
34
+ (to define custom SQL expression for measure instead of fact column)
35
+ * allow crossjoin of where conditions as well as where with several same dimension members
36
+ * Improvements
37
+ * use latest Nokogiri 1.5.0 version
38
+
39
+ ### 0.2.0 / 2011-07-01
40
+
41
+ * New features
42
+ * support for LucidDB database
43
+ * Improvements
44
+ * only set log4j configuration file if not set already (possible to override e.g. Mondrian debugging settings)
45
+ * `result.to_html(:formatted=>true)` will return formatted results
46
+ * set Unicode encoding for mysql connection
47
+ * `format_string` attribute and `formula` element for calculated members
48
+ * `:use_content_checksum` connection option (by default set to true)
49
+ * `key_expression`, `name_expression`, `ordinal_expression` elements with `sql` subelement support for levels
50
+ * `:upcase_data_dictionary` option for schema definition
51
+ * Bug fixes
52
+ * fixed examples in README
53
+ * correctly quote `CatalogContent` in connection string (to allow usage of semicolons in generated XML catalog)
54
+ * workarounds for issues with Java classloader when using in production mode with jruby-rack
55
+ * construct correct file path on Windows
56
+
57
+ ### 0.1.0 / 2011-03-18
58
+
59
+ * Initial release
60
+ * support for MySQL, PostgreSQL and Oracle databases
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'nokogiri', '~> 1.5.0'
4
+
5
+ group :development do
6
+ gem 'jruby-openssl'
7
+ gem 'jeweler', '~> 1.8.3'
8
+ gem 'rdoc'
9
+ gem 'rspec', '~> 2.10'
10
+ gem 'autotest'
11
+ gem 'jdbc-mysql'
12
+ gem 'jdbc-postgres'
13
+ gem 'jdbc-luciddb'
14
+ gem 'jdbc-jtds'
15
+ gem 'activerecord', '= 3.2.8'
16
+ gem 'activerecord-jdbc-adapter', '= 1.2.2'
17
+ gem 'activerecord-oracle_enhanced-adapter', :require => false
18
+ gem 'coffee-script', '~> 2.2.0'
19
+ gem 'therubyrhino', '~> 1.73.1'
20
+ gem 'pry', :require => false
21
+ 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
+
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2010-2012 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.
@@ -0,0 +1,302 @@
1
+ mondrian-olap
2
+ =============
3
+
4
+ JRuby gem for performing multidimensional queries of relational database data using Mondrian OLAP Java library.
5
+
6
+ DESCRIPTION
7
+ -----------
8
+
9
+ 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.
10
+
11
+ 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.
12
+
13
+ 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.
14
+
15
+ mondrian-olap is used in [eazyBI data analysis and reporting web application](https://eazybi.com). [eazyBI remote setup](https://eazybi.com/help/remote-setup) can be used to create easy-to-use web based reports and dashboards on top of mondrian-olap based backend database. There is also [mondrian-olap demo Rails application for trying MDX queries](https://github.com/rsim/mondrian_demo).
16
+
17
+ USAGE
18
+ -----
19
+
20
+ ### Schema definition
21
+
22
+ At first you need to define OLAP schema mapping to relational database schema tables and columns. OLAP schema consists of:
23
+
24
+ * Cubes
25
+
26
+ 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.
27
+
28
+ * Dimensions
29
+
30
+ Dimension can be used in one cube (private) or in many cubes (shared). In relational database dimensions are stored in dimension tables.
31
+
32
+ * Hierarchies and levels
33
+
34
+ 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.
35
+
36
+ * Members
37
+
38
+ Dimension hierarchy level values are called members.
39
+
40
+ * Measures
41
+
42
+ 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.
43
+
44
+ * Calculated measures
45
+
46
+ Calculated measures are not stored in database but calculated using specified formula from other measures.
47
+
48
+ Read more about about [defining Mondrian OLAP schema](http://mondrian.pentaho.com/documentation/schema.php).
49
+
50
+ Here is example how to define OLAP schema and its mapping to relational database tables and columns using mondrian-olap:
51
+
52
+ ```ruby
53
+ require "rubygems"
54
+ require "mondrian-olap"
55
+
56
+ schema = Mondrian::OLAP::Schema.define do
57
+ cube 'Sales' do
58
+ table 'sales'
59
+ dimension 'Customers', :foreign_key => 'customer_id' do
60
+ hierarchy :has_all => true, :all_member_name => 'All Customers', :primary_key => 'id' do
61
+ table 'customers'
62
+ level 'Country', :column => 'country', :unique_members => true
63
+ level 'State Province', :column => 'state_province', :unique_members => true
64
+ level 'City', :column => 'city', :unique_members => false
65
+ level 'Name', :column => 'fullname', :unique_members => true
66
+ end
67
+ end
68
+ dimension 'Products', :foreign_key => 'product_id' do
69
+ hierarchy :has_all => true, :all_member_name => 'All Products',
70
+ :primary_key => 'id', :primary_key_table => 'products' do
71
+ join :left_key => 'product_class_id', :right_key => 'id' do
72
+ table 'products'
73
+ table 'product_classes'
74
+ end
75
+ level 'Product Family', :table => 'product_classes', :column => 'product_family', :unique_members => true
76
+ level 'Brand Name', :table => 'products', :column => 'brand_name', :unique_members => false
77
+ level 'Product Name', :table => 'products', :column => 'product_name', :unique_members => true
78
+ end
79
+ end
80
+ dimension 'Time', :foreign_key => 'time_id', :type => 'TimeDimension' do
81
+ hierarchy :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 'Quarter', :column => 'quarter', :unique_members => false, :level_type => 'TimeQuarters'
85
+ level 'Month', :column => 'month_of_year', :type => 'Numeric', :unique_members => false, :level_type => 'TimeMonths'
86
+ end
87
+ hierarchy 'Weekly', :has_all => false, :primary_key => 'id' do
88
+ table 'time'
89
+ level 'Year', :column => 'the_year', :type => 'Numeric', :unique_members => true, :level_type => 'TimeYears'
90
+ level 'Week', :column => 'week_of_year', :type => 'Numeric', :unique_members => false, :level_type => 'TimeWeeks'
91
+ end
92
+ end
93
+ measure 'Unit Sales', :column => 'unit_sales', :aggregator => 'sum'
94
+ measure 'Store Sales', :column => 'store_sales', :aggregator => 'sum'
95
+ end
96
+ end
97
+ ```
98
+
99
+ ### Connection creation
100
+
101
+ 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:
102
+
103
+ ```ruby
104
+ require "jdbc/mysql"
105
+
106
+ olap = Mondrian::OLAP::Connection.create(
107
+ :driver => 'mysql',
108
+ :host => 'localhost,
109
+ :database => 'mondrian_test',
110
+ :username => 'mondrian_user',
111
+ :password => 'secret',
112
+ :schema => schema
113
+ )
114
+ ```
115
+
116
+ ### MDX queries
117
+
118
+ Mondrian OLAP provides MDX query language. [Read more about MDX](http://mondrian.pentaho.com/documentation/mdx.php).
119
+ 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":
120
+
121
+ ```ruby
122
+ result = olap.execute <<-MDX
123
+ SELECT {[Measures].[Unit Sales], [Measures].[Store Sales]} ON COLUMNS,
124
+ {[Products].children} ON ROWS
125
+ FROM [Sales]
126
+ WHERE ([Time].[2010].[Q1], [Customers].[USA].[CA])
127
+ MDX
128
+ ```
129
+
130
+ which would correspond to the following SQL query:
131
+
132
+ SELECT SUM(unit_sales) unit_sales_sum, SUM(store_sales) store_sales_sum
133
+ FROM sales
134
+ LEFT JOIN products ON sales.product_id = products.id
135
+ LEFT JOIN product_classes ON products.product_class_id = product_classes.id
136
+ LEFT JOIN time ON sales.time_id = time.id
137
+ LEFT JOIN customers ON sales.customer_id = customers.id
138
+ WHERE time.the_year = 2010 AND time.quarter = 'Q1'
139
+ AND customers.country = 'USA' AND customers.state_province = 'CA'
140
+ GROUP BY product_classes.product_family
141
+ ORDER BY product_classes.product_family
142
+
143
+ and then get axis and cells of result object:
144
+
145
+ ```ruby
146
+ result.axes_count # => 2
147
+ result.column_names # => ["Unit Sales", "Store Sales"]
148
+ result.column_full_names # => ["[Measures].[Unit Sales]", "[Measures].[Store Sales]"]
149
+ result.row_names # => e.g. ["Drink", "Food", "Non-Consumable"]
150
+ result.row_full_names # => e.g. ["[Products].[Drink]", "[Products].[Food]", "[Products].[Non-Consumable]"]
151
+ result.values # => [[..., ...], [..., ...], [..., ...]]
152
+ # (three rows, each row containing value for "unit sales" and "store sales")
153
+ ```
154
+
155
+ ### Query builder methods
156
+
157
+ MDX queries could be built and executed also using Ruby methods in a similar way as ActiveRecord/Arel queries are made.
158
+ Previous MDX query can be executed as:
159
+
160
+ ```ruby
161
+ olap.from('Sales').
162
+ columns('[Measures].[Unit Sales]', '[Measures].[Store Sales]').
163
+ rows('[Products].children').
164
+ where('[Time].[2010].[Q1]', '[Customers].[USA].[CA]').
165
+ execute
166
+ ```
167
+
168
+ 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":
169
+
170
+ ```ruby
171
+ olap.from('Sales').
172
+ with_member('[Measures].[ProfitPct]').
173
+ as('Val((Measures.[Store Sales] - Measures.[Store Cost]) / Measures.[Store Sales])',
174
+ :format_string => 'Percent').
175
+ columns('[Measures].[Store Sales]', '[Measures].[ProfitPct]').
176
+ rows('[Products].children').crossjoin('[Customers].[Canada]', '[Customers].[USA]').
177
+ top_count(50, '[Measures].[Store Sales]').
178
+ where('[Time].[2010].[Q1]').
179
+ execute
180
+ ```
181
+
182
+ See more examples of queries in `spec/query_spec.rb`.
183
+
184
+ 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.
185
+
186
+ ### Cube dimension and member queries
187
+
188
+ mondrian-olap provides also methods for querying dimensions and members:
189
+
190
+ ```ruby
191
+ cube = olap.cube('Sales')
192
+ cube.dimension_names # => ['Measures', 'Customers', 'Products', 'Time']
193
+ cube.dimensions # => array of dimension objects
194
+ cube.dimension('Customers') # => customers dimension object
195
+ cube.dimension('Time').hierarchy_names # => ['Time', 'Time.Weekly']
196
+ cube.dimension('Time').hierarchies # => array of hierarchy objects
197
+ cube.dimension('Customers').hierarchy # => default customers dimension hierarchy
198
+ cube.dimension('Customers').hierarchy.level_names
199
+ # => ['(All)', 'Country', 'State Province', 'City', 'Name']
200
+ cube.dimension('Customers').hierarchy.levels
201
+ # => array of hierarchy level objects
202
+ cube.dimension('Customers').hierarchy.level('Country').members
203
+ # => array of all level members
204
+ cube.member('[Customers].[USA].[CA]') # => lookup member by full name
205
+ cube.member('[Customers].[USA].[CA]').children
206
+ # => get all children of member in deeper hierarchy level
207
+ cube.member('[Customers].[USA]').descendants_at_level('City')
208
+ # => get all descendants of member in specified hierarchy level
209
+ ```
210
+
211
+ See more examples of dimension and member queries in `spec/cube_spec.rb`.
212
+
213
+ ### User defined MDX functions
214
+
215
+ You can define new MDX functions using JavaScript, CoffeeScript or Ruby language that you can later use
216
+ either in calculated member formulas or in MDX queries. Here are examples of user defined functions in Ruby:
217
+
218
+ ```ruby
219
+ schema = Mondrian::OLAP::Schema.define do
220
+ # ... cube definitions ...
221
+ user_defined_function 'Factorial' do
222
+ ruby do
223
+ parameters :numeric
224
+ returns :numeric
225
+ def call(n)
226
+ n <= 1 ? 1 : n * call(n - 1)
227
+ end
228
+ end
229
+ end
230
+ user_defined_function 'UpperName' do
231
+ ruby do
232
+ parameters :member
233
+ returns :string
234
+ syntax :property
235
+ def call(member)
236
+ member.getName.upcase
237
+ end
238
+ end
239
+ end
240
+ end
241
+ ```
242
+
243
+ See more examples of user defined functions in `spec/schema_definition_spec.rb`.
244
+
245
+ ### Data access roles
246
+
247
+ In schema you can define data access roles which can be selected for connection and which will limit access just to
248
+ subset of measures and dimension members. Here is example of data access role definition:
249
+
250
+ ```ruby
251
+ schema = Mondrian::OLAP::Schema.define do
252
+ # ... cube definitions ...
253
+ role 'California manager' do
254
+ schema_grant :access => 'none' do
255
+ cube_grant :cube => 'Sales', :access => 'all' do
256
+ dimension_grant :dimension => '[Measures]', :access => 'all'
257
+ hierarchy_grant :hierarchy => '[Customers]', :access => 'custom',
258
+ :top_level => '[Customers].[State Province]', :bottom_level => '[Customers].[City]' do
259
+ member_grant :member => '[Customers].[USA].[CA]', :access => 'all'
260
+ member_grant :member => '[Customers].[USA].[CA].[Los Angeles]', :access => 'none'
261
+ end
262
+ end
263
+ end
264
+ end
265
+ end
266
+ ```
267
+
268
+ See more examples of data access roles in `spec/connection_role_spec.rb`.
269
+
270
+ REQUIREMENTS
271
+ ------------
272
+
273
+ mondrian-olap gem is compatible with JRuby versions 1.6 and 1.7 and Java 6 and 7 VM. mondrian-olap works only with JRuby and not with other Ruby implementations as it includes Mondrian OLAP Java libraries.
274
+
275
+ mondrian-olap currently supports MySQL, PostgreSQL, Oracle, LucidDB and Microsoft SQL Server databases. When using MySQL, PostgreSQL or LucidDB databases then install jdbc-mysql, jdbc-postgres or jdbc-luciddb gem and require "jdbc/mysql", "jdbc/postgres" or "jdbc/luciddb" to load the corresponding JDBC database driver. When using Oracle then include Oracle JDBC driver (`ojdbc6.jar` for Java 6) in `CLASSPATH` or copy to `JRUBY_HOME/lib` or require it in application manually. When using SQL Server you can choose between the jTDS or Microsoft JDBC drivers. If you use jTDS require "jdbc/jtds". If you use the Microsoft JDBC driver include `sqljdbc.jar` or `sqljdbc4.jar` in `CLASSPATH` or copy to `JRUBY_HOME/lib` or require it in application manually.
276
+
277
+ INSTALL
278
+ -------
279
+
280
+ Install gem with:
281
+
282
+ gem install mondrian-olap
283
+
284
+ or include in your project's Gemfile:
285
+
286
+ gem "mondrian-olap"
287
+
288
+ LINKS
289
+ -----
290
+
291
+ * Source code: http://github.com/rsim/mondrian-olap
292
+ * Bug reports / Feature requests: http://github.com/rsim/mondrian-olap/issues
293
+ * General discussions and questions at: http://groups.google.com/group/mondrian-olap
294
+ * mondrian-olap demo Rails application: https://github.com/rsim/mondrian_demo
295
+
296
+ LICENSE
297
+ -------
298
+
299
+ mondrian-olap is released under the terms of MIT license; see LICENSE.txt.
300
+
301
+ Mondrian OLAP Engine is released under the terms of the Eclipse Public
302
+ License v1.0 (EPL); see LICENSE-Mondrian.html.