influxer 1.1.5 → 1.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7088f24ca98f504a152e38aff5f5ccc895eef65f1916aa5986bc425d9ef2d532
4
- data.tar.gz: 733e79c1bc8f7023fcb23032f519b7cfe5b7a61e373b1e7b213a821adcb29c43
3
+ metadata.gz: c454bccdf9c3272a5d359f23a8788a77c3b4a8475db929af0958eec10f5ca9b0
4
+ data.tar.gz: 2251b0e2015c90c1e1dbfd7bb3eb80d1838f4b16f897ebad8ac2b390e2c370fd
5
5
  SHA512:
6
- metadata.gz: 9f4217519c7c72281f1ed91fe9a22134a89be30f1e473f1ac06fc227599403d0b0d0938da7ebbbcc5f3e1c98f13916c560fb6692edbf59360d883be92766e65e
7
- data.tar.gz: 9e88838a7c84d1ac73be7a583e4bebcc73c48ef22f3bdab12eab0adce32350bb694094c6833a2c38089524d7c88dc58fb8917ba35a74c9e353a7c2a809ab2bfc
6
+ metadata.gz: 7ad48550cca618b24d924856782ab1fe0af754c36e4eb340ccbde6976c467de958e1fa2b85fe040501140e6bf6935358e0bad59f9c202bd94e780c073bc63623
7
+ data.tar.gz: 7bbb917021cedd9a6e23a9ff635d9fa3b0e93a28cf5c9312806a9d471af6ed342e0424372d8cae843ad6c6c95aeb813f755d54a741d7b2db4d4cbbde3865433b
@@ -9,6 +9,7 @@ AllCops:
9
9
  - 'spec/dummy/**/*'
10
10
  - 'vendor/**/*'
11
11
  - 'gemfiles/vendor/**/*'
12
+ - '**/*.gemfile'
12
13
  - Gemfile
13
14
  - Rakefile
14
15
  DisplayCopNames: true
@@ -18,6 +19,9 @@ AllCops:
18
19
  Rails:
19
20
  Enabled: false
20
21
 
22
+ Bundler/OrderedGems:
23
+ Enabled: false
24
+
21
25
  Style/SymbolArray:
22
26
  Enabled: false
23
27
 
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.1.6
6
+
7
+ - [Fixes [#41](https://github.com/palkan/influxer/issues/41)] Fix query building with empty arrays in `where` clause ([@dimiii][])
8
+
9
+ [PR](https://github.com/palkan/influxer/pull/44)
10
+
11
+ **BREAKING:** `where.not` now returns non-empty result for an empty array.
12
+
13
+ - Support of year alias in queries ([@dimiii][])
14
+
15
+ - [Fixes [#40](https://github.com/palkan/influxer/issues/40)] Avoid adding precision suffix to write queries. ([@palkan][])
16
+
5
17
  ## 1.1.5
6
18
 
7
19
  - [Fixes [#37](https://github.com/palkan/influxer/issues/37)] Timestamp ranges are quoted again. ([@jklimke][])
@@ -113,4 +125,5 @@ end
113
125
 
114
126
  [@palkan]: https://github.com/palkan
115
127
  [@MPursche]: https://github.com/MPursche
116
- [@jklimke]: https://github.com/jklimke
128
+ [@jklimke]: https://github.com/jklimke
129
+ [@dimiii]: https://github.com/dimiii
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
4
 
5
5
  require "influxer/version"
6
6
 
@@ -18,7 +18,6 @@ module Influxer
18
18
  else
19
19
  include ActiveModel::Model
20
20
  end
21
- # rubocop:enable Style/MixinUsage
22
21
 
23
22
  include ActiveModel::Validations
24
23
  extend ActiveModel::Callbacks
@@ -225,10 +224,8 @@ module Influxer
225
224
  end
226
225
 
227
226
  def parsed_timestamp
228
- quote_timestamp @timestamp, client
227
+ quote_timestamp_for_write @timestamp, client
229
228
  end
230
- # rubocop:enable Metrics/MethodLength
231
- # rubocop:enable Metrics/AbcSize
232
229
 
233
230
  def unquote(name)
234
231
  name.gsub(/(\A['"]|['"]\z)/, '')
@@ -40,6 +40,18 @@ module Influxer
40
40
  "#{factorize_timestamp(val, TIME_FACTORS.fetch(precision))}#{precision}"
41
41
  end
42
42
 
43
+ def quote_timestamp_for_write(val, client)
44
+ if !TIME_FACTORS.keys.include?(client.time_precision) &&
45
+ !val.is_a?(Numeric)
46
+ raise ArgumentError,
47
+ "Influxer doesn't support quoting #{val} " \
48
+ " with '#{client.time_precision}' precision. " \
49
+ "Please, convert to numeric value yourself"
50
+ end
51
+
52
+ factorize_timestamp(val, TIME_FACTORS.fetch(client.time_precision))
53
+ end
54
+
43
55
  def factorize_timestamp(val, factor)
44
56
  case val
45
57
  when Numeric
@@ -10,7 +10,8 @@ module Influxer
10
10
  u: '1u',
11
11
  week: '1w',
12
12
  day: '1d',
13
- month: '30d'
13
+ month: '30d',
14
+ year: '365d'
14
15
  }.freeze
15
16
 
16
17
  FILL_RESERVED = %i[null previous none].freeze
@@ -59,7 +59,7 @@ module Influxer
59
59
  when Regexp
60
60
  "#{key}#{negate ? ' !~ ' : ' =~ '}#{val.inspect}"
61
61
  when Array
62
- return build_none if val.empty?
62
+ return build_none(negate) if val.empty?
63
63
  build_in(key, val, negate)
64
64
  when Range
65
65
  build_range(key, val, negate)
@@ -98,9 +98,9 @@ module Influxer
98
98
  end
99
99
  # rubocop: enable Metrics/AbcSize, Metrics/MethodLength, Style/IfInsideElse
100
100
 
101
- def build_none
102
- @null_relation = true
103
- build_eql(1, 0, false)
101
+ def build_none(negate = false)
102
+ @null_relation = !negate
103
+ negate ? 'time >= 0' : 'time < 0'
104
104
  end
105
105
  end
106
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Influxer # :nodoc:
4
- VERSION = "1.1.5"
4
+ VERSION = "1.1.6"
5
5
  end
@@ -269,6 +269,52 @@ describe Influxer::Metrics, :query do
269
269
  expect(point.timestamp).to eq(timestamp_test)
270
270
  end
271
271
 
272
+ context "with non-default precision", precision: :s do
273
+ it "test write timestamp with the specified precision" do
274
+ base_time = Time.now
275
+ timestamp_test = base_time.to_s
276
+ expected_time = base_time.to_i
277
+
278
+ expect(client)
279
+ .to receive(:write_point).with(
280
+ "dummies",
281
+ { tags: { dummy_id: 2, host: 'test' }, values: { user_id: 1 }, timestamp: expected_time },
282
+ nil,
283
+ nil,
284
+ nil
285
+ )
286
+
287
+ point = dummy_metrics.write(user_id: 1, dummy_id: 2, host: 'test', timestamp: timestamp_test)
288
+ expect(point.persisted?).to be_truthy
289
+ expect(point.user_id).to eq 1
290
+ expect(point.dummy_id).to eq 2
291
+ expect(point.timestamp).to eq(timestamp_test)
292
+ end
293
+ end
294
+
295
+ context "when duration suffix is enabled", :duration_suffix do
296
+ it "test write timestamp without suffix" do
297
+ base_time = Time.now
298
+ timestamp_test = base_time.to_s
299
+ expected_time = (base_time.to_i * 1_000_000_000).to_i
300
+
301
+ expect(client)
302
+ .to receive(:write_point).with(
303
+ "dummies",
304
+ { tags: { dummy_id: 2, host: 'test' }, values: { user_id: 1 }, timestamp: expected_time },
305
+ nil,
306
+ nil,
307
+ nil
308
+ )
309
+
310
+ point = dummy_metrics.write(user_id: 1, dummy_id: 2, host: 'test', timestamp: timestamp_test)
311
+ expect(point.persisted?).to be_truthy
312
+ expect(point.user_id).to eq 1
313
+ expect(point.dummy_id).to eq 2
314
+ expect(point.timestamp).to eq(timestamp_test)
315
+ end
316
+ end
317
+
272
318
  it "doesn't write data and return false if invalid" do
273
319
  expect(client).not_to receive(:write_point)
274
320
  expect(DummyMetrics.write(dummy_id: 2)).to be false
@@ -109,30 +109,16 @@ describe Influxer::Relation, :query do
109
109
  end
110
110
 
111
111
  it "handle empty arrays", :aggregate_failures do
112
- expect(rel.where(user_id: []).to_sql).to eq "select * from \"dummy\" where (1 = 0)"
112
+ expect(rel.where(user_id: []).to_sql).to eq "select * from \"dummy\" where (time < 0)"
113
113
  expect(rel.to_a).to eq []
114
114
  end
115
115
 
116
- context "with timestamp duration" do
117
- around do |ex|
118
- old_duration = Influxer.config.time_duration_suffix_enabled
119
- Influxer.config.time_duration_suffix_enabled = true
120
- ex.run
121
- Influxer.config.time_duration_suffix_enabled = old_duration
122
- end
123
-
116
+ context "with timestamp duration", :duration_suffix do
124
117
  it "adds ns suffix to times" do
125
118
  expect(rel.where(time: DateTime.new(2015)).to_sql).to eq "select * from \"dummy\" where (time = #{(DateTime.new(2015).to_time.to_r * 1_000_000_000).to_i}ns)"
126
119
  end
127
120
 
128
- context "with different time_precision" do
129
- around do |ex|
130
- old_precision = Influxer.config.time_precision
131
- Influxer.config.time_precision = 's'
132
- ex.run
133
- Influxer.config.time_precision = old_precision
134
- end
135
-
121
+ context "with different time_precision", precision: :s do
136
122
  it "adds s suffix to times" do
137
123
  expect(rel.where(time: DateTime.new(2015)).to_sql).to eq "select * from \"dummy\" where (time = #{DateTime.new(2015).to_time.to_i}s)"
138
124
  end
@@ -152,14 +138,7 @@ describe Influxer::Relation, :query do
152
138
  end
153
139
  end
154
140
 
155
- context "with different time_precision" do
156
- around do |ex|
157
- old_precision = Influxer.config.time_precision
158
- Influxer.config.time_precision = 's'
159
- ex.run
160
- Influxer.config.time_precision = old_precision
161
- end
162
-
141
+ context "with different time_precision", precision: :s do
163
142
  it "casts to correct numeric representation" do
164
143
  expect(rel.where(time: DateTime.new(2015)).to_sql).to eq "select * from \"dummy\" where (time = #{DateTime.new(2015).to_time.to_i})"
165
144
  end
@@ -202,8 +181,7 @@ describe Influxer::Relation, :query do
202
181
  end
203
182
 
204
183
  it "handle empty arrays", :aggregate_failures do
205
- expect(rel.where.not(user_id: []).to_sql).to eq "select * from \"dummy\" where (1 = 0)"
206
- expect(rel.to_a).to eq []
184
+ expect(rel.where.not(user_id: []).to_sql).to eq "select * from \"dummy\" where (time >= 0)"
207
185
  end
208
186
 
209
187
  context "with tags" do
@@ -215,13 +193,13 @@ describe Influxer::Relation, :query do
215
193
 
216
194
  describe "#none" do
217
195
  it "returns empty array", :aggregate_failures do
218
- expect(rel.none.to_sql).to eq "select * from \"dummy\" where (1 = 0)"
196
+ expect(rel.none.to_sql).to eq "select * from \"dummy\" where (time < 0)"
219
197
  expect(rel.to_a).to eq []
220
198
  end
221
199
 
222
200
  it "works with chaining", :aggregate_failures do
223
201
  expect(rel.none.where.not(user_id: 1, dummy: :a).to_sql)
224
- .to eq "select * from \"dummy\" where (1 = 0) and (user_id <> 1) and (dummy <> 'a')"
202
+ .to eq "select * from \"dummy\" where (time < 0) and (user_id <> 1) and (dummy <> 'a')"
225
203
  expect(rel.to_a).to eq []
226
204
  end
227
205
  end
@@ -288,6 +266,10 @@ describe Influxer::Relation, :query do
288
266
  expect(rel.time(:month).to_sql).to eq "select * from \"dummy\" group by time(30d)"
289
267
  end
290
268
 
269
+ it "group by year" do
270
+ expect(rel.time(:year).to_sql).to eq "select * from \"dummy\" group by time(365d)"
271
+ end
272
+
291
273
  it "group by hour and fill" do
292
274
  expect(rel.time(:month, fill: 0).to_sql).to eq "select * from \"dummy\" group by time(30d) fill(0)"
293
275
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ shared_context "precision:seconds", precision: :s do
4
+ around do |ex|
5
+ old_precision = Influxer.config.time_precision
6
+ Influxer.config.time_precision = 's'
7
+ ex.run
8
+ Influxer.config.time_precision = old_precision
9
+ end
10
+ end
11
+
12
+ shared_context "with_duration_suffix", duration_suffix: true do
13
+ around do |ex|
14
+ old_duration = Influxer.config.time_duration_suffix_enabled
15
+ Influxer.config.time_duration_suffix_enabled = true
16
+ ex.run
17
+ Influxer.config.time_duration_suffix_enabled = old_duration
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Dem
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-19 00:00:00.000000000 Z
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -232,6 +232,7 @@ files:
232
232
  - spec/support/metrics/dummy_metrics.rb
233
233
  - spec/support/metrics/user_metrics.rb
234
234
  - spec/support/metrics/visits_metrics.rb
235
+ - spec/support/shared_contexts/shared_precision.rb
235
236
  - spec/support/shared_contexts/shared_query.rb
236
237
  - spec/support/user.rb
237
238
  homepage: http://github.com/palkan/influxer