rgviz-rails 0.21 → 0.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -94,7 +94,7 @@ module Rgviz
94
94
  end
95
95
  end
96
96
 
97
- # Select pivot columns
97
+ # Select pivot columns and group by columns
98
98
  if @query.pivot
99
99
  @query.pivot.columns.each do |col|
100
100
  col_to_s = col.to_s
@@ -104,6 +104,18 @@ module Rgviz
104
104
  @original_columns << col_to_s
105
105
  i += 1
106
106
  end
107
+
108
+ @max_original_columns = @original_columns.length
109
+
110
+ if @query.group_by
111
+ @query.group_by.columns.each do |col|
112
+ col_to_s = col.to_s
113
+
114
+ @table.cols << (Column.new :id => column_id(col, i), :type => column_type(col), :label => column_label(col_to_s))
115
+ @selects << "(#{column_select(col)}) as c#{i}"
116
+ i += 1
117
+ end
118
+ end
107
119
  end
108
120
  end
109
121
 
@@ -187,9 +199,9 @@ module Rgviz
187
199
  selections = []
188
200
 
189
201
  # Fill grouped_by, pivots and selections, as well as uniq_pivots
190
- @table.cols.each_with_index do |col, i|
202
+ @table.cols.each_with_index do |col, i|
191
203
  val = column_value(col, result.send("c#{i}"))
192
- if @group_bys.include?(@original_columns[i])
204
+ if i >= @max_original_columns || @group_bys.include?(@original_columns[i])
193
205
  grouped_by << val
194
206
  elsif @pivots.include?(@original_columns[i])
195
207
  pivots << val
@@ -213,6 +225,8 @@ module Rgviz
213
225
  col_i = 0
214
226
  new_cols = []
215
227
  @original_columns.each_with_index do |original_column, i|
228
+ break if i >= @max_original_columns
229
+
216
230
  old_col = @table.cols[i]
217
231
  if @group_bys.include?(original_column)
218
232
  old_col.id = "c#{col_i}"
@@ -389,4 +389,25 @@ describe Executor do
389
389
  end
390
390
  end
391
391
 
392
+ it "processes pivot with group by not in select" do
393
+ Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 10
394
+ Person.make :name => 'Sales', :birthday => '2001-02-12', :age => 20
395
+
396
+ table = exec 'select birthday, sum(age) group by month(birthday) pivot name order by name'
397
+
398
+ table.cols.length.should == 4
399
+
400
+ i = 0
401
+ [
402
+ ['2000-01-12', nil, 10, nil],
403
+ [nil, '2001-02-12', nil, 20],
404
+ ].each do |values|
405
+ table.rows[i].c.length.should == 4
406
+ values.each_with_index do |v, j|
407
+ table.rows[i].c[j].v.should == v
408
+ end
409
+ i += 1
410
+ end
411
+ end
412
+
392
413
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgviz-rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 33
4
+ hash: 39
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 21
9
- version: "0.21"
8
+ - 22
9
+ version: "0.22"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ary Borenszweig