active_median 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10eda8c3a8100441196584a8188a6bbd09829e5494d1f39a8faa8e9f77e98fcd
4
- data.tar.gz: a6c2a49151b3ead3d6e7cf0d2eff4fc8d5d455b7d3fcee35b15645372863f37f
3
+ metadata.gz: 629f5530448797da4aca90cd7d89f1b37550caeeacb64a7ce5f56c761dbad09a
4
+ data.tar.gz: 5d9b666c75a1c3ac976f968df91422e9cbc5d2c89f3f41a6cd58a7a409ef8c47
5
5
  SHA512:
6
- metadata.gz: baeda2f4c8fa2b36c5fb29b2afc1daecbbd6a242e9e761b65503eba7868f55d7a9ccd0c39fe645c032cd5aab3f6d79a6ce63bdba6950277fab588883d89911e7
7
- data.tar.gz: d8b888c42e7731b07c15a283b17ee28e2b6dc0a279f6dd417390b087fd6454bbcf3ff5659a73f3ec27067260499765584952e8e107ecd2be6d858a913d775cea
6
+ metadata.gz: f45451ab6d041058e087a88e56c0faaccfb066a96f3c9f48fae7abc4edbca67dcbf3841bdd142133b5b272847e54e783591046ef8f77589305fb412bdc213c94
7
+ data.tar.gz: ed76ff4622fbc943d3190c060193a55fb2d74f16541ccf8965b32313019e22a4bbd45eeb120d8aa8eb3f6866a1601e975123bc1276367c9a8128c2d796e04860
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.1 (2021-02-21)
2
+
3
+ - Fixed error with relations with `select` clauses
4
+
1
5
  ## 0.3.0 (2021-02-08)
2
6
 
3
7
  - Added column alias
data/README.md CHANGED
@@ -81,7 +81,15 @@ mysql <options> < load.sql
81
81
 
82
82
  ### SQLite
83
83
 
84
- SQLite requires an extension. Download [percentile.c](https://www.sqlite.org/src/file?name=ext/misc/percentile.c&ci=d49c32e6e7cc341b) and follow the [instructions for compiling loadable extensions](https://www.sqlite.org/loadext.html#compiling_a_loadable_extension) for your platform. On Mac, use:
84
+ SQLite requires an extension. Download [percentile.c](https://www.sqlite.org/src/file?name=ext/misc/percentile.c&ci=d49c32e6e7cc341b) and follow the [instructions for compiling loadable extensions](https://www.sqlite.org/loadext.html#compiling_a_loadable_extension) for your platform.
85
+
86
+ On Linux, use:
87
+
88
+ ```sh
89
+ gcc -g -fPIC -shared -lsqlite3 percentile.c -o percentile.so
90
+ ```
91
+
92
+ On Mac, use:
85
93
 
86
94
  ```sh
87
95
  gcc -g -fPIC -dynamiclib -L/usr/local/opt/sqlite/lib -lsqlite3 percentile.c -o percentile.dylib
@@ -92,7 +100,7 @@ To load it in Rails, create an initializer with:
92
100
  ```ruby
93
101
  db = ActiveRecord::Base.connection.raw_connection
94
102
  db.enable_load_extension(1)
95
- db.load_extension("percentile.dylib")
103
+ db.load_extension("percentile.so") # or percentile.dylib
96
104
  db.enable_load_extension(0)
97
105
  ```
98
106
 
@@ -39,6 +39,9 @@ module ActiveMedian
39
39
 
40
40
  group_values = all.group_values
41
41
 
42
+ # replace select to match behavior of average
43
+ relation = unscope(:select)
44
+
42
45
  relation =
43
46
  case connection.adapter_name
44
47
  when /mysql/i
@@ -51,21 +54,21 @@ module ActiveMedian
51
54
  over = "PARTITION BY #{group_values.join(", ")}"
52
55
  end
53
56
 
54
- select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) OVER (#{over}) AS #{column_alias}").unscope(:group)
57
+ relation.select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) OVER (#{over}) AS #{column_alias}").unscope(:group)
55
58
  else
56
59
  # if mysql gets native function, check (and memoize) version first
57
- select(*group_values, "PERCENTILE_CONT(#{column}, #{percentile}) AS #{column_alias}")
60
+ relation.select(*group_values, "PERCENTILE_CONT(#{column}, #{percentile}) AS #{column_alias}")
58
61
  end
59
62
  when /sqlserver/i
60
63
  if group_values.any?
61
64
  over = "PARTITION BY #{group_values.join(", ")}"
62
65
  end
63
66
 
64
- select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) OVER (#{over}) AS #{column_alias}").unscope(:group)
67
+ relation.select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) OVER (#{over}) AS #{column_alias}").unscope(:group)
65
68
  when /sqlite/i
66
- select(*group_values, "PERCENTILE(#{column}, #{percentile} * 100) AS #{column_alias}")
69
+ relation.select(*group_values, "PERCENTILE(#{column}, #{percentile} * 100) AS #{column_alias}")
67
70
  when /postg/i, /redshift/i # postgis too
68
- select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) AS #{column_alias}")
71
+ relation.select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) AS #{column_alias}")
69
72
  else
70
73
  raise "Connection adapter not supported: #{connection.adapter_name}"
71
74
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveMedian
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_median
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-08 00:00:00.000000000 Z
11
+ date: 2021-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport