sequel-batches 0.1.3 → 0.2.0

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
- SHA1:
3
- metadata.gz: 59714df347d4f6cb7e6e697051a8a049fda88dc1
4
- data.tar.gz: 011f44112aee94dda9e0e47e10999e13fe4972fd
2
+ SHA256:
3
+ metadata.gz: c22ae251b55c86ad2a6e7a62edfa43b7be2cc629da1457532ddf9d7575450130
4
+ data.tar.gz: 32e9759bf95501a53b12f7813a085821867b3405c5cadf9f716a3306950e7a27
5
5
  SHA512:
6
- metadata.gz: eb8daebb6ba2b19abcb3ee3ce6070042b28b36e9d63d01bb9a35f367faacc228e8a1908a22631d08291d70f54d49e8b1f6d10bdb5403b9825b7bc6b8610cb7b2
7
- data.tar.gz: 9b9b8ab0afcb1670d6aa517d29299ab1e5887ed322e3f848db85d10b240a5c5ef8529dc93e55ea3406a7b5a1521ef2b14d68f250c52e988fe86a675e98aa7b57
6
+ metadata.gz: c7d249497e4f035ac74de379de666244269adf9139b79169d0f096b78873a04601a04fca173afa73e2171ea0aeeb7f7609c2e82d3f52f67f04094a7991525b36
7
+ data.tar.gz: e32900947434fa3af0a04db69cfaafa34ef7832f1820d6cb7f0273ccd73655983e046bd56b5570c73b5948baa2a118520c85d79ace60fa691d5015af01a8d7dd
data/.gitignore CHANGED
@@ -9,5 +9,9 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
12
13
  *.gem
14
+ *.lock
15
+ *.log
13
16
  .coveralls.yml
17
+ .ruby-version
data/.travis.yml CHANGED
@@ -1,17 +1,34 @@
1
1
  sudo: false
2
+
2
3
  language: ruby
4
+
3
5
  rvm:
4
- - 2.3.3
5
- - 2.4.2
6
- - 2.5.0
7
- - jruby
8
- before_install: gem install bundler -v 1.14.6
9
- env:
10
- - SEQUEL_VERSION='~> 4.0'
11
- - SEQUEL_VERSION='~> 5.0'
12
- gemfile:
13
- - gemfiles/ci.gemfile
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - 2.6
10
+ - jruby-9.2.8.0
11
+ - ruby-head
12
+ - jruby-head
13
+
14
+ before_install: gem install bundler
15
+
16
+ env: SEQUEL_VERSION="~> 5.0"
17
+
18
+ gemfile: gemfiles/ci.gemfile
19
+
14
20
  addons:
15
21
  postgresql: "9.6"
22
+
16
23
  services:
17
24
  - postgresql
25
+
26
+ matrix:
27
+ include:
28
+ - rvm: 2.6
29
+ env: SEQUEL_VERSION="~> 4.0"
30
+ allow_failures:
31
+ - rvm: ruby-head
32
+ env: SEQUEL_VERSION="~> 5.0"
33
+ - rvm: jruby-head
34
+ env: SEQUEL_VERSION="~> 5.0"
data/Gemfile CHANGED
@@ -1,6 +1,14 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
3
  # Specify your gem's dependencies in sequel-batches.gemspec
6
4
  gemspec
5
+
6
+ # MRI/Rubinius Adapter Dependencies
7
+ platforms :ruby do
8
+ gem "pg"
9
+ end
10
+
11
+ # JRuby Adapter Dependencies
12
+ platforms :jruby do
13
+ gem "jdbc-postgres"
14
+ end
data/README.md CHANGED
@@ -2,11 +2,23 @@
2
2
 
3
3
  This dataset extension provides the method #in_batches. The method splits dataset in parts and yields it.
4
4
 
5
- You can set following options:
6
- - pk Overrides primary key of your dataset
7
- - of sets chunk size (1000 by default)
8
- - start as a hash { [column]: <start_value> } represents frame start for batch processing
9
- - finish as a hash represents frame end
5
+ Note: currently only PostgreSQL database is supported.
6
+
7
+ You can set the following options:
8
+
9
+ ### pk
10
+ Overrides primary key of your dataset. This option is required in case your table doesn't have a real PK, otherwise you will get `Sequel::Extensions::Batches::MissingPKError`.
11
+
12
+ Note that you have to provide columns that don't contain NULL values, otherwise this may not work as intended. You will receive `Sequel::Extensions::Batches::NullPKError` in case batch processing detects a NULL value on it's way, but it's not guaranteed since it doesn't check all the rows for performance reasons.
13
+
14
+ ### of
15
+ Sets chunk size (1000 by default).
16
+
17
+ ### start
18
+ A hash `{ [column]: <start_value> }` that represents frame start for batch processing. Note that you will get `Sequel::Extensions::Batches::InvalidPKError` in case you provide a hash with wrong keys (ordering matters as well).
19
+
20
+ ### finish
21
+ Same as `start` but represents the frame end.
10
22
 
11
23
  ## Installation
12
24
 
data/gemfiles/ci.gemfile CHANGED
@@ -12,4 +12,4 @@ platforms :jruby do
12
12
  gem 'jdbc-postgres', '~> 9.4'
13
13
  end
14
14
 
15
- gem sequel, "#{ENV['SEQUEL_VERSION']}"
15
+ gem "sequel", "#{ENV['SEQUEL_VERSION']}"
@@ -1,7 +1,7 @@
1
1
  module Sequel
2
2
  module Extensions
3
3
  module Batches
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -5,63 +5,52 @@ module Sequel
5
5
  module Extensions
6
6
  module Batches
7
7
  MissingPKError = Class.new(StandardError)
8
+ NullPKError = Class.new(StandardError)
9
+ InvalidPKError = Class.new(StandardError)
8
10
 
9
- def in_batches(pk: nil, of: 1000, start: {}, finish: {})
10
- pk ||= self.db.schema(first_source)
11
- .select{|r| r[1][:primary_key]}
12
- .map(&:first) or raise MissingPKError
13
- qualified_pk = pk.map { |c| Sequel[first_source][c] }
11
+ def in_batches(pk: nil, of: 1000, start: nil, finish: nil)
12
+ pk ||= db.schema(first_source).select { |x| x[1][:primary_key] }.map(&:first)
13
+ raise MissingPKError if pk.empty?
14
14
 
15
- pk_expr = (-> (pk:) do
16
- pk.map do |col|
17
- colname = col.is_a?(Symbol) ? col : col.column
18
- Sequel.as(
19
- Sequel.pg_array(
20
- [
21
- Sequel.function(:min, col),
22
- Sequel.function(:max, col)
23
- ]
24
- ), :"#{colname}"
25
- )
26
- end
27
- end)
15
+ qualified_pk = pk.map { |x| Sequel[first_source][x] }
28
16
 
29
- entire_min_max = self.order(*pk).select(*pk_expr.call(pk: qualified_pk)).first
30
- min_max = {}
17
+ check_pk = lambda do |input_pk|
18
+ raise InvalidPKError if input_pk.keys != pk
19
+ input_pk
20
+ end
31
21
 
32
- range_expr = (-> (col, range) do
33
- Sequel.&(
34
- Sequel.expr(Sequel[first_source][col]) >= range[0],
35
- Sequel.expr(Sequel[first_source][col]) <= range[1],
36
- )
37
- end)
22
+ conditions = lambda do |pk, sign:|
23
+ raise NullPKError if pk.values.any?(&:nil?)
24
+ row_expr = Sequel.function(:row, *pk.values)
25
+ Sequel.function(:row, *qualified_pk).public_send(sign, row_expr)
26
+ end
38
27
 
39
- loop do
40
- pk.each do |col|
41
- entire_min_max[col][0] = start[col] || entire_min_max[col][0]
42
- entire_min_max[col][1] = finish[col] || entire_min_max[col][1]
43
- end
28
+ base_ds = order(*qualified_pk)
29
+ base_ds = base_ds.where(conditions.call(check_pk.call(start), sign: :>=)) if start
30
+ base_ds = base_ds.where(conditions.call(check_pk.call(finish), sign: :<=)) if finish
44
31
 
45
- ds = self.order(*qualified_pk).limit(of).where(
46
- Sequel.&(*pk.map { |col| range_expr.call(col, entire_min_max[col]) })
47
- )
48
- if min_max.present?
49
- pk_combinations = pk.each_with_index.map { |x, i| pk[0..-i] }
50
- ds = ds.where(Sequel.|(*pk_combinations.each_with_index.map do |pks, i|
51
- Sequel.&(*pks.each_with_index.map do |col, j|
52
- if j == i
53
- Sequel[first_source][col] > min_max[col].last
54
- else
55
- Sequel[first_source][col] >= min_max[col].last
56
- end
57
- end)
58
- end))
32
+ pk_ds = db.from(base_ds).select(*pk).order(*pk)
33
+ actual_start = pk_ds.first
34
+ actual_finish = pk_ds.last
35
+
36
+ return unless actual_start && actual_finish
37
+
38
+ base_ds = base_ds.where(conditions.call(actual_start, sign: :>=))
39
+ base_ds = base_ds.where(conditions.call(actual_finish, sign: :<=))
40
+
41
+ current_instance = nil
42
+
43
+ loop do
44
+ if current_instance
45
+ working_ds = base_ds.where(conditions.call(current_instance.to_h, sign: :>))
46
+ else
47
+ working_ds = base_ds
59
48
  end
60
49
 
61
- min_max = self.db.from(ds).select(*pk_expr.call(pk: pk)).first
50
+ current_instance = db.from(working_ds.limit(of)).select(*pk).order(*pk).last or break
51
+ working_ds = working_ds.where(conditions.call(current_instance.to_h, sign: :<=))
62
52
 
63
- break if min_max.values.flatten.any?(&:blank?)
64
- yield self.where(Sequel.&(*pk.map { |col| range_expr.call(col, min_max[col]) }))
53
+ yield working_ds
65
54
  end
66
55
  end
67
56
 
data/log/.keep ADDED
File without changes
@@ -30,10 +30,11 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_development_dependency "sequel", "~> 5.0"
34
- spec.add_development_dependency "bundler", "~> 1.16"
35
- spec.add_development_dependency "rake", "~> 10.0"
36
- spec.add_development_dependency "rspec", "~> 3.0"
37
- spec.add_development_dependency "pry", "~> 0.10"
33
+ spec.add_development_dependency "bundler"
38
34
  spec.add_development_dependency "coveralls"
35
+ spec.add_development_dependency "pry"
36
+ spec.add_development_dependency "rake"
37
+ spec.add_development_dependency "rspec"
38
+
39
+ spec.add_runtime_dependency "sequel"
39
40
  end
metadata CHANGED
@@ -1,94 +1,94 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-batches
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fiscal-cliff
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-28 00:00:00.000000000 Z
11
+ date: 2019-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: bundler
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - "~>"
17
+ - - ">="
17
18
  - !ruby/object:Gem::Version
18
- version: '5.0'
19
- name: sequel
20
- prerelease: false
19
+ version: '0'
21
20
  type: :development
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: coveralls
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - "~>"
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
- version: '1.16'
33
- name: bundler
34
- prerelease: false
33
+ version: '0'
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.16'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: pry
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - "~>"
45
+ - - ">="
45
46
  - !ruby/object:Gem::Version
46
- version: '10.0'
47
- name: rake
48
- prerelease: false
47
+ version: '0'
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: rake
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
- - - "~>"
59
+ - - ">="
59
60
  - !ruby/object:Gem::Version
60
- version: '3.0'
61
- name: rspec
62
- prerelease: false
61
+ version: '0'
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: rspec
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
- - - "~>"
73
+ - - ">="
73
74
  - !ruby/object:Gem::Version
74
- version: '0.10'
75
- name: pry
76
- prerelease: false
75
+ version: '0'
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '0.10'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
+ name: sequel
84
85
  requirement: !ruby/object:Gem::Requirement
85
86
  requirements:
86
87
  - - ">="
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
- name: coveralls
90
+ type: :runtime
90
91
  prerelease: false
91
- type: :development
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
@@ -103,28 +103,26 @@ extra_rdoc_files: []
103
103
  files:
104
104
  - ".gitignore"
105
105
  - ".rspec"
106
- - ".ruby-version"
107
106
  - ".travis.yml"
108
107
  - CODE_OF_CONDUCT.md
109
108
  - Gemfile
110
- - Gemfile.lock
111
109
  - LICENSE.txt
112
110
  - README.md
113
111
  - Rakefile
114
112
  - bin/console
115
113
  - bin/setup
116
114
  - gemfiles/ci.gemfile
117
- - gemfiles/ci.gemfile.lock
118
115
  - lib/sequel.rb
119
116
  - lib/sequel/extensions/batches.rb
120
117
  - lib/sequel/extensions/batches/version.rb
118
+ - log/.keep
121
119
  - sequel-batches.gemspec
122
120
  homepage: https://github.com/fiscal-cliff
123
121
  licenses:
124
122
  - MIT
125
123
  metadata:
126
124
  allowed_push_host: https://rubygems.org
127
- post_install_message:
125
+ post_install_message:
128
126
  rdoc_options: []
129
127
  require_paths:
130
128
  - lib
@@ -139,9 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
137
  - !ruby/object:Gem::Version
140
138
  version: '0'
141
139
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.6.14
144
- signing_key:
140
+ rubygems_version: 3.0.3
141
+ signing_key:
145
142
  specification_version: 4
146
143
  summary: The extension mimics AR5 batches api
147
144
  test_files: []
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- jruby-9.1.15.0
data/Gemfile.lock DELETED
@@ -1,70 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- sequel-batches (0.1.2)
5
- sequel (~> 5.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- coderay (1.1.2)
11
- coveralls (0.8.21)
12
- json (>= 1.8, < 3)
13
- simplecov (~> 0.14.1)
14
- term-ansicolor (~> 1.3)
15
- thor (~> 0.19.4)
16
- tins (~> 1.6)
17
- diff-lcs (1.3)
18
- docile (1.1.5)
19
- ffi (1.9.23-java)
20
- json (2.1.0)
21
- json (2.1.0-java)
22
- method_source (0.9.0)
23
- pry (0.11.3)
24
- coderay (~> 1.1.0)
25
- method_source (~> 0.9.0)
26
- pry (0.11.3-java)
27
- coderay (~> 1.1.0)
28
- method_source (~> 0.9.0)
29
- spoon (~> 0.0)
30
- rake (10.5.0)
31
- rspec (3.7.0)
32
- rspec-core (~> 3.7.0)
33
- rspec-expectations (~> 3.7.0)
34
- rspec-mocks (~> 3.7.0)
35
- rspec-core (3.7.1)
36
- rspec-support (~> 3.7.0)
37
- rspec-expectations (3.7.0)
38
- diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.7.0)
40
- rspec-mocks (3.7.0)
41
- diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.7.0)
43
- rspec-support (3.7.1)
44
- sequel (5.6.0)
45
- simplecov (0.14.1)
46
- docile (~> 1.1.0)
47
- json (>= 1.8, < 3)
48
- simplecov-html (~> 0.10.0)
49
- simplecov-html (0.10.2)
50
- spoon (0.0.6)
51
- ffi
52
- term-ansicolor (1.6.0)
53
- tins (~> 1.0)
54
- thor (0.19.4)
55
- tins (1.16.3)
56
-
57
- PLATFORMS
58
- java
59
- ruby
60
-
61
- DEPENDENCIES
62
- bundler (~> 1.16)
63
- coveralls
64
- pry (~> 0.10)
65
- rake (~> 10.0)
66
- rspec (~> 3.0)
67
- sequel-batches!
68
-
69
- BUNDLED WITH
70
- 1.16.1
@@ -1,74 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- sequel-batches (0.1.2)
5
- sequel (~> 5.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- coderay (1.1.2)
11
- coveralls (0.8.21)
12
- json (>= 1.8, < 3)
13
- simplecov (~> 0.14.1)
14
- term-ansicolor (~> 1.3)
15
- thor (~> 0.19.4)
16
- tins (~> 1.6)
17
- diff-lcs (1.3)
18
- docile (1.1.5)
19
- ffi (1.9.23-java)
20
- jdbc-postgres (9.4.1212)
21
- json (2.1.0)
22
- json (2.1.0-java)
23
- method_source (0.9.0)
24
- pg (0.20.0)
25
- pry (0.11.3)
26
- coderay (~> 1.1.0)
27
- method_source (~> 0.9.0)
28
- pry (0.11.3-java)
29
- coderay (~> 1.1.0)
30
- method_source (~> 0.9.0)
31
- spoon (~> 0.0)
32
- rake (10.5.0)
33
- rspec (3.7.0)
34
- rspec-core (~> 3.7.0)
35
- rspec-expectations (~> 3.7.0)
36
- rspec-mocks (~> 3.7.0)
37
- rspec-core (3.7.1)
38
- rspec-support (~> 3.7.0)
39
- rspec-expectations (3.7.0)
40
- diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.7.0)
42
- rspec-mocks (3.7.0)
43
- diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.7.0)
45
- rspec-support (3.7.1)
46
- sequel (5.6.0)
47
- simplecov (0.14.1)
48
- docile (~> 1.1.0)
49
- json (>= 1.8, < 3)
50
- simplecov-html (~> 0.10.0)
51
- simplecov-html (0.10.2)
52
- spoon (0.0.6)
53
- ffi
54
- term-ansicolor (1.6.0)
55
- tins (~> 1.0)
56
- thor (0.19.4)
57
- tins (1.16.3)
58
-
59
- PLATFORMS
60
- java
61
- ruby
62
-
63
- DEPENDENCIES
64
- bundler (~> 1.16)
65
- coveralls
66
- jdbc-postgres (~> 9.4)
67
- pg (~> 0.20.0)
68
- pry (~> 0.10)
69
- rake (~> 10.0)
70
- rspec (~> 3.0)
71
- sequel-batches!
72
-
73
- BUNDLED WITH
74
- 1.16.1