mondrian-olap 0.5.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/Changelog.md +86 -0
  3. data/LICENSE-Mondrian.txt +87 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +43 -40
  6. data/VERSION +1 -1
  7. data/lib/mondrian/jars/commons-collections-3.2.2.jar +0 -0
  8. data/lib/mondrian/jars/commons-dbcp-1.4.jar +0 -0
  9. data/lib/mondrian/jars/commons-io-2.2.jar +0 -0
  10. data/lib/mondrian/jars/commons-lang-2.6.jar +0 -0
  11. data/lib/mondrian/jars/commons-logging-1.2.jar +0 -0
  12. data/lib/mondrian/jars/commons-pool-1.5.7.jar +0 -0
  13. data/lib/mondrian/jars/commons-vfs2-2.2.jar +0 -0
  14. data/lib/mondrian/jars/eigenbase-xom-1.3.5.jar +0 -0
  15. data/lib/mondrian/jars/guava-17.0.jar +0 -0
  16. data/lib/mondrian/jars/log4j-1.2.17.jar +0 -0
  17. data/lib/mondrian/jars/log4j.properties +2 -4
  18. data/lib/mondrian/jars/mondrian-9.1.0.0.jar +0 -0
  19. data/lib/mondrian/jars/olap4j-1.2.0.jar +0 -0
  20. data/lib/mondrian/olap/connection.rb +252 -67
  21. data/lib/mondrian/olap/cube.rb +63 -2
  22. data/lib/mondrian/olap/error.rb +37 -8
  23. data/lib/mondrian/olap/query.rb +41 -21
  24. data/lib/mondrian/olap/result.rb +163 -44
  25. data/lib/mondrian/olap/schema.rb +42 -3
  26. data/lib/mondrian/olap/schema_element.rb +25 -6
  27. data/lib/mondrian/olap/schema_udf.rb +21 -16
  28. data/spec/connection_role_spec.rb +69 -13
  29. data/spec/connection_spec.rb +3 -2
  30. data/spec/cube_cache_control_spec.rb +261 -0
  31. data/spec/cube_spec.rb +32 -4
  32. data/spec/fixtures/MondrianTest.xml +1 -6
  33. data/spec/fixtures/MondrianTestOracle.xml +1 -6
  34. data/spec/mondrian_spec.rb +71 -1
  35. data/spec/query_spec.rb +323 -25
  36. data/spec/rake_tasks.rb +253 -159
  37. data/spec/schema_definition_spec.rb +314 -61
  38. data/spec/spec_helper.rb +115 -45
  39. data/spec/support/data/customers.csv +10902 -0
  40. data/spec/support/data/product_classes.csv +101 -0
  41. data/spec/support/data/products.csv +101 -0
  42. data/spec/support/data/sales.csv +101 -0
  43. data/spec/support/data/time.csv +731 -0
  44. metadata +126 -124
  45. data/LICENSE-Mondrian.html +0 -259
  46. data/lib/mondrian/jars/commons-collections-3.2.jar +0 -0
  47. data/lib/mondrian/jars/commons-dbcp-1.2.1.jar +0 -0
  48. data/lib/mondrian/jars/commons-logging-1.1.1.jar +0 -0
  49. data/lib/mondrian/jars/commons-pool-1.2.jar +0 -0
  50. data/lib/mondrian/jars/commons-vfs-1.0.jar +0 -0
  51. data/lib/mondrian/jars/eigenbase-xom-1.3.1.jar +0 -0
  52. data/lib/mondrian/jars/log4j-1.2.14.jar +0 -0
  53. data/lib/mondrian/jars/mondrian.jar +0 -0
  54. data/lib/mondrian/jars/olap4j-1.0.1.539.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a82185c2c1e818166ad00f6a79629772eda89fd6
4
- data.tar.gz: 48189b91d855f7dc3df6842d91360068285be951
2
+ SHA256:
3
+ metadata.gz: e5b807f5866de6c32810049ddaa15cf62725bdd14db8c92be93828172cc4a0c6
4
+ data.tar.gz: 34eb04b5545e340509f8699ce499a447a32effee40749e1b580d6063b7d596cf
5
5
  SHA512:
6
- metadata.gz: d11c3fb9718d6a81be7f534c1b96a6cf731b64019a947a01bbfb58e3a2d52453bd334c5f083ef05981093657f66b3b4572f64748ae0aa4382f4c6a03c445aa9f
7
- data.tar.gz: 5f588afd736a0e8c62f05b5a9d56aa75fe181e46373d4025d85522532b8371a3fb439e3d000339ed70ad61d0f8c99ce37e17b9ddc693cfe44a4884ff557c375f
6
+ metadata.gz: 503b38add95142332eb40c8885075461b98bb2cbbb2f49446b213754a593b94fd2226a965e2d90383e96b163eeab180a5de999cc3631b347060e5c59323ef83b
7
+ data.tar.gz: 7a9e42bda5d2acc62ccda1da5ab63bb63ad51c49828ed08e89a83e5c4e1a2742118be320c925e7771e29e95166b2e73e26420ac5f7132c4ffb3a2e4221c8ce83
data/Changelog.md CHANGED
@@ -1,3 +1,89 @@
1
+ ### Master
2
+
3
+ ### 1.2.0 / 2021-03-06
4
+
5
+ * New features
6
+ * Upgrade to the latest Mondrian version 9.1.0.0
7
+ * Improved Vertica and Snowflake tests to use bulk data loading
8
+ * Remove support of LucidDB (which is abandoned a long time ago)
9
+ * Improve bigint key columns support
10
+ * Add MySQL 8 JDBC driver support
11
+ * Tested with JRuby 9.2.14.0
12
+ * Remove JRuby 1.7 support
13
+
14
+ ### 1.1.0 / 2019-11-09
15
+
16
+ * New features
17
+ * Upgrade to the latest Mondrian version 8.3.0.5
18
+ * Tested with JRuby 9.2.9.0
19
+ * Set query specific timeout
20
+ * Support for Vertica and Snowflake databases
21
+ * Bug fixes
22
+ * Handle and wrap TokenMgrError exception
23
+ * Patch for MONDRIAN-2660
24
+ * Patch for MONDRIAN-2661
25
+
26
+ ### 1.0.0 / 2019-03-04
27
+
28
+ * New features
29
+ * Upgrade to the latest Mondrian version 8.2.0.4
30
+ * Desupport Java 7, added support for Java 11, tested with JRuby 9.2.6.0
31
+ * Remove deprecated NativeException, Fixnum
32
+ * Added Mondrian query profiling option
33
+ * Added connection flush_schema method and flush_schema(schema_key) class method
34
+ * Added pin_schema_timeout connection parameter
35
+ * Bug fixes
36
+ * Fixed parsing of drill through queries with newlines
37
+ * Do not log Mondrian errors on the console
38
+ * Fixed handling of dimension names with escaped ]
39
+ * Patch for MONDRIAN-2641
40
+
41
+ ### 0.9.0 / 2017-10-07
42
+
43
+ * New features
44
+ * Upgraded to the latest Mondrian version 3.14.0.5
45
+ * Added an annotations_hash method for schema elements
46
+ * Bug fixes
47
+ * Fixed drill through SQL query generation
48
+ * Set a single role as a union role - used as a workaround for a Mondrian bug
49
+
50
+ ### 0.8.0 / 2016-10-26
51
+
52
+ * New features
53
+ * upgraded to the latest Mondrian version 3.12.0.6
54
+ * added flush_region_cache_with_segments and flush_region_cache_with_full_names methods for partial clearing of the cache
55
+ * added Name() and Property() extensions for drill_through return fields
56
+ * Bug fixes
57
+ * fixed retrieving of drill through results with Clob values
58
+
59
+ ### 0.7.0 / 2015-12-12
60
+
61
+ * New features
62
+ * upgraded to latest the latest Mondrian version 3.11
63
+ * removed Java 6 support
64
+ * fixes for JRuby 9.0 support
65
+ * added a query builder method "distinct"
66
+ * Improvements
67
+ * added annotations for dimension_usage and virtual_cube_dimension schema elements
68
+ * Bug fixes
69
+ * fixed the order of axis aliases - columns, rows, pages, chapters, sections
70
+
71
+
72
+ ### 0.6.0 / 2014-11-10
73
+
74
+ * New features
75
+ * upgraded to latest Mondrian 3.8.0 version
76
+ * connection with generic JDBC driver using jdbc_driver and jdbc_url parameters
77
+ * added hierarchy and parent attributes for calculated member schema definition element
78
+ * added visible attribute for cube, dimension, virtual_cube_dimension, hierarchy and level schema definition elements
79
+ * added query builder generate method
80
+ * added schema parameters and query execution with parameters
81
+ * updated specs to pass on Java 8
82
+ * Improvements
83
+ * set defaultRowPrefetch property for Oracle connection
84
+ * Bug fixes
85
+ * fixed result drill_through method with just all members selection
86
+
1
87
  ### 0.5.0 / 2013-11-29
2
88
 
3
89
  * New features
@@ -0,0 +1,87 @@
1
+ Eclipse Public License -v 1.0
2
+
3
+ THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4
+
5
+ 1. DEFINITIONS
6
+
7
+ "Contribution" means:
8
+
9
+ a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
10
+
11
+ b) in the case of each subsequent Contributor:
12
+
13
+ i) changes to the Program, and
14
+
15
+ ii) additions to the Program;
16
+
17
+ where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
18
+
19
+ "Contributor" means any person or entity that distributes the Program.
20
+
21
+ "Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
22
+
23
+ "Program" means the Contributions distributed in accordance with this Agreement.
24
+
25
+ "Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
26
+
27
+ 2. GRANT OF RIGHTS
28
+
29
+ a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
30
+
31
+ b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
32
+
33
+ c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
34
+
35
+ d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
36
+
37
+ 3. REQUIREMENTS
38
+
39
+ A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
40
+
41
+ a) it complies with the terms and conditions of this Agreement; and
42
+
43
+ b) its license agreement:
44
+
45
+ i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
46
+
47
+ ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
48
+
49
+ iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
50
+
51
+ iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
52
+
53
+ When the Program is made available in source code form:
54
+
55
+ a) it must be made available under this Agreement; and
56
+
57
+ b) a copy of this Agreement must be included with each copy of the Program.
58
+
59
+ Contributors may not remove or alter any copyright notices contained within the Program.
60
+
61
+ Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
62
+
63
+ 4. COMMERCIAL DISTRIBUTION
64
+
65
+ Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
66
+
67
+ For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
68
+
69
+ 5. NO WARRANTY
70
+
71
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
72
+
73
+ 6. DISCLAIMER OF LIABILITY
74
+
75
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
76
+
77
+ 7. GENERAL
78
+
79
+ If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
80
+
81
+ If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
82
+
83
+ All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
84
+
85
+ Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
86
+
87
+ This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2010-2013 Raimonds Simanovskis
3
+ Copyright (c) 2010-2021 Raimonds Simanovskis
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Travis CI status](https://travis-ci.org/rsim/mondrian-olap.svg?branch=master)](https://travis-ci.org/rsim/mondrian-olap)
2
+ [![AppVeyor status](https://ci.appveyor.com/api/projects/status/08xd4tyty2k3wxba/branch/master?svg=true)](https://ci.appveyor.com/project/rsim/mondrian-olap)
3
+
1
4
  mondrian-olap
2
5
  =============
3
6
 
@@ -12,7 +15,7 @@ One of the most popular open-source OLAP engines is [Mondrian](http://mondrian.p
12
15
 
13
16
  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
17
 
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).
18
+ mondrian-olap is used in [eazyBI data analysis and reporting web application](https://eazybi.com). [Private eazyBI](https://eazybi.com/help/private-eazybi) 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). The [mondrian-rest](https://github.com/jazzido/mondrian-rest) uses mondrian-olap to implement a REST API interface for a Mondrian schema.
16
19
 
17
20
  USAGE
18
21
  -----
@@ -56,42 +59,42 @@ require "mondrian-olap"
56
59
  schema = Mondrian::OLAP::Schema.define do
57
60
  cube 'Sales' do
58
61
  table 'sales'
59
- dimension 'Customers', :foreign_key => 'customer_id' do
60
- hierarchy :has_all => true, :all_member_name => 'All Customers', :primary_key => 'id' do
62
+ dimension 'Customers', foreign_key: 'customer_id' do
63
+ hierarchy has_all: true, all_member_name: 'All Customers', primary_key: 'id' do
61
64
  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
65
+ level 'Country', column: 'country', unique_members: true
66
+ level 'State Province', column: 'state_province', unique_members: true
67
+ level 'City', column: 'city', unique_members: false
68
+ level 'Name', column: 'fullname', unique_members: true
66
69
  end
67
70
  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
71
+ dimension 'Products', foreign_key: 'product_id' do
72
+ hierarchy has_all: true, all_member_name: 'All Products',
73
+ primary_key: 'id', primary_key_table: 'products' do
74
+ join left_key: 'product_class_id', right_key: 'id' do
72
75
  table 'products'
73
76
  table 'product_classes'
74
77
  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
+ level 'Product Family', table: 'product_classes', column: 'product_family', unique_members: true
79
+ level 'Brand Name', table: 'products', column: 'brand_name', unique_members: false
80
+ level 'Product Name', table: 'products', column: 'product_name', unique_members: true
78
81
  end
79
82
  end
80
- dimension 'Time', :foreign_key => 'time_id', :type => 'TimeDimension' do
81
- hierarchy :has_all => false, :primary_key => 'id' do
83
+ dimension 'Time', foreign_key: 'time_id', type: 'TimeDimension' do
84
+ hierarchy has_all: false, primary_key: 'id' do
82
85
  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
+ level 'Year', column: 'the_year', type: 'Numeric', unique_members: true, level_type: 'TimeYears'
87
+ level 'Quarter', column: 'quarter', unique_members: false, level_type: 'TimeQuarters'
88
+ level 'Month', column: 'month_of_year', type: 'Numeric', unique_members: false, level_type: 'TimeMonths'
86
89
  end
87
- hierarchy 'Weekly', :has_all => false, :primary_key => 'id' do
90
+ hierarchy 'Weekly', has_all: false, primary_key: 'id' do
88
91
  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'
92
+ level 'Year', column: 'the_year', type: 'Numeric', unique_members: true, level_type: 'TimeYears'
93
+ level 'Week', column: 'week_of_year', type: 'Numeric', unique_members: false, level_type: 'TimeWeeks'
91
94
  end
92
95
  end
93
- measure 'Unit Sales', :column => 'unit_sales', :aggregator => 'sum'
94
- measure 'Store Sales', :column => 'store_sales', :aggregator => 'sum'
96
+ measure 'Unit Sales', column: 'unit_sales', aggregator: 'sum'
97
+ measure 'Store Sales', column: 'store_sales', aggregator: 'sum'
95
98
  end
96
99
  end
97
100
  ```
@@ -104,12 +107,12 @@ When schema is defined it is necessary to establish OLAP connection to database.
104
107
  require "jdbc/mysql"
105
108
 
106
109
  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
110
+ driver: 'mysql',
111
+ host: 'localhost',
112
+ database: 'mondrian_test',
113
+ username: 'mondrian_user',
114
+ password: 'secret',
115
+ schema: schema
113
116
  )
114
117
  ```
115
118
 
@@ -171,7 +174,7 @@ Here is example of more complex query "Get sales amount and profit % of top 50 p
171
174
  olap.from('Sales').
172
175
  with_member('[Measures].[ProfitPct]').
173
176
  as('Val((Measures.[Store Sales] - Measures.[Store Cost]) / Measures.[Store Sales])',
174
- :format_string => 'Percent').
177
+ format_string: 'Percent').
175
178
  columns('[Measures].[Store Sales]', '[Measures].[ProfitPct]').
176
179
  rows('[Products].children').crossjoin('[Customers].[Canada]', '[Customers].[USA]').
177
180
  top_count(50, '[Measures].[Store Sales]').
@@ -251,13 +254,13 @@ subset of measures and dimension members. Here is example of data access role de
251
254
  schema = Mondrian::OLAP::Schema.define do
252
255
  # ... cube definitions ...
253
256
  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'
257
+ schema_grant access: 'none' do
258
+ cube_grant cube: 'Sales', access: 'all' do
259
+ dimension_grant dimension: '[Measures]', access: 'all'
260
+ hierarchy_grant hierarchy: '[Customers]', access: 'custom',
261
+ top_level: '[Customers].[State Province]', bottom_level: '[Customers].[City]' do
262
+ member_grant member: '[Customers].[USA].[CA]', access: 'all'
263
+ member_grant member: '[Customers].[USA].[CA].[Los Angeles]', access: 'none'
261
264
  end
262
265
  end
263
266
  end
@@ -270,9 +273,9 @@ See more examples of data access roles in `spec/connection_role_spec.rb`.
270
273
  REQUIREMENTS
271
274
  ------------
272
275
 
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.
276
+ mondrian-olap gem is compatible with JRuby version 9.2.x, and Java 8 and 11 VM. mondrian-olap works only with JRuby and not with other Ruby implementations as it includes Mondrian OLAP Java libraries.
274
277
 
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.
278
+ mondrian-olap supports MySQL, PostgreSQL, Oracle, Microsoft SQL Server, Vertica and Snowflake databases as well as other databases that are supported by Mondrian OLAP engine (using jdbc_driver and jdbc_url connection parameters). When using MySQL or PostgreSQL databases then install jdbc-mysql or jdbc-postgres gem and require "jdbc/mysql" or "jdbc/postgres" to load the corresponding JDBC database driver. When using Oracle then require Oracle JDBC driver (`ojdbc8.jar` for Java 8). 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 then require the latest `mssql-jdbc-*.jar`. When using Vertica or Snowflake then require corresponding JDBC drivers.
276
279
 
277
280
  INSTALL
278
281
  -------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 1.2.0
Binary file
Binary file
@@ -1,5 +1,3 @@
1
- # Logs errors on the console
1
+ # By default do not log anything
2
2
  #
3
- log4j.rootLogger = ERROR, A1
4
- log4j.appender.A1 = org.apache.log4j.ConsoleAppender
5
- log4j.appender.A1.layout=org.apache.log4j.PatternLayout
3
+ log4j.rootLogger=OFF
Binary file
@@ -7,9 +7,10 @@ module Mondrian
7
7
  connection
8
8
  end
9
9
 
10
- attr_reader :raw_connection, :raw_catalog, :raw_schema
10
+ attr_reader :raw_connection, :raw_mondrian_connection, :raw_catalog, :raw_schema,
11
+ :raw_schema_reader, :raw_cache_control
11
12
 
12
- def initialize(params={})
13
+ def initialize(params = {})
13
14
  @params = params
14
15
  @driver = params[:driver]
15
16
  @connected = false
@@ -29,6 +30,13 @@ module Mondrian
29
30
  props.setProperty('JdbcUser', @params[:username]) if @params[:username]
30
31
  props.setProperty('JdbcPassword', @params[:password]) if @params[:password]
31
32
 
33
+ # on Oracle increase default row prefetch size
34
+ # as default 10 is very low and slows down loading of all dimension members
35
+ if @driver == 'oracle'
36
+ prefetch_rows = @params[:prefetch_rows] || 100
37
+ props.setProperty("jdbc.defaultRowPrefetch", prefetch_rows.to_s)
38
+ end
39
+
32
40
  conn_string = connection_string
33
41
 
34
42
  # latest Mondrian version added ClassResolver which uses current thread class loader to load some classes
@@ -47,6 +55,9 @@ module Mondrian
47
55
  @raw_catalog = @raw_connection.getOlapCatalog
48
56
  # currently it is assumed that there is just one schema per connection catalog
49
57
  @raw_schema = @raw_catalog.getSchemas.first
58
+ @raw_mondrian_connection = @raw_connection.getMondrianConnection
59
+ @raw_schema_reader = @raw_mondrian_connection.getSchemaReader
60
+ @raw_cache_control = @raw_mondrian_connection.getCacheControl(nil)
50
61
  @connected = true
51
62
  true
52
63
  end
@@ -57,16 +68,31 @@ module Mondrian
57
68
  end
58
69
 
59
70
  def close
71
+ @raw_jdbc_connection = @raw_catalog = @raw_schema = @raw_mondrian_connection = nil
72
+ @raw_schema_reader = @raw_cache_control = nil
60
73
  @raw_connection.close
74
+ @raw_connection = nil
61
75
  @connected = false
62
- @raw_connection = @raw_jdbc_connection = nil
63
76
  true
64
77
  end
65
78
 
66
- def execute(query_string)
67
- Error.wrap_native_exception do
79
+ def execute(query_string, parameters = {})
80
+ options = {}
81
+ Error.wrap_native_exception(options) do
82
+ start_time = Time.now
68
83
  statement = @raw_connection.prepareOlapStatement(query_string)
69
- Result.new(self, statement.executeQuery())
84
+ options[:profiling_statement] = statement if parameters[:profiling]
85
+ set_statement_parameters(statement, parameters)
86
+ raw_cell_set = statement.executeQuery()
87
+ total_duration = ((Time.now - start_time) * 1000).to_i
88
+ Result.new(self, raw_cell_set, profiling_handler: statement.getProfileHandler, total_duration: total_duration)
89
+ end
90
+ end
91
+
92
+ # access mondrian.olap.Parameter object
93
+ def mondrian_parameter(parameter_name)
94
+ Error.wrap_native_exception do
95
+ @raw_schema_reader.getParameter(parameter_name)
70
96
  end
71
97
  end
72
98
 
@@ -81,6 +107,36 @@ module Mondrian
81
107
  Query.from(self, cube_name)
82
108
  end
83
109
 
110
+ def raw_schema_key
111
+ @raw_mondrian_connection.getSchema.getKey
112
+ end
113
+
114
+ def schema_key
115
+ raw_schema_key.toString
116
+ end
117
+
118
+ def self.raw_schema_key(schema_key)
119
+ if schema_key =~ /\A<(.*), (.*)>\z/
120
+ schema_content_key = $1
121
+ connection_key = $2
122
+
123
+ cons = Java::mondrian.rolap.SchemaContentKey.java_class.declared_constructor(java.lang.String)
124
+ cons.accessible = true
125
+ raw_schema_content_key = cons.new_instance(schema_content_key)
126
+
127
+ cons = Java::mondrian.rolap.ConnectionKey.java_class.declared_constructor(java.lang.String)
128
+ cons.accessible = true
129
+ raw_connection_key = cons.new_instance(connection_key)
130
+
131
+ cons = Java::mondrian.rolap.SchemaKey.java_class.declared_constructor(
132
+ Java::mondrian.rolap.SchemaContentKey, Java::mondrian.rolap.ConnectionKey)
133
+ cons.accessible = true
134
+ cons.new_instance(raw_schema_content_key, raw_connection_key)
135
+ else
136
+ raise ArgumentError, "invalid schema key #{schema_key}"
137
+ end
138
+ end
139
+
84
140
  def cube_names
85
141
  @raw_schema.getCubes.map{|c| c.getName}
86
142
  end
@@ -91,12 +147,37 @@ module Mondrian
91
147
 
92
148
  # Will affect only the next created connection. If it is necessary to clear all schema cache then
93
149
  # flush_schema_cache should be called, then close and then new connection should be created.
150
+ # This method flushes schemas for all connections (clears the schema pool).
94
151
  def flush_schema_cache
95
- unwrapped_connection = @raw_connection.unwrap(Java::MondrianOlap::Connection.java_class)
96
- raw_cache_control = unwrapped_connection.getCacheControl(nil)
97
152
  raw_cache_control.flushSchemaCache
98
153
  end
99
154
 
155
+ def self.raw_schema_pool
156
+ method = Java::mondrian.rolap.RolapSchemaPool.java_class.declared_method('instance')
157
+ method.accessible = true
158
+ method.invoke_static
159
+ end
160
+
161
+ def self.flush_schema_cache
162
+ method = Java::mondrian.rolap.RolapSchemaPool.java_class.declared_method('clear')
163
+ method.accessible = true
164
+ method.invoke(raw_schema_pool)
165
+ end
166
+
167
+ # This method flushes the schema only for this connection (removes from the schema pool).
168
+ def flush_schema
169
+ if raw_mondrian_connection && (rolap_schema = raw_mondrian_connection.getSchema)
170
+ raw_cache_control.flushSchema(rolap_schema)
171
+ end
172
+ end
173
+
174
+ def self.flush_schema(schema_key)
175
+ method = Java::mondrian.rolap.RolapSchemaPool.java_class.declared_method('remove',
176
+ Java::mondrian.rolap.SchemaKey.java_class)
177
+ method.accessible = true
178
+ method.invoke(raw_schema_pool, raw_schema_key(schema_key))
179
+ end
180
+
100
181
  def available_role_names
101
182
  @raw_connection.getAvailableRoleNames.to_a
102
183
  end
@@ -121,7 +202,9 @@ module Mondrian
121
202
  Error.wrap_native_exception do
122
203
  # workaround to access non-public method (was not public when using inside Torquebox)
123
204
  # @raw_connection.setRoleNames(Array(names))
124
- @raw_connection.java_method(:setRoleNames, [Java::JavaUtil::List.java_class]).call(Array(names))
205
+ names = Array(names)
206
+ @raw_connection.java_method(:setRoleNames, [Java::JavaUtil::List.java_class]).call(names)
207
+ names
125
208
  end
126
209
  end
127
210
 
@@ -131,7 +214,7 @@ module Mondrian
131
214
 
132
215
  def locale=(locale)
133
216
  locale_elements = locale.to_s.split('_')
134
- raise ArgumentError, "invalid locale string #{locale.inspect}" unless [1,2,3].include?(locale_elements.length)
217
+ raise ArgumentError, "invalid locale string #{locale.inspect}" unless [1, 2, 3].include?(locale_elements.length)
135
218
  java_locale = Java::JavaUtil::Locale.new(*locale_elements)
136
219
  @raw_connection.setLocale(java_locale)
137
220
  end
@@ -195,6 +278,14 @@ module Mondrian
195
278
  pool.close if pool && !pool.isClosed
196
279
  end
197
280
 
281
+ # unregister MBean
282
+ mbs = Java::JavaLangManagement::ManagementFactory.getPlatformMBeanServer
283
+ mbean_name = Java::JavaxManagement::ObjectName.new("mondrian.server:type=Server-#{static_mondrian_server.getId}")
284
+ begin
285
+ mbs.unregisterMBean(mbean_name)
286
+ rescue Java::JavaxManagement::InstanceNotFoundException
287
+ end
288
+
198
289
  true
199
290
  end
200
291
 
@@ -203,79 +294,137 @@ module Mondrian
203
294
  def connection_string
204
295
  string = "jdbc:mondrian:Jdbc=#{quote_string(jdbc_uri)};JdbcDrivers=#{jdbc_driver};"
205
296
  # by default use content checksum to reload schema when catalog has changed
206
- string << "UseContentChecksum=true;" unless @params[:use_content_checksum] == false
297
+ string += "UseContentChecksum=true;" unless @params[:use_content_checksum] == false
298
+ string += "PinSchemaTimeout=#{@params[:pin_schema_timeout]};" if @params[:pin_schema_timeout]
207
299
  if role = @params[:role] || @params[:roles]
208
300
  roles = Array(role).map{|r| r && r.to_s.gsub(',', ',,')}.compact
209
- string << "Role=#{quote_string(roles.join(','))};" unless roles.empty?
301
+ string += "Role=#{quote_string(roles.join(','))};" unless roles.empty?
210
302
  end
211
303
  if locale = @params[:locale]
212
- string << "Locale=#{quote_string(locale.to_s)};"
304
+ string += "Locale=#{quote_string(locale.to_s)};"
213
305
  end
214
- string << (@params[:catalog] ? "Catalog=#{catalog_uri}" : "CatalogContent=#{quote_string(catalog_content)}")
306
+ string + (@params[:catalog] ? "Catalog=#{catalog_uri}" : "CatalogContent=#{quote_string(catalog_content)}")
215
307
  end
216
308
 
217
309
  def jdbc_uri
218
- case @driver
219
- when 'mysql', 'postgresql'
220
- uri = "jdbc:#{@driver}://#{@params[:host]}#{@params[:port] && ":#{@params[:port]}"}/#{@params[:database]}"
221
- uri << "?useUnicode=yes&characterEncoding=UTF-8" if @driver == 'mysql'
222
- if (properties = @params[:properties]).is_a?(Hash) && !properties.empty?
223
- uri << (@driver == 'mysql' ? '&' : '?')
224
- uri << properties.map{|k, v| "#{k}=#{v}"}.join('&')
225
- end
226
- uri
227
- when 'oracle'
228
- # connection using TNS alias
229
- if @params[:database] && !@params[:host] && !@params[:url] && ENV['TNS_ADMIN']
230
- "jdbc:oracle:thin:@#{@params[:database]}"
231
- else
232
- @params[:url] || begin
233
- database = @params[:database]
234
- unless database =~ %r{^(:|/)}
235
- # assume database is a SID if no colon or slash are supplied (backward-compatibility)
236
- database = ":#{database}"
237
- end
238
- "jdbc:oracle:thin:@#{@params[:host] || 'localhost'}:#{@params[:port] || 1521}#{database}"
239
- end
240
- end
241
- when 'luciddb'
242
- uri = "jdbc:luciddb:http://#{@params[:host]}#{@params[:port] && ":#{@params[:port]}"}"
243
- uri << ";schema=#{@params[:database_schema]}" if @params[:database_schema]
244
- uri
245
- when 'mssql'
246
- uri = "jdbc:jtds:sqlserver://#{@params[:host]}#{@params[:port] && ":#{@params[:port]}"}/#{@params[:database]}"
247
- uri << ";instance=#{@params[:instance]}" if @params[:instance]
248
- uri << ";domain=#{@params[:domain]}" if @params[:domain]
249
- uri << ";appname=#{@params[:appname]}" if @params[:appname]
250
- uri
251
- when 'sqlserver'
252
- uri = "jdbc:sqlserver://#{@params[:host]}#{@params[:port] && ":#{@params[:port]}"}"
253
- uri << ";databaseName=#{@params[:database]}" if @params[:database]
254
- uri << ";integratedSecurity=#{@params[:integrated_security]}" if @params[:integrated_security]
255
- uri << ";applicationName=#{@params[:application_name]}" if @params[:application_name]
256
- uri << ";instanceName=#{@params[:instance_name]}" if @params[:instance_name]
257
- uri
310
+ if respond_to?(method_name = "jdbc_uri_#{@driver}", true)
311
+ send method_name
258
312
  else
259
313
  raise ArgumentError, 'unknown JDBC driver'
260
314
  end
261
315
  end
262
316
 
317
+ def jdbc_uri_generic(options = {})
318
+ uri_prefix = options[:uri_prefix] || "jdbc:#{@driver}://"
319
+ uri = "#{uri_prefix}#{@params[:host]}#{@params[:port] && ":#{@params[:port]}"}"
320
+ uri += "/#{@params[:database]}" if @params[:database] && options[:add_database] != false
321
+ properties = new_empty_properties
322
+ properties.merge!(options[:default_properties]) if options[:default_properties].is_a?(Hash)
323
+ properties.merge!(@params[:properties]) if @params[:properties].is_a?(Hash)
324
+ "#{uri}#{uri_properties_string(properties, options[:separator], options[:first_separator])}"
325
+ end
326
+
327
+ def new_empty_properties
328
+ # If ActiveSupport::HashWithIndifferentAccess is present then treat symbol and string keys as equal
329
+ defined?(ActiveSupport::HashWithIndifferentAccess) ? ActiveSupport::HashWithIndifferentAccess.new : {}
330
+ end
331
+
332
+ def uri_properties_string(properties, separator = nil, first_separator = nil)
333
+ properties_string = properties.map { |k, v| "#{k}=#{v}" }.join(separator || '&')
334
+ unless properties_string.empty?
335
+ first_separator ||= '?'
336
+ "#{first_separator}#{properties_string}"
337
+ end
338
+ end
339
+
340
+ def jdbc_uri_mysql
341
+ jdbc_uri_generic(default_properties: {useUnicode: true, characterEncoding: 'UTF-8'})
342
+ end
343
+
344
+ alias_method :jdbc_uri_postgresql, :jdbc_uri_generic
345
+ alias_method :jdbc_uri_vertica, :jdbc_uri_generic
346
+
347
+ def jdbc_uri_oracle
348
+ # connection using TNS alias
349
+ if @params[:database] && !@params[:host] && !@params[:url] && ENV['TNS_ADMIN']
350
+ "jdbc:oracle:thin:@#{@params[:database]}"
351
+ else
352
+ @params[:url] || begin
353
+ database = @params[:database]
354
+ unless database =~ %r{^(:|/)}
355
+ # assume database is a SID if no colon or slash are supplied (backward-compatibility)
356
+ database = ":#{database}"
357
+ end
358
+ "jdbc:oracle:thin:@#{@params[:host] || 'localhost'}:#{@params[:port] || 1521}#{database}"
359
+ end
360
+ end
361
+ end
362
+
363
+ def jdbc_uri_mssql
364
+ jdbc_uri_generic(
365
+ uri_prefix: 'jdbc:jtds:sqlserver://', separator: ';', first_separator: ';',
366
+ default_properties: @params.slice(:instance, :domain, :appname)
367
+ )
368
+ end
369
+
370
+ JDBC_SQLSERVER_PARAM_PROPERTIES = {
371
+ database: 'databaseName',
372
+ integrated_security: 'integratedSecurity',
373
+ application_name: 'applicationName',
374
+ instance_name: 'instanceName'
375
+ }
376
+
377
+ def jdbc_uri_sqlserver
378
+ jdbc_uri_generic(
379
+ uri_prefix: 'jdbc:sqlserver://', add_database: false, separator: ';', first_separator: ';',
380
+ default_properties: uri_default_param_properties(JDBC_SQLSERVER_PARAM_PROPERTIES)
381
+ )
382
+ end
383
+
384
+ def uri_default_param_properties(param_properties)
385
+ default_properties = {}
386
+ param_properties.each do |key, property|
387
+ if value = @params[key]
388
+ default_properties[property] = value
389
+ end
390
+ end
391
+ default_properties
392
+ end
393
+
394
+ JDBC_SNOWFLAKE_PARAM_PROPERTIES = {
395
+ database: 'db',
396
+ database_schema: 'schema',
397
+ warehouse: 'warehouse'
398
+ }
399
+
400
+ def jdbc_uri_snowflake
401
+ jdbc_uri_generic(
402
+ add_database: false, separator: '&', first_separator: '/?',
403
+ default_properties: uri_default_param_properties(JDBC_SNOWFLAKE_PARAM_PROPERTIES)
404
+ )
405
+ end
406
+
407
+ def jdbc_uri_jdbc
408
+ @params[:jdbc_url] or raise ArgumentError, 'missing jdbc_url parameter'
409
+ end
410
+
411
+ JDBC_DRIVER_CLASS = {
412
+ 'postgresql' => 'org.postgresql.Driver',
413
+ 'oracle' => 'oracle.jdbc.OracleDriver',
414
+ 'mssql' => 'net.sourceforge.jtds.jdbc.Driver',
415
+ 'sqlserver' => 'com.microsoft.sqlserver.jdbc.SQLServerDriver',
416
+ 'vertica' => 'com.vertica.jdbc.Driver',
417
+ 'snowflake' => 'net.snowflake.client.jdbc.SnowflakeDriver'
418
+ }
419
+
263
420
  def jdbc_driver
264
421
  case @driver
265
422
  when 'mysql'
266
- 'com.mysql.jdbc.Driver'
267
- when 'postgresql'
268
- 'org.postgresql.Driver'
269
- when 'oracle'
270
- 'oracle.jdbc.OracleDriver'
271
- when 'luciddb'
272
- 'org.luciddb.jdbc.LucidDbClientDriver'
273
- when 'mssql'
274
- 'net.sourceforge.jtds.jdbc.Driver'
275
- when 'sqlserver'
276
- 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
423
+ (Java::com.mysql.cj.jdbc.Driver rescue nil) ? 'com.mysql.cj.jdbc.Driver' : 'com.mysql.jdbc.Driver'
424
+ when 'jdbc'
425
+ @params[:jdbc_driver] or raise ArgumentError, 'missing jdbc_driver parameter'
277
426
  else
278
- raise ArgumentError, 'unknown JDBC driver'
427
+ JDBC_DRIVER_CLASS[@driver] or raise ArgumentError, 'unknown JDBC driver'
279
428
  end
280
429
  end
281
430
 
@@ -298,7 +447,43 @@ module Mondrian
298
447
  end
299
448
 
300
449
  def quote_string(string)
301
- "'#{string.gsub("'","''")}'"
450
+ "'#{string.gsub("'", "''")}'"
451
+ end
452
+
453
+ def set_statement_parameters(statement, parameters)
454
+ if parameters && !parameters.empty?
455
+ parameters = parameters.dup
456
+ # define addtional parameters which can be accessed from user defined functions
457
+ if define_parameters = parameters.delete(:define_parameters)
458
+ query_validator = statement.getQuery.createValidator
459
+ define_parameters.each do |dp_name, dp_value|
460
+ dp_type_class = dp_value.is_a?(Numeric) ? Java::MondrianOlapType::NumericType : Java::MondrianOlapType::StringType
461
+ query_validator.createOrLookupParam(true, dp_name, dp_type_class.new, nil, nil)
462
+ parameters[dp_name] = dp_value
463
+ end
464
+ end
465
+ if parameters.delete(:profiling)
466
+ statement.enableProfiling(ProfilingHandler.new)
467
+ end
468
+ if timeout = parameters.delete(:timeout)
469
+ statement.getQuery.setQueryTimeoutMillis(timeout * 1000)
470
+ end
471
+ parameters.each do |parameter_name, value|
472
+ statement.getQuery.setParameter(parameter_name, value)
473
+ end
474
+ end
475
+ end
476
+
477
+ class ProfilingHandler
478
+ java_implements Java::mondrian.spi.ProfileHandler
479
+ attr_reader :plan
480
+ attr_reader :timing
481
+
482
+ java_signature 'void explain(String plan, mondrian.olap.QueryTiming timing)'
483
+ def explain(plan, timing)
484
+ @plan = plan
485
+ @timing = timing
486
+ end
302
487
  end
303
488
 
304
489
  end