cube 1.2.1 → 1.3.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.
Files changed (6) hide show
  1. data/README.md +12 -1
  2. data/VERSION +1 -1
  3. data/cube.gemspec +2 -2
  4. data/lib/cube/cube.rb +19 -4
  5. data/spec/cube_spec.rb +21 -22
  6. metadata +17 -17
data/README.md CHANGED
@@ -23,7 +23,7 @@ XMLA.configure do |c|
23
23
  end
24
24
  ```
25
25
 
26
- Usage
26
+ Queriying the OLAP
27
27
  -------
28
28
  ```
29
29
  table = XMLA::Cube.execute <<-MDX
@@ -33,6 +33,17 @@ table = XMLA::Cube.execute <<-MDX
33
33
  MDX
34
34
  ```
35
35
 
36
+ Scalar results
37
+ -----------
38
+ ```
39
+ result = XMLA::Cube.execute_scalar <<-MDX
40
+ SELECT {Hierarchize({[Measures].[MTBF]})} ON COLUMNS
41
+ FROM [Outage]
42
+ WHERE [Country].[Croatia]
43
+ MDX
44
+ ```
45
+ This returns decimal value.
46
+
36
47
  Limitations
37
48
  ------------
38
49
  * No drill down (fails to even parse the result)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cube"
8
- s.version = "1.2.1"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["drKreso"]
12
- s.date = "2012-02-17"
12
+ s.date = "2012-02-18"
13
13
  s.description = "Eases the pain I had to go through to get to the data out of XMLA based OLAP provider"
14
14
  s.email = "kresimir.bojcic@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -1,5 +1,6 @@
1
1
  require 'savon'
2
2
  require 'guerrilla_patch'
3
+ require 'bigdecimal'
3
4
 
4
5
  Savon.configure do |config|
5
6
  config.soap_version = 1
@@ -14,21 +15,25 @@ module XMLA
14
15
  attr_reader :query, :catalog
15
16
 
16
17
  def Cube.execute(query, catalog = XMLA.catalog)
17
- Cube.new(query, catalog).as_table
18
+ OlapResult.new(Cube.new(query, catalog).as_table)
19
+ end
20
+
21
+ def Cube.execute_scalar(query, catalog = XMLA.catalog)
22
+ BigDecimal.new Cube.new(query, catalog).as_table[0]
18
23
  end
19
24
 
20
25
  def as_table
21
26
  return [table] if y_size == 0
22
- clean_table(table, y_size).reduce([]) { |result, row| result << row.flatten.join('|') }
27
+ clean_table(table, y_size).reduce([]) { |result, row| result << row.flatten }
23
28
  end
24
29
 
30
+ private
31
+
25
32
  let(:x_axe) { @x_axe ||= axes[0] }
26
33
  let(:y_axe) { @y_axe ||= axes[1] }
27
34
  let(:y_size) { (y_axe.nil? || y_axe[0].nil?) ? 0 : y_axe[0].size }
28
35
  let(:x_size) { x_axe.size }
29
36
 
30
- private
31
-
32
37
  #header and rows
33
38
  def table
34
39
  if (header.size == 1 && y_size == 0)
@@ -103,6 +108,16 @@ module XMLA
103
108
  end
104
109
 
105
110
  end
111
+
112
+ class OlapResult
113
+ attr_reader :header, :rows
114
+ def initialize(table)
115
+ @header = table[0]
116
+ table.delete_at(0)
117
+ @rows = table
118
+ end
119
+ end
120
+
106
121
  end
107
122
 
108
123
 
@@ -19,29 +19,29 @@ describe XMLA::Cube do
19
19
  it 'supports multiple items on x axis' do
20
20
  VCR.use_cassette('kvatovi_u_koloni') do
21
21
  result = XMLA::Cube.execute("select [Lokacija].[Kvart].children on COLUMNS, [Measures].[Broj] on ROWS from [GOSJAR]")
22
- result.size.should == 2
23
- result[0].split('|').size.should == 18
24
- result[1].should == "Broj|1422|2259|2148|2733|2004|2607|2829|1611|2581|1945|3602|1356|1696|2327|1228|3186|"
22
+ result.rows.count.should == 1
23
+ result.header.count.should == 18
24
+ result.rows.join('|').should == "Broj|1422|2259|2148|2733|2004|2607|2829|1611|2581|1945|3602|1356|1696|2327|1228|3186|"
25
25
  end
26
26
  end
27
27
 
28
28
  it 'supports multiple items on y axis' do
29
29
  VCR.use_cassette('kvartovi_u_recima') do
30
30
  result = XMLA::Cube.execute("select [Measures].[Broj] on COLUMNS, non empty topcount( [Lokacija].[Kvart].children, 100, [Measures].[Broj]) on ROWS from [GOSJAR]")
31
- result.size.should == 17
32
- result[0].should == '|Broj'
33
- result[6].should == 'TRESNJEVKA - JUG|2607'
34
- result[16].should == 'PODSLJEME|1228'
31
+ result.rows.count.should == 16
32
+ result.header.join('|').should == '|Broj'
33
+ result.rows[5].join('|').should == 'TRESNJEVKA - JUG|2607'
34
+ result.rows[15].join('|').should == 'PODSLJEME|1228'
35
35
  end
36
36
  end
37
37
 
38
38
  it 'support multiple items on y axis and multiple items on x axis' do
39
39
  VCR.use_cassette('razlog_prijave_i_kvart') do
40
40
  result = XMLA::Cube.execute("select [Measures].[Broj] on COLUMNS, non empty topcount ( [Razlog prijave].[Razlog].children * [Lokacija].[Kvart].children , 20, [Measures].[Broj] ) on ROWS from [GOSJAR]")
41
- result.size.should == 21
42
- result[0].should == "||Broj"
43
- result[2].should == "|GORNJA DUBRAVA|1383"
44
- result[20].should == "Redovna izmjena|GORNJA DUBRAVA|575"
41
+ result.rows.count.should == 20
42
+ result.header.join('|').should == "||Broj"
43
+ result.rows[1].join('|').should == "|GORNJA DUBRAVA|1383"
44
+ result.rows[19].join('|').should == "Redovna izmjena|GORNJA DUBRAVA|575"
45
45
  end
46
46
  end
47
47
 
@@ -63,9 +63,9 @@ describe XMLA::Cube do
63
63
 
64
64
  VCR.use_cassette('mondrian_broj_intervencija') do
65
65
  result = XMLA::Cube.execute("SELECT NON EMPTY {Hierarchize({[Measures].[Broj intervencija]})} ON COLUMNS, NON EMPTY {Hierarchize({[Gradska cetvrt].[Gradska cetvrt].Members})} ON ROWS FROM [Kvarovi]")
66
- result.size.should == 17
67
- result[0].should == "|Broj intervencija"
68
- result[2].should == "GORNJI GRAD – MEDVEŠČAK|2259"
66
+ result.rows.count.should == 16
67
+ result.header.join('|').should == "|Broj intervencija"
68
+ result.rows[1].join('|').should == "GORNJI GRAD – MEDVEŠČAK|2259"
69
69
  end
70
70
  end
71
71
 
@@ -78,9 +78,9 @@ describe XMLA::Cube do
78
78
  non empty ( { Filter (Hierarchize({[Razlog prijave].children}), [Measures].[Broj intervencija] >= 7000 )}) ON ROWS
79
79
  FROM [Kvarovi]
80
80
  MDX
81
- result.size.should == 2
82
- result[0].should == "|Broj intervencija"
83
- result[1].should == "Ne radi svjetiljka|14442"
81
+ result.rows.count.should == 1
82
+ result.header.join('|').should == "|Broj intervencija"
83
+ result.rows[0].join('|').should == "Ne radi svjetiljka|14442"
84
84
  end
85
85
  end
86
86
 
@@ -94,8 +94,8 @@ describe XMLA::Cube do
94
94
  non empty ( { Filter (Hierarchize({[Razlog prijave].children}), [Measures].[Broj intervencija] >= 15000 )}) ON ROWS
95
95
  FROM [Kvarovi]
96
96
  MDX
97
- result.size.should == 1
98
- result[0].should == ""
97
+ result.rows.count.should == 0
98
+ result.rows[0].should == nil
99
99
  end
100
100
  end
101
101
 
@@ -103,13 +103,12 @@ describe XMLA::Cube do
103
103
  configure_mondrian
104
104
 
105
105
  VCR.use_cassette('mondrian_scalar_value') do
106
- result = XMLA::Cube.execute <<-MDX
106
+ result = XMLA::Cube.execute_scalar <<-MDX
107
107
  SELECT {Hierarchize({[Measures].[Rok otklona]})} ON COLUMNS
108
108
  FROM [Kvarovi]
109
109
  WHERE [Vrijeme prijave].[2011]
110
110
  MDX
111
- result.size.should == 1
112
- result[0].should == "7.356"
111
+ result.should == 7.356
113
112
  end
114
113
 
115
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cube
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-17 00:00:00.000000000Z
12
+ date: 2012-02-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
16
- requirement: &70127395026240 !ruby/object:Gem::Requirement
16
+ requirement: &70281986966140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70127395026240
24
+ version_requirements: *70281986966140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: webmock
27
- requirement: &70127395025680 !ruby/object:Gem::Requirement
27
+ requirement: &70281987002860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70127395025680
35
+ version_requirements: *70281987002860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: guerrilla_patch
38
- requirement: &70127395024960 !ruby/object:Gem::Requirement
38
+ requirement: &70281987005480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70127395024960
46
+ version_requirements: *70281987005480
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: vcr
49
- requirement: &70127395024440 !ruby/object:Gem::Requirement
49
+ requirement: &70281987007640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70127395024440
57
+ version_requirements: *70281987007640
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &70127395023920 !ruby/object:Gem::Requirement
60
+ requirement: &70281987010760 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.3.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70127395023920
68
+ version_requirements: *70281987010760
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
- requirement: &70127395023320 !ruby/object:Gem::Requirement
71
+ requirement: &70281987013780 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.0.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70127395023320
79
+ version_requirements: *70281987013780
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: jeweler
82
- requirement: &70127395022740 !ruby/object:Gem::Requirement
82
+ requirement: &70281987015800 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: 1.6.4
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70127395022740
90
+ version_requirements: *70281987015800
91
91
  description: Eases the pain I had to go through to get to the data out of XMLA based
92
92
  OLAP provider
93
93
  email: kresimir.bojcic@gmail.com
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  segments:
138
138
  - 0
139
- hash: 1611623706615328168
139
+ hash: 3603504358049639102
140
140
  required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  none: false
142
142
  requirements: