olap4r 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,270 @@
1
+ require "spec_helper"
2
+
3
+ describe Olap::QueryBuilder do
4
+ context "#initialize" do
5
+ it "returns Olap::QueryBuilder instance" do
6
+ instance = Olap::QueryBuilder.new
7
+ instance.should be_a(Olap::QueryBuilder)
8
+ end
9
+ end
10
+
11
+ context "given an instance" do
12
+ let(:query_builder) { Olap::QueryBuilder.new }
13
+
14
+ context "#select with array" do
15
+ it "ignores empty array of columns" do
16
+ query_builder.select :columns, []
17
+ query_builder.to_s.should == ""
18
+ end
19
+
20
+ it "builds select :columns" do
21
+ query_builder.select :columns, "[Store].[All Stores]"
22
+ query_builder.to_s.should == "SELECT { [Store].[All Stores] } ON COLUMNS"
23
+ end
24
+
25
+ it "builds select :columns with multiple arguments" do
26
+ query_builder.select :columns, "[Store].[All Stores]", "[Store].[All Stores].CHILDREN"
27
+ query_builder.to_s.should == "SELECT HIERARCHIZE(UNION([Store].[All Stores], [Store].[All Stores].CHILDREN)) ON COLUMNS"
28
+ end
29
+
30
+ it "ignores empty array of rows" do
31
+ query_builder.select :rows, []
32
+ query_builder.to_s.should == ""
33
+ end
34
+
35
+ it "builds select :rows" do
36
+ query_builder.select :rows, "[Store].[All Stores]"
37
+ query_builder.to_s.should == "SELECT { [Store].[All Stores] } ON ROWS"
38
+ end
39
+
40
+ it "accepts select :rows with multiple arguments" do
41
+ query_builder.select :rows, "[Store].[All Stores]", "[Store].[All Stores].CHILDREN"
42
+ query_builder.to_s.should == "SELECT HIERARCHIZE(UNION([Store].[All Stores], [Store].[All Stores].CHILDREN)) ON ROWS"
43
+ end
44
+
45
+ it "builds select :rows and :column" do
46
+ query_builder.select :rows, "[Store].[All Stores]"
47
+ query_builder.select :columns, "[Measures].[Unit Sales]"
48
+ query_builder.to_s.should == "SELECT { [Measures].[Unit Sales] } ON COLUMNS, { [Store].[All Stores] } ON ROWS"
49
+ end
50
+ end
51
+
52
+ context "#select with hashes" do
53
+ it "ignores empty array of columns" do
54
+ query_builder.select :columns, []
55
+ query_builder.to_s.should == ""
56
+ end
57
+
58
+ it "builds select :columns" do
59
+ query_builder.select :columns, { :id => "[Store].[All Stores]", :properties => [] }
60
+ query_builder.to_s.should == "SELECT { [Store].[All Stores] } ON COLUMNS"
61
+ end
62
+
63
+ it "builds select :columns with multiple arguments" do
64
+ query_builder.select :columns, { :id => "[Store].[All Stores]", :properties => [] }, { :id => "[Store].[All Stores]", :properties => [] }
65
+ query_builder.to_s.should == "SELECT HIERARCHIZE(UNION([Store].[All Stores], [Store].[All Stores])) ON COLUMNS"
66
+ end
67
+
68
+ it "ignores empty array of rows" do
69
+ query_builder.select :rows, []
70
+ query_builder.to_s.should == ""
71
+ end
72
+
73
+ it "builds select :rows" do
74
+ query_builder.select :rows, { :id => "[Store].[All Stores]", :properties => [] }
75
+ query_builder.to_s.should == "SELECT { [Store].[All Stores] } ON ROWS"
76
+ end
77
+
78
+ it "accepts select :rows with multiple arguments" do
79
+ query_builder.select :rows, { :id => "[Store].[All Stores]", :properties => [] }, { :id => "[Store].[All Stores]", :properties => ["children"] }
80
+ query_builder.to_s.should == "SELECT HIERARCHIZE(UNION([Store].[All Stores], [Store].[All Stores].CHILDREN)) ON ROWS"
81
+ end
82
+
83
+ it "builds select :rows and :column" do
84
+ query_builder.select :rows, { :id => "[Store].[All Stores]", :properties => [] }
85
+ query_builder.select :columns, { :id => "[Measures].[Unit Sales]", :properties => [] }
86
+ query_builder.to_s.should == "SELECT { [Measures].[Unit Sales] } ON COLUMNS, { [Store].[All Stores] } ON ROWS"
87
+ end
88
+
89
+ it "silently ignores :drilldownlevel on root members" do
90
+ query_builder.select :rows, { :id => "[Geography]", :properties => ["drilldownlevel"] }
91
+ query_builder.to_s.should == "SELECT { [Geography] } ON ROWS"
92
+ end
93
+ end
94
+
95
+ it "selects the cube" do
96
+ query_builder.from "[Sales]"
97
+ query_builder.to_s.should == "FROM [Sales]"
98
+ end
99
+
100
+ it "ignores empty array of conditions" do
101
+ query_builder.where []
102
+ query_builder.to_s.should == ""
103
+ end
104
+
105
+ it "adds where conditions" do
106
+ query_builder.where "[Measures].[Unit Sales]"
107
+ query_builder.to_s.should == "WHERE ( [Measures].[Unit Sales] )"
108
+ end
109
+
110
+ it "adds multiple where conditions" do
111
+ query_builder.where "[Measures].[Unit Sales]", "[Store].[All Stores]"
112
+ query_builder.to_s.should == "WHERE ( [Measures].[Unit Sales], [Store].[All Stores] )"
113
+ end
114
+
115
+ it "builds the whole query with chaining" do
116
+ query_builder.select(:columns, "[Store].[All Stores]", "[Store].[All Stores].CHILDREN").
117
+ select(:rows, "[Measures].[Unit Sales]", "[Measures].[Sales Count]").
118
+ from("[Sales]").
119
+ where("[Store Type].[All Store Types].[Supermarket]")
120
+ query_builder.to_s.should == "SELECT HIERARCHIZE(UNION([Store].[All Stores], [Store].[All Stores].CHILDREN)) ON COLUMNS, { [Measures].[Unit Sales], [Measures].[Sales Count] } ON ROWS FROM [Sales] WHERE ( [Store Type].[All Store Types].[Supermarket] )"
121
+ end
122
+
123
+ it "executes built query" do
124
+ query_builder.select(:columns, "[Store].[All Stores]", "[Store].[All Stores].CHILDREN").
125
+ select(:rows, "[Measures].[Unit Sales]").
126
+ from("[Sales]").
127
+ where("[Store Type].[All Store Types].[Supermarket]")
128
+
129
+ connection = Olap::Connection.new RSPEC_CONFIG["mondrian"]["connection_string"]
130
+ connection.execute(query_builder).should be_a(Olap::CellSet)
131
+ end
132
+ end
133
+ end
134
+
135
+ describe Olap::QueryBuilder, "advanced queries" do
136
+ context "given an instance" do
137
+ let(:query_builder) { Olap::QueryBuilder.new }
138
+
139
+ context "for a single dimension" do
140
+ it "adds DRILLDOWNLEVEL function for a member of a dimension" do
141
+ query_builder.select :rows, { :id => "[Store].[All Stores].[USA]", :properties => ["drilldownlevel"] }
142
+ query_builder.to_s.should == "SELECT { DRILLDOWNLEVEL([Store].[All Stores].[USA]) } ON ROWS"
143
+ end
144
+
145
+ it "adds CHILDREN function for a member of a dimension" do
146
+ query_builder.select :rows, { :id => "[Store].[All Stores].[USA]", :properties => ["children"] }
147
+ query_builder.to_s.should == "SELECT { [Store].[All Stores].[USA].CHILDREN } ON ROWS"
148
+ end
149
+
150
+ it "adds HIERARCHIZED and UNION to a set and dimension" do
151
+ query_builder.select :rows,
152
+ "[Geography]",
153
+ { :id => "[Geography].[All Geographys]", :properties => ["children"] }
154
+
155
+ query_builder.to_s.should == "SELECT HIERARCHIZE(UNION({ [Geography] }, [Geography].[All Geographys].CHILDREN)) ON ROWS"
156
+ end
157
+
158
+ it "adds HIERARCHIZE and UNION for 2 members of a dimension" do
159
+ query_builder.select :rows,
160
+ "[Store].[All Stores].[USA]",
161
+ "[Store].[All Stores].[Israel]"
162
+
163
+ query_builder.to_s.should == "SELECT HIERARCHIZE(UNION([Store].[All Stores].[USA], [Store].[All Stores].[Israel])) ON ROWS"
164
+ end
165
+
166
+ it "adds HIERARCHIZE, UNION and member functions for 2 members of a dimension" do
167
+ query_builder.select :rows,
168
+ { :id => "[Store].[All Stores]", :properties => ["children"] },
169
+ { :id => "[Store].[All Stores]", :properties => ["drilldownlevel"] }
170
+
171
+ query_builder.to_s.should == "SELECT HIERARCHIZE(UNION([Store].[All Stores].CHILDREN, DRILLDOWNLEVEL([Store].[All Stores]))) ON ROWS"
172
+ end
173
+
174
+ it "adds HIERARCHIZE AND 2 UNIONs for 3 members of a dimension" do
175
+ query_builder.select :rows,
176
+ "[Store].[All Stores].[USA]",
177
+ "[Store].[All Stores].[Israel]",
178
+ "[Store].[All Stores].[Canada]"
179
+
180
+ query_builder.to_s.should == "SELECT HIERARCHIZE(UNION(UNION([Store].[All Stores].[USA], [Store].[All Stores].[Israel]), [Store].[All Stores].[Canada])) ON ROWS"
181
+ end
182
+
183
+ it "adds HIERARCHIZE AND 4 UNIONs for 5 members of a dimension" do
184
+ query_builder.select :rows,
185
+ "[Store].[All Stores].[USA]",
186
+ "[Store].[All Stores].[Israel]",
187
+ "[Store].[All Stores].[Canada]",
188
+ "[Store].[All Stores].[Mexico]",
189
+ "[Store].[All Stores].[Vatican]"
190
+
191
+ query_builder.to_s.should == "SELECT HIERARCHIZE(UNION(UNION(UNION(UNION([Store].[All Stores].[USA], [Store].[All Stores].[Israel]), [Store].[All Stores].[Canada]), [Store].[All Stores].[Mexico]), [Store].[All Stores].[Vatican])) ON ROWS"
192
+ end
193
+ end
194
+
195
+ context "for multiple dimensions" do
196
+ it "adds CROSSJOIN for 2 members of 2 dimensions" do
197
+ query_builder.select :rows,
198
+ "[Store]",
199
+ "[Store Type]"
200
+
201
+ query_builder.to_s.should == "SELECT HIERARCHIZE(CROSSJOIN({ [Store] }, { [Store Type] })) ON ROWS"
202
+ end
203
+
204
+ it "adds HIERARCHIZE, CROSSJOIN and UNION for 3 members of 2 dimensions" do
205
+ query_builder.select :rows,
206
+ "[Store].[All Stores].[USA]",
207
+ "[Store].[All Stores].[Israel]",
208
+ "[Store Type]"
209
+
210
+ query_builder.to_s.should == "SELECT HIERARCHIZE(CROSSJOIN(UNION([Store].[All Stores].[USA], [Store].[All Stores].[Israel]), { [Store Type] })) ON ROWS"
211
+ end
212
+
213
+ it "adds HIERACHIZE, CROSSJOIN and 2 nested JOINs for 4 members of 2 dimensions" do
214
+ query_builder.select :rows,
215
+ "[Store].[All Stores].[USA]",
216
+ "[Store].[All Stores].[Israel]",
217
+ "[Store].[All Stores].[Canada]",
218
+ "[Store Type]"
219
+
220
+ query_builder.to_s.should == "SELECT HIERARCHIZE(CROSSJOIN(UNION(UNION([Store].[All Stores].[USA], [Store].[All Stores].[Israel]), [Store].[All Stores].[Canada]), { [Store Type] })) ON ROWS"
221
+ end
222
+
223
+ it "adds HIERACHIZE, CROSSJOIN and 3 nested JOINs for 5 members of 2 dimensions" do
224
+ query_builder.select :rows,
225
+ "[Store].[All Stores].[USA]",
226
+ "[Store].[All Stores].[Israel]",
227
+ "[Store].[All Stores].[Canada]",
228
+ "[Store Type].[All Store Types].[Deluxe Supermarket]",
229
+ "[Store Type].[All Store Types].[HeadQuarters]"
230
+
231
+ query_builder.to_s.should == "SELECT HIERARCHIZE(CROSSJOIN(UNION(UNION([Store].[All Stores].[USA], [Store].[All Stores].[Israel]), [Store].[All Stores].[Canada]), UNION([Store Type].[All Store Types].[Deluxe Supermarket], [Store Type].[All Store Types].[HeadQuarters]))) ON ROWS"
232
+ end
233
+
234
+ it "adds HIERACHIZE, CROSSJOIN and 4 nested JOINs for 6 members of 2 dimensions" do
235
+ query_builder.select :rows,
236
+ "[Store].[All Stores].[USA]",
237
+ "[Store].[All Stores].[Israel]",
238
+ "[Store].[All Stores].[Canada]",
239
+ "[Store Type].[All Store Types].[Deluxe Supermarket]",
240
+ "[Store Type].[All Store Types].[HeadQuarters]",
241
+ "[Store Type].[All Store Types].[Gourmet Supermarket]"
242
+
243
+ query_builder.to_s.should == "SELECT HIERARCHIZE(CROSSJOIN(UNION(UNION([Store].[All Stores].[USA], [Store].[All Stores].[Israel]), [Store].[All Stores].[Canada]), UNION(UNION([Store Type].[All Store Types].[Deluxe Supermarket], [Store Type].[All Store Types].[HeadQuarters]), [Store Type].[All Store Types].[Gourmet Supermarket]))) ON ROWS"
244
+ end
245
+
246
+ it "adds HIERACHIZE, 2 nested CROSSJOINs and 3 nested JOINs for 6 members of 3 dimensions" do
247
+ query_builder.select :rows,
248
+ "[Store].[All Stores].[USA]",
249
+ "[Store].[All Stores].[Israel]",
250
+ "[Store Type].[All Store Types].[Deluxe Supermarket]",
251
+ "[Store Type].[All Store Types].[HeadQuarters]",
252
+ "[Product].[All Products].[Food]",
253
+ "[Product].[All Products].[Drink]"
254
+
255
+ query_builder.to_s.should == "SELECT HIERARCHIZE(CROSSJOIN(CROSSJOIN(UNION([Store].[All Stores].[USA], [Store].[All Stores].[Israel]), UNION([Store Type].[All Store Types].[Deluxe Supermarket], [Store Type].[All Store Types].[HeadQuarters])), UNION([Product].[All Products].[Food], [Product].[All Products].[Drink]))) ON ROWS"
256
+ end
257
+
258
+ it "adds HIERACHIZE, 2 nested CROSSJOINs and 3 nested JOINs for 6 members of 3 dimensions with according functions" do
259
+ query_builder.select :rows,
260
+ "[Store].[All Stores].[USA]",
261
+ { :id => "[Store].[All Stores].[Israel]", :properties => ["children"] },
262
+ "[Store Type].[All Store Types].[Deluxe Supermarket]",
263
+ "[Store Type].[All Store Types].[HeadQuarters]",
264
+ "[Product].[All Products].[Food]",
265
+ { :id => "[Product].[All Products].[Drink]", :properties => ["drilldownlevel"] }
266
+ query_builder.to_s.should == "SELECT HIERARCHIZE(CROSSJOIN(CROSSJOIN(UNION([Store].[All Stores].[USA], [Store].[All Stores].[Israel].CHILDREN), UNION([Store Type].[All Store Types].[Deluxe Supermarket], [Store Type].[All Store Types].[HeadQuarters])), UNION([Product].[All Products].[Food], DRILLDOWNLEVEL([Product].[All Products].[Drink])))) ON ROWS"
267
+ end
268
+ end
269
+ end
270
+ end
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require "rspec"
4
+ require "olap4r"
5
+ require "yaml"
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ end
13
+
14
+ RSPEC_CONFIG = YAML.load_file "spec/config.yml"
15
+ require "olap4r-mondrian"
16
+ require "olap4r-xmla"
17
+
18
+ require RSPEC_CONFIG["mondrian"]["jdbc_driver_path"]
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: olap4r
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Filip Tepper
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-08-20 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: jruby-openssl
17
+ version_requirements: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ requirement: *id001
24
+ prerelease: false
25
+ type: :development
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ version_requirements: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.11.0
34
+ requirement: *id002
35
+ prerelease: false
36
+ type: :development
37
+ - !ruby/object:Gem::Dependency
38
+ name: yard
39
+ version_requirements: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 0.8.2.1
45
+ requirement: *id003
46
+ prerelease: false
47
+ type: :development
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ version_requirements: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.1.0
56
+ requirement: *id004
57
+ prerelease: false
58
+ type: :development
59
+ - !ruby/object:Gem::Dependency
60
+ name: jeweler
61
+ version_requirements: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 1.8.4
67
+ requirement: *id005
68
+ prerelease: false
69
+ type: :development
70
+ - !ruby/object:Gem::Dependency
71
+ name: olap4r-mondrian
72
+ version_requirements: &id006 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.1.0
78
+ requirement: *id006
79
+ prerelease: false
80
+ type: :development
81
+ - !ruby/object:Gem::Dependency
82
+ name: olap4r-xmla
83
+ version_requirements: &id007 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: 0.1.0
89
+ requirement: *id007
90
+ prerelease: false
91
+ type: :development
92
+ description: olap4j wrapper for JRuby
93
+ email: filip@tepper.pl
94
+ executables: []
95
+
96
+ extensions: []
97
+
98
+ extra_rdoc_files:
99
+ - README.md
100
+ files:
101
+ - .document
102
+ - .rspec
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - README.md
106
+ - Rakefile
107
+ - VERSION
108
+ - lib/olap4j.jar
109
+ - lib/olap4r.rb
110
+ - lib/olap4r/cellset.rb
111
+ - lib/olap4r/connection.rb
112
+ - lib/olap4r/query_builder.rb
113
+ - lib/olap4r/rowset.rb
114
+ - olap4r.gemspec
115
+ - spec/config.yml.example
116
+ - spec/connection_spec.rb
117
+ - spec/fixtures/FoodMart.xml
118
+ - spec/query_builder_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: http://github.com/Freeport-Metrics/olap4r
121
+ licenses:
122
+ - MIT
123
+ post_install_message:
124
+ rdoc_options: []
125
+
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: 2
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: "0"
143
+ requirements: []
144
+
145
+ rubyforge_project:
146
+ rubygems_version: 1.8.24
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: olap4j wrapper for JRuby
150
+ test_files: []
151
+