olap4r 0.1.0 → 0.1.1
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.
- data/Gemfile.lock +2 -0
 - data/README.md +2 -0
 - data/VERSION +1 -1
 - data/lib/olap4r/query_builder.rb +22 -5
 - data/olap4r.gemspec +2 -2
 - data/spec/connection_spec.rb +18 -0
 - data/spec/query_builder_spec.rb +7 -1
 - metadata +2 -2
 
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -11,6 +11,7 @@ GEM 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  rdoc
         
     | 
| 
       12 
12 
     | 
    
         
             
                jruby-openssl (0.7.7)
         
     | 
| 
       13 
13 
     | 
    
         
             
                  bouncy-castle-java (>= 1.5.0146.1)
         
     | 
| 
      
 14 
     | 
    
         
            +
                json (1.7.3)
         
     | 
| 
       14 
15 
     | 
    
         
             
                json (1.7.3-java)
         
     | 
| 
       15 
16 
     | 
    
         
             
                olap4r-mondrian (0.1.0)
         
     | 
| 
       16 
17 
     | 
    
         
             
                olap4r-xmla (0.1.0)
         
     | 
| 
         @@ -29,6 +30,7 @@ GEM 
     | 
|
| 
       29 
30 
     | 
    
         | 
| 
       30 
31 
     | 
    
         
             
            PLATFORMS
         
     | 
| 
       31 
32 
     | 
    
         
             
              java
         
     | 
| 
      
 33 
     | 
    
         
            +
              ruby
         
     | 
| 
       32 
34 
     | 
    
         | 
| 
       33 
35 
     | 
    
         
             
            DEPENDENCIES
         
     | 
| 
       34 
36 
     | 
    
         
             
              bundler (~> 1.1.0)
         
     | 
    
        data/README.md
    CHANGED
    
    
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.1. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.1.1
         
     | 
    
        data/lib/olap4r/query_builder.rb
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Olap
         
     | 
| 
       2 
2 
     | 
    
         
             
              class QueryBuilder
         
     | 
| 
       3 
3 
     | 
    
         
             
                def initialize
         
     | 
| 
       4 
     | 
    
         
            -
                  @select = { 
     | 
| 
      
 4 
     | 
    
         
            +
                  @select = {:columns => [], :rows => []}
         
     | 
| 
       5 
5 
     | 
    
         
             
                  @from = nil
         
     | 
| 
       6 
6 
     | 
    
         
             
                  @conditions = []
         
     | 
| 
       7 
7 
     | 
    
         
             
                end
         
     | 
| 
         @@ -49,13 +49,16 @@ module Olap 
     | 
|
| 
       49 
49 
     | 
    
         
             
                  field
         
     | 
| 
       50 
50 
     | 
    
         
             
                end
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
      
 52 
     | 
    
         
            +
                def extract_hierarchy(field)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  field.match(/\[([^\]]+)\]/)[0]
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
       52 
56 
     | 
    
         
             
                def build_axis axis
         
     | 
| 
       53 
57 
     | 
    
         
             
                  return nil if @select[axis].empty?
         
     | 
| 
       54 
58 
     | 
    
         | 
| 
       55 
59 
     | 
    
         
             
                  hierarchies = {}
         
     | 
| 
       56 
60 
     | 
    
         
             
                  @select[axis].each do |field|
         
     | 
| 
       57 
     | 
    
         
            -
                    hierarchy = field 
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 61 
     | 
    
         
            +
                    hierarchy = extract_hierarchy(field)
         
     | 
| 
       59 
62 
     | 
    
         
             
                    hierarchies[hierarchy] = [] if hierarchies[hierarchy].nil?
         
     | 
| 
       60 
63 
     | 
    
         
             
                    hierarchies[hierarchy].push field
         
     | 
| 
       61 
64 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -102,12 +105,26 @@ module Olap 
     | 
|
| 
       102 
105 
     | 
    
         
             
                  crossjoined
         
     | 
| 
       103 
106 
     | 
    
         
             
                end
         
     | 
| 
       104 
107 
     | 
    
         | 
| 
      
 108 
     | 
    
         
            +
                def build_conditions
         
     | 
| 
      
 109 
     | 
    
         
            +
                  filters_by_hierarchy = @conditions.inject({}) { |hash, c|
         
     | 
| 
      
 110 
     | 
    
         
            +
                    hierarchy = extract_hierarchy(c)
         
     | 
| 
      
 111 
     | 
    
         
            +
                    if !hash[hierarchy] then
         
     | 
| 
      
 112 
     | 
    
         
            +
                      hash[hierarchy] = [c]
         
     | 
| 
      
 113 
     | 
    
         
            +
                    else
         
     | 
| 
      
 114 
     | 
    
         
            +
                      hash[hierarchy] << c
         
     | 
| 
      
 115 
     | 
    
         
            +
                    end
         
     | 
| 
      
 116 
     | 
    
         
            +
                    hash
         
     | 
| 
      
 117 
     | 
    
         
            +
                  }
         
     | 
| 
      
 118 
     | 
    
         
            +
                  filters_by_hierarchy.collect { |k, v| (v.size > 1) ? "{#{v.join(', ')}}" : v }.join(' * ')
         
     | 
| 
      
 119 
     | 
    
         
            +
                end
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
       105 
121 
     | 
    
         
             
                def build_query
         
     | 
| 
       106 
122 
     | 
    
         
             
                  query = []
         
     | 
| 
       107 
123 
     | 
    
         | 
| 
       108 
124 
     | 
    
         
             
                  columns = build_axis :columns
         
     | 
| 
       109 
125 
     | 
    
         
             
                  rows = build_axis :rows
         
     | 
| 
       110 
126 
     | 
    
         | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
       111 
128 
     | 
    
         
             
                  unless rows.nil? && columns.nil?
         
     | 
| 
       112 
129 
     | 
    
         
             
                    query << "SELECT"
         
     | 
| 
       113 
130 
     | 
    
         | 
| 
         @@ -119,7 +136,7 @@ module Olap 
     | 
|
| 
       119 
136 
     | 
    
         
             
                  end
         
     | 
| 
       120 
137 
     | 
    
         | 
| 
       121 
138 
     | 
    
         
             
                  query << "FROM #{@from}" unless @from.nil?
         
     | 
| 
       122 
     | 
    
         
            -
                  query << "WHERE ( #{ 
     | 
| 
      
 139 
     | 
    
         
            +
                  query << "WHERE ( #{build_conditions} )" if @conditions.any?
         
     | 
| 
       123 
140 
     | 
    
         | 
| 
       124 
141 
     | 
    
         
             
                  query.join " "
         
     | 
| 
       125 
142 
     | 
    
         
             
                end
         
     | 
| 
         @@ -128,4 +145,4 @@ module Olap 
     | 
|
| 
       128 
145 
     | 
    
         
             
                  field.scan(/\[([^\]]*)\]/).length
         
     | 
| 
       129 
146 
     | 
    
         
             
                end
         
     | 
| 
       130 
147 
     | 
    
         
             
              end
         
     | 
| 
       131 
     | 
    
         
            -
            end
         
     | 
| 
      
 148 
     | 
    
         
            +
            end
         
     | 
    
        data/olap4r.gemspec
    CHANGED
    
    | 
         @@ -5,11 +5,11 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = "olap4r"
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0.1. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.1.1"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["Filip Tepper"]
         
     | 
| 
       12 
     | 
    
         
            -
              s.date = "2012- 
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = "2012-10-22"
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.description = "olap4j wrapper for JRuby"
         
     | 
| 
       14 
14 
     | 
    
         
             
              s.email = "filip@tepper.pl"
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.extra_rdoc_files = [
         
     | 
    
        data/spec/connection_spec.rb
    CHANGED
    
    | 
         @@ -95,6 +95,24 @@ shared_examples_for "an Olap::Connection driver" do 
     | 
|
| 
       95 
95 
     | 
    
         
             
                  end
         
     | 
| 
       96 
96 
     | 
    
         
             
                end
         
     | 
| 
       97 
97 
     | 
    
         | 
| 
      
 98 
     | 
    
         
            +
            	context "#execute query with conditions" do
         
     | 
| 
      
 99 
     | 
    
         
            +
            	  let(:cellset) { connection.execute "SELECT { [Department] } ON COLUMNS, \
         
     | 
| 
      
 100 
     | 
    
         
            +
            					{ [Position] } ON ROWS \
         
     | 
| 
      
 101 
     | 
    
         
            +
            			FROM [HR] \
         
     | 
| 
      
 102 
     | 
    
         
            +
            			WHERE ( {[Time].[1997].[Q1], [Time].[1997].[Q2], [Time].[1998].[Q1]} \
         
     | 
| 
      
 103 
     | 
    
         
            +
            					* {[Employees].[Sheri Nowmer].[Maya Gutierrez], [Employees].[Sheri Nowmer].[Darren Stanz]} \
         
     | 
| 
      
 104 
     | 
    
         
            +
            					* [Pay Type].[Hourly]  \
         
     | 
| 
      
 105 
     | 
    
         
            +
            					* [Store Type].[Small Grocery] )" }
         
     | 
| 
      
 106 
     | 
    
         
            +
            					
         
     | 
| 
      
 107 
     | 
    
         
            +
            	  it "returns Olap::CellSet instance for successful queries" do
         
     | 
| 
      
 108 
     | 
    
         
            +
                   	cellset.should be_a(Olap::CellSet)
         
     | 
| 
      
 109 
     | 
    
         
            +
                  end
         
     | 
| 
      
 110 
     | 
    
         
            +
                  
         
     | 
| 
      
 111 
     | 
    
         
            +
                  it "returns cellset formatted values" do
         
     | 
| 
      
 112 
     | 
    
         
            +
                    cellset.values(:value).should =~ [[10.309]]
         
     | 
| 
      
 113 
     | 
    
         
            +
                  end
         
     | 
| 
      
 114 
     | 
    
         
            +
                end
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
       98 
116 
     | 
    
         
             
                context "#execute" do
         
     | 
| 
       99 
117 
     | 
    
         
             
                  let(:cellset) { connection.execute "SELECT [Measures].[Unit Sales] ON COLUMNS, [Store] ON ROWS FROM [Sales]" }
         
     | 
| 
       100 
118 
     | 
    
         | 
    
        data/spec/query_builder_spec.rb
    CHANGED
    
    | 
         @@ -109,7 +109,13 @@ describe Olap::QueryBuilder do 
     | 
|
| 
       109 
109 
     | 
    
         | 
| 
       110 
110 
     | 
    
         
             
                it "adds multiple where conditions" do
         
     | 
| 
       111 
111 
     | 
    
         
             
                  query_builder.where "[Measures].[Unit Sales]", "[Store].[All Stores]"
         
     | 
| 
       112 
     | 
    
         
            -
                  query_builder.to_s.should == "WHERE ( [Measures].[Unit Sales] 
     | 
| 
      
 112 
     | 
    
         
            +
                  query_builder.to_s.should == "WHERE ( [Measures].[Unit Sales] * [Store].[All Stores] )"
         
     | 
| 
      
 113 
     | 
    
         
            +
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                it "adds multiple where conditions correctly for conditions from the same dimension" do
         
     | 
| 
      
 117 
     | 
    
         
            +
                  query_builder.where "[Measures].[Unit Sales]", "[Store].[All Stores].[USA]", "[Store].[All Stores].[Canada]"
         
     | 
| 
      
 118 
     | 
    
         
            +
                  query_builder.to_s.should == "WHERE ( [Measures].[Unit Sales] * {[Store].[All Stores].[USA], [Store].[All Stores].[Canada]} )"
         
     | 
| 
       113 
119 
     | 
    
         
             
                end
         
     | 
| 
       114 
120 
     | 
    
         | 
| 
       115 
121 
     | 
    
         
             
                it "builds the whole query with chaining" do
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: olap4r
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       5 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.1.1
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors: 
         
     | 
| 
       8 
8 
     | 
    
         
             
              - Filip Tepper
         
     | 
| 
         @@ -10,7 +10,7 @@ autorequire: 
     | 
|
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            date: 2012- 
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2012-10-22 00:00:00 Z
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       15 
15 
     | 
    
         
             
              - !ruby/object:Gem::Dependency 
         
     | 
| 
       16 
16 
     | 
    
         
             
                name: jruby-openssl
         
     |