rgviz-rails 0.20 → 0.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -168,7 +168,7 @@ module Rgviz
168
168
  else
169
169
  # A little more complicated...
170
170
 
171
- # This has the grouping as a key and the pivoted selection values as a key (in a list)
171
+ # This has the grouping as a key and the pivoted selection values as a value (in a list)
172
172
  fin = ActiveSupport::OrderedHash.new
173
173
 
174
174
  # The uniq pivot values
@@ -202,9 +202,7 @@ module Rgviz
202
202
 
203
203
  # Now put all this info into fin
204
204
  fin[grouped_by] = {} unless fin[grouped_by]
205
- selections.each do |selection|
206
- fin[grouped_by][pivots] = selection
207
- end
205
+ fin[grouped_by][pivots] = selections
208
206
  end
209
207
 
210
208
  # Sort the uniq pivots so the results will be sorted for a human
@@ -236,6 +234,7 @@ module Rgviz
236
234
  @table.rows << row
237
235
 
238
236
  group_i = 0
237
+ value_i = 0
239
238
  @original_columns.each_with_index do |original_column, i|
240
239
  if @group_bys.include?(original_column)
241
240
  hash = {}
@@ -244,10 +243,14 @@ module Rgviz
244
243
  group_i += 1
245
244
  elsif !@pivots.include?(original_column)
246
245
  uniq_pivots.each do |uniq_pivot|
246
+ v = value[uniq_pivot]
247
+ v = v[value_i] if v
248
+
247
249
  hash = {}
248
- hash[:v] = value[uniq_pivot] unless @query.options && @query.options.no_values
250
+ hash[:v] = v unless @query.options && @query.options.no_values
249
251
  row.c << (Cell.new hash)
250
252
  end
253
+ value_i += 1
251
254
  end
252
255
  end
253
256
  end
@@ -383,10 +386,12 @@ module Rgviz
383
386
  def visit_scalar_function_column(node)
384
387
  case node.function
385
388
  when ScalarFunctionColumn::Sum, ScalarFunctionColumn::Difference,
386
- ScalarFunctionColumn::Product, ScalarFunctionColumn::Quotient
389
+ ScalarFunctionColumn::Product, ScalarFunctionColumn::Quotient
390
+ @string += "("
387
391
  node.arguments[0].accept self
388
392
  @string += node.function.to_s
389
393
  node.arguments[1].accept self
394
+ @string += ")"
390
395
  else
391
396
  @string += @executor.adapter.accept_scalar_function_column(node, self)
392
397
  end
@@ -437,9 +442,11 @@ module Rgviz
437
442
 
438
443
  class WhereVisitor < ColumnVisitor
439
444
  def visit_binary_expression(node)
445
+ @string += "("
440
446
  node.left.accept self
441
447
  @string += " #{node.operator} "
442
448
  node.right.accept self
449
+ @string += ")"
443
450
  false
444
451
  end
445
452
 
@@ -368,4 +368,25 @@ describe Executor do
368
368
  end
369
369
  end
370
370
 
371
+ it "processes pivot4" do
372
+ Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 10
373
+ Person.make :name => 'Sales', :birthday => '2001-02-12', :age => 20
374
+
375
+ table = exec 'select birthday, month(birthday), sum(age) group by month(birthday) pivot name order by name'
376
+
377
+ table.cols.length.should == 5
378
+
379
+ i = 0
380
+ [
381
+ ['2000-01-12', nil, 1, 10, nil],
382
+ [nil, '2001-02-12', 2, nil, 20],
383
+ ].each do |values|
384
+ table.rows[i].c.length.should == 5
385
+ values.each_with_index do |v, j|
386
+ table.rows[i].c[j].v.should == v
387
+ end
388
+ i += 1
389
+ end
390
+ end
391
+
371
392
  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: 35
4
+ hash: 33
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 20
9
- version: "0.20"
8
+ - 21
9
+ version: "0.21"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ary Borenszweig