active_median 0.2.1 → 0.2.2

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: cfbbd982f15a11c2f820533f977d7d066e1a8f46a397155681ca06673cf44cc2
4
- data.tar.gz: d2156aea58744c1d2955c00077f2b4ef064b2d541d8c69f0ca0a923d93ecbd29
3
+ metadata.gz: cf284681e30c58d0007a57126dc72e61f952f5d49ffc4e57cdec17f6c2f10fff
4
+ data.tar.gz: 1dca9e20643055bd0ab0978ef48d22034c5e5aea1fdd983db46a031040843d20
5
5
  SHA512:
6
- metadata.gz: b5ff96c9f885f59dbc83dd1744fe427f67d1e43eefdb527fcb7e8994427452de186e12e8e0849bc1b15d3bcca2f65c0ec2a7403c631d2dba0f170b87bda074df
7
- data.tar.gz: 39671ed1587132c3e54cf9bb1e44f3d9999e7435aacdb2438d03989e94e8cb29b3448663c06bb23fb45315609098d28dc557d0726db612dc290c0229b9a2361a
6
+ metadata.gz: 49458af0dab24314e50668dcf8ecf4b9133c042c7cca5ff30b6caaae118fdfdfc635af3732f8b07e3923547c9addf28d09b86a6ba68401b454d938229b3150cd
7
+ data.tar.gz: d3f37b499830cb8d3cad119c0d4eadb5fc4c4f6bee0e095e4767fddc81c8fc4a1fd89d98270ef130d0dff346db95abfa179d7de2519c6201e2829ba20015611d
@@ -1,3 +1,8 @@
1
+ ## 0.2.2
2
+
3
+ - Added support for MySQL with udf_infusion
4
+ - Added support for SQL Server and Redshift
5
+
1
6
  ## 0.2.1
2
7
 
3
8
  - Added support for arrays and hashes
data/README.md CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  Median for ActiveRecord
4
4
 
5
- Supports PostgreSQL 9.4+, MariaDB 10.3.3+, and SQLite, plus arrays and hashes
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
 
@@ -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
- else
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)
@@ -1,3 +1,3 @@
1
1
  module ActiveMedian
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
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.2.1
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-15 00:00:00.000000000 Z
11
+ date: 2018-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord