influxer 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +8 -0
- data/lib/influxer/config.rb +2 -1
- data/lib/influxer/metrics/quoting/timestamp.rb +40 -9
- data/lib/influxer/metrics/relation.rb +1 -3
- data/lib/influxer/version.rb +1 -1
- data/spec/metrics/relation_spec.rb +55 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34d7516d9e613074dcc24cf1c401bf69af544fa8
|
4
|
+
data.tar.gz: ea286c505a09b55058dc00fa05bebd1786c2de20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96fbc0c09e0127c7be545ffab4e0108a9ea26c7d471678c74095d35ce55827103357ce584b371e86cdd82200ff0ea86a63fb1f4ff61890e6d841b59de1618d35
|
7
|
+
data.tar.gz: 5e580bcbfebb8ca2d731cd658e81d7cd418dc90a4e423aac8ea47d5cb06ccdd409b4e938d6752be4f9b5955bbcede839a004c3ee77dd7fd103c01471a51e1a22
|
data/Changelog.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.1.4
|
6
|
+
|
7
|
+
- [Fixes [#35](https://github.com/palkan/influxer/issues/35)] Support time duration suffix and handle `'s'` and `'ms'` precisions. ([@palkan][])
|
8
|
+
|
9
|
+
[PR](https://github.com/palkan/influxer/pull/36)
|
10
|
+
|
11
|
+
**BREAKING:** `Time`-like value are only typecasted for `time` key.
|
12
|
+
|
5
13
|
## 1.1.2
|
6
14
|
|
7
15
|
- Support exclusive ranges as `where` arguments. ([@MPursche][])
|
data/lib/influxer/config.rb
CHANGED
@@ -2,24 +2,55 @@
|
|
2
2
|
|
3
3
|
module Influxer
|
4
4
|
module TimestampQuoting #:nodoc:
|
5
|
-
|
5
|
+
TIME_FACTORS = {
|
6
|
+
'ns' => 1_000_000_000,
|
7
|
+
'ms' => 1_000,
|
8
|
+
's' => 1
|
9
|
+
}.freeze
|
6
10
|
|
7
|
-
|
8
|
-
|
11
|
+
DEFAULT_PRECISION = 'ns'
|
12
|
+
|
13
|
+
# Quote timestamp
|
14
|
+
# rubocop: disable Metrics/MethodLength, Metrics/AbcSize
|
9
15
|
def quote_timestamp(val, client)
|
10
|
-
|
16
|
+
if Influxer.config.time_duration_suffix_enabled
|
17
|
+
precision = if TIME_FACTORS.keys.include?(client.time_precision)
|
18
|
+
client.time_precision
|
19
|
+
else
|
20
|
+
DEFAULT_PRECISION
|
21
|
+
end
|
22
|
+
return quote_timestamp_with_suffix(val, precision)
|
23
|
+
end
|
24
|
+
|
25
|
+
if !TIME_FACTORS.keys.include?(client.time_precision) &&
|
26
|
+
!val.is_a?(Numeric)
|
27
|
+
warn(
|
28
|
+
"Influxer doesn't automatically cast Time and String values " \
|
29
|
+
"to '#{client.time_precision}' precision. " \
|
30
|
+
"Please, convert to numeric value yourself"
|
31
|
+
)
|
32
|
+
return val
|
33
|
+
end
|
34
|
+
|
35
|
+
factorize_timestamp(val, TIME_FACTORS.fetch(client.time_precision))
|
36
|
+
end
|
37
|
+
# rubocop: enable Metrics/MethodLength, Metrics/AbcSize
|
38
|
+
|
39
|
+
def quote_timestamp_with_suffix(val, precision)
|
40
|
+
"#{factorize_timestamp(val, TIME_FACTORS.fetch(precision))}#{precision}"
|
41
|
+
end
|
11
42
|
|
43
|
+
def factorize_timestamp(val, factor)
|
12
44
|
case val
|
13
45
|
when Numeric
|
14
|
-
val.
|
46
|
+
(val.to_f * factor).to_i
|
15
47
|
when String
|
16
|
-
(Time.parse(val).to_r *
|
48
|
+
(Time.parse(val).to_r * factor).to_i
|
17
49
|
when Date, DateTime
|
18
|
-
(val.to_time.to_r *
|
50
|
+
(val.to_time.to_r * factor).to_i
|
19
51
|
when Time
|
20
|
-
(val.to_r *
|
52
|
+
(val.to_r * factor).to_i
|
21
53
|
end
|
22
54
|
end
|
23
|
-
# rubocop: enable Metrics/AbcSize, Metrics/MethodLength
|
24
55
|
end
|
25
56
|
end
|
@@ -268,17 +268,15 @@ module Influxer
|
|
268
268
|
self
|
269
269
|
end
|
270
270
|
|
271
|
-
# rubocop: disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
272
271
|
def quoted(val, key = nil)
|
273
272
|
if val.is_a?(String) || val.is_a?(Symbol) || @klass.tag?(key)
|
274
273
|
"'#{val}'"
|
275
|
-
elsif
|
274
|
+
elsif key.to_s == "time"
|
276
275
|
quote_timestamp val, @instance.client
|
277
276
|
else
|
278
277
|
val.to_s
|
279
278
|
end
|
280
279
|
end
|
281
|
-
# rubocop: enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
282
280
|
|
283
281
|
def get_points(list)
|
284
282
|
return list if normalized?
|
data/lib/influxer/version.rb
CHANGED
@@ -69,7 +69,7 @@ describe Influxer::Relation, :query do
|
|
69
69
|
describe "#where" do
|
70
70
|
it "generate valid conditions from hash" do
|
71
71
|
Timecop.freeze(Time.now)
|
72
|
-
expect(rel.where(user_id: 1, dummy: 'q',
|
72
|
+
expect(rel.where(user_id: 1, dummy: 'q', time: Time.now).to_sql).to eq "select * from \"dummy\" where (user_id = 1) and (dummy = 'q') and (time = #{(Time.now.to_r * 1_000_000_000).to_i})"
|
73
73
|
end
|
74
74
|
|
75
75
|
it "generate valid conditions from strings" do
|
@@ -81,11 +81,11 @@ describe Influxer::Relation, :query do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it "handle dates" do
|
84
|
-
expect(rel.where(
|
84
|
+
expect(rel.where(time: Date.new(2015)).to_sql).to eq "select * from \"dummy\" where (time = #{(Date.new(2015).to_time.to_r * 1_000_000_000).to_i})"
|
85
85
|
end
|
86
86
|
|
87
87
|
it "handle date times" do
|
88
|
-
expect(rel.where(
|
88
|
+
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})"
|
89
89
|
end
|
90
90
|
|
91
91
|
it "handle inclusive ranges" do
|
@@ -105,6 +105,58 @@ describe Influxer::Relation, :query do
|
|
105
105
|
expect(rel.to_a).to eq []
|
106
106
|
end
|
107
107
|
|
108
|
+
context "with timestamp duration" do
|
109
|
+
around do |ex|
|
110
|
+
old_duration = Influxer.config.time_duration_suffix_enabled
|
111
|
+
Influxer.config.time_duration_suffix_enabled = true
|
112
|
+
ex.run
|
113
|
+
Influxer.config.time_duration_suffix_enabled = old_duration
|
114
|
+
end
|
115
|
+
|
116
|
+
it "adds ns suffix to times" do
|
117
|
+
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)"
|
118
|
+
end
|
119
|
+
|
120
|
+
context "with different time_precision" do
|
121
|
+
around do |ex|
|
122
|
+
old_precision = Influxer.config.time_precision
|
123
|
+
Influxer.config.time_precision = 's'
|
124
|
+
ex.run
|
125
|
+
Influxer.config.time_precision = old_precision
|
126
|
+
end
|
127
|
+
|
128
|
+
it "adds s suffix to times" do
|
129
|
+
expect(rel.where(time: DateTime.new(2015)).to_sql).to eq "select * from \"dummy\" where (time = #{DateTime.new(2015).to_time.to_i}s)"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with unsupported time_precision" do
|
134
|
+
around do |ex|
|
135
|
+
old_precision = Influxer.config.time_precision
|
136
|
+
Influxer.config.time_precision = 'h'
|
137
|
+
ex.run
|
138
|
+
Influxer.config.time_precision = old_precision
|
139
|
+
end
|
140
|
+
|
141
|
+
it "casts to ns with suffix" do
|
142
|
+
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)"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "with different time_precision" do
|
148
|
+
around do |ex|
|
149
|
+
old_precision = Influxer.config.time_precision
|
150
|
+
Influxer.config.time_precision = 's'
|
151
|
+
ex.run
|
152
|
+
Influxer.config.time_precision = old_precision
|
153
|
+
end
|
154
|
+
|
155
|
+
it "casts to correct numeric representation" do
|
156
|
+
expect(rel.where(time: DateTime.new(2015)).to_sql).to eq "select * from \"dummy\" where (time = #{DateTime.new(2015).to_time.to_i})"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
108
160
|
context "with tags" do
|
109
161
|
it "integer tag values" do
|
110
162
|
expect(rel.where(dummy_id: 10).to_sql).to eq "select * from \"dummy\" where (dummy_id = '10')"
|
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.
|
4
|
+
version: 1.1.4
|
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-
|
11
|
+
date: 2018-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|