active_median 0.2.1 → 0.2.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +21 -2
- data/lib/active_median/model.rb +18 -1
- data/lib/active_median/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf284681e30c58d0007a57126dc72e61f952f5d49ffc4e57cdec17f6c2f10fff
|
4
|
+
data.tar.gz: 1dca9e20643055bd0ab0978ef48d22034c5e5aea1fdd983db46a031040843d20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49458af0dab24314e50668dcf8ecf4b9133c042c7cca5ff30b6caaae118fdfdfc635af3732f8b07e3923547c9addf28d09b86a6ba68401b454d938229b3150cd
|
7
|
+
data.tar.gz: d3f37b499830cb8d3cad119c0d4eadb5fc4c4f6bee0e095e4767fddc81c8fc4a1fd89d98270ef130d0dff346db95abfa179d7de2519c6201e2829ba20015611d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,13 @@
|
|
2
2
|
|
3
3
|
Median for ActiveRecord
|
4
4
|
|
5
|
-
Supports
|
5
|
+
Supports:
|
6
|
+
|
7
|
+
- PostgreSQL 9.4+
|
8
|
+
- MariaDB 10.3.3+
|
9
|
+
- MySQL and SQL (with extensions)
|
10
|
+
- SQL Server 2012+
|
11
|
+
- Arrays and hashes
|
6
12
|
|
7
13
|
:fire: Uses native functions for blazing performance
|
8
14
|
|
@@ -53,7 +59,20 @@ Add this line to your application’s Gemfile:
|
|
53
59
|
gem 'active_median'
|
54
60
|
```
|
55
61
|
|
56
|
-
For SQLite, also follow the instructions below.
|
62
|
+
For MySQL and SQLite, also follow the instructions below.
|
63
|
+
|
64
|
+
### MySQL
|
65
|
+
|
66
|
+
MySQL requires the `PERCENTILE_CONT` function from [udf_infusion](https://github.com/infusion/udf_infusion). To install it, do:
|
67
|
+
|
68
|
+
```sh
|
69
|
+
git clone https://github.com/infusion/udf_infusion.git
|
70
|
+
cd udf_infusion
|
71
|
+
./configure --enable-functions="percentile_cont"
|
72
|
+
make
|
73
|
+
sudo make install
|
74
|
+
mysql <options> < load.sql
|
75
|
+
```
|
57
76
|
|
58
77
|
### SQLite
|
59
78
|
|
data/lib/active_median/model.rb
CHANGED
@@ -6,6 +6,21 @@ module ActiveMedian
|
|
6
6
|
relation =
|
7
7
|
case connection.adapter_name
|
8
8
|
when /mysql/i
|
9
|
+
# assume mariadb by default
|
10
|
+
# use send as this method is private in Rails 4.2
|
11
|
+
mariadb = connection.send(:mariadb?) rescue true
|
12
|
+
|
13
|
+
if mariadb
|
14
|
+
if group_values.any?
|
15
|
+
over = "PARTITION BY #{group_values.join(", ")}"
|
16
|
+
end
|
17
|
+
|
18
|
+
select(*group_values, "PERCENTILE_CONT(0.50) WITHIN GROUP (ORDER BY #{column}) OVER (#{over})").unscope(:group)
|
19
|
+
else
|
20
|
+
# if mysql gets native function, check (and memoize) version first
|
21
|
+
select(*group_values, "PERCENTILE_CONT(#{column}, 0.50)")
|
22
|
+
end
|
23
|
+
when /sqlserver/i
|
9
24
|
if group_values.any?
|
10
25
|
over = "PARTITION BY #{group_values.join(", ")}"
|
11
26
|
end
|
@@ -13,8 +28,10 @@ module ActiveMedian
|
|
13
28
|
select(*group_values, "PERCENTILE_CONT(0.50) WITHIN GROUP (ORDER BY #{column}) OVER (#{over})").unscope(:group)
|
14
29
|
when /sqlite/i
|
15
30
|
select(*group_values, "MEDIAN(#{column})")
|
16
|
-
|
31
|
+
when /postg/i, /redshift/i # postgis too
|
17
32
|
select(*group_values, "PERCENTILE_CONT(0.50) WITHIN GROUP (ORDER BY #{column})")
|
33
|
+
else
|
34
|
+
raise "Connection adapter not supported: #{connection.adapter_name}"
|
18
35
|
end
|
19
36
|
|
20
37
|
result = connection.select_all(relation.to_sql)
|
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|