influxer 1.1.2 → 1.1.3
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/.rubocop.yml +4 -0
- data/Changelog.md +20 -1
- data/lib/influxer/metrics/metrics.rb +3 -16
- data/lib/influxer/metrics/quoting/timestamp.rb +25 -0
- data/lib/influxer/metrics/relation.rb +6 -2
- data/lib/influxer/metrics/relation/where_clause.rb +15 -3
- data/lib/influxer/version.rb +1 -1
- data/spec/metrics/relation_spec.rb +21 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36dc815f87b5baba491093838e46cf60537af9eb
|
4
|
+
data.tar.gz: 3149c0e7950e1986bfefeb78cec5bf8e3b334596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9555072584dbcb205fafdf5f82615430d729a8e7b56962bda588c1b8319b3c5e2b6a07c238705bb1bec8737b39d85852e63d8dd3bdbd0a7483ba441bb512e806
|
7
|
+
data.tar.gz: b2b26a45612366170dba61278e5fb3fbeb0ae56b802bf652b8db90fcf4b63372eb3a33386d791fb605c3668a27b3e399001a608df4a156e4755fb15dbfb36f96
|
data/.rubocop.yml
CHANGED
data/Changelog.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## master
|
4
|
+
|
5
|
+
## 1.1.2
|
6
|
+
|
7
|
+
- Support exclusive ranges as `where` arguments. ([@MPursche][])
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
# range including the end
|
11
|
+
where(a: 1..4)
|
12
|
+
#=> ... WHERE a >= 1 AND a <= 4
|
13
|
+
|
14
|
+
#range excluding the end
|
15
|
+
where(a: 1...4)
|
16
|
+
#=> ... WHERE a >= 1 AND a < 4
|
17
|
+
```
|
18
|
+
|
3
19
|
## 1.1.1
|
4
20
|
|
5
21
|
- [Fixes [#31](https://github.com/palkan/influxer/issues/31)] Fix bug with empty arrays in `where` clause
|
@@ -81,4 +97,7 @@ end
|
|
81
97
|
- Add `delete_all` support
|
82
98
|
- Add cache support (using `Rails.cache`)
|
83
99
|
- Scopes (default and named)
|
84
|
-
- Support for fanout series
|
100
|
+
- Support for fanout series
|
101
|
+
|
102
|
+
[@palkan]: https://github.com/palkan
|
103
|
+
[@MPursche]: https://github.com/MPursche
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'influxer/metrics/relation'
|
4
4
|
require 'influxer/metrics/scoping'
|
5
|
+
require 'influxer/metrics/quoting/timestamp'
|
5
6
|
require 'influxer/metrics/active_model3/model'
|
6
7
|
|
7
8
|
module Influxer
|
@@ -12,8 +13,6 @@ module Influxer
|
|
12
13
|
# rubocop:disable Metrics/ClassLength
|
13
14
|
class Metrics
|
14
15
|
TIME_FACTOR = 1_000_000_000
|
15
|
-
|
16
|
-
# rubocop:disable Style/MixinUsage
|
17
16
|
if Influxer.active_model3?
|
18
17
|
include Influxer::ActiveModel3::Model
|
19
18
|
else
|
@@ -25,6 +24,7 @@ module Influxer
|
|
25
24
|
extend ActiveModel::Callbacks
|
26
25
|
|
27
26
|
include Influxer::Scoping
|
27
|
+
include Influxer::TimestampQuoting
|
28
28
|
|
29
29
|
define_model_callbacks :write
|
30
30
|
|
@@ -224,21 +224,8 @@ module Influxer
|
|
224
224
|
self.class.database)
|
225
225
|
end
|
226
226
|
|
227
|
-
# rubocop:disable Metrics/MethodLength
|
228
|
-
# rubocop:disable Metrics/AbcSize
|
229
227
|
def parsed_timestamp
|
230
|
-
|
231
|
-
|
232
|
-
case @timestamp
|
233
|
-
when Numeric
|
234
|
-
@timestamp.to_i.to_s.ljust(19, '0').to_i
|
235
|
-
when String
|
236
|
-
(Time.parse(@timestamp).to_r * TIME_FACTOR).to_i
|
237
|
-
when Date
|
238
|
-
(@timestamp.to_time.to_r * TIME_FACTOR).to_i
|
239
|
-
when Time
|
240
|
-
(@timestamp.to_r * TIME_FACTOR).to_i
|
241
|
-
end
|
228
|
+
quote_timestamp @timestamp, client
|
242
229
|
end
|
243
230
|
# rubocop:enable Metrics/MethodLength
|
244
231
|
# rubocop:enable Metrics/AbcSize
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Influxer
|
4
|
+
module TimestampQuoting #:nodoc:
|
5
|
+
TIME_FACTOR = 1_000_000_000
|
6
|
+
|
7
|
+
# Quote timestamp as ns
|
8
|
+
# rubocop: disable Metrics/AbcSize, Metrics/MethodLength
|
9
|
+
def quote_timestamp(val, client)
|
10
|
+
return val unless client.time_precision == 'ns'
|
11
|
+
|
12
|
+
case val
|
13
|
+
when Numeric
|
14
|
+
val.to_i.to_s.ljust(19, '0').to_i
|
15
|
+
when String
|
16
|
+
(Time.parse(val).to_r * TIME_FACTOR).to_i
|
17
|
+
when Date, DateTime
|
18
|
+
(val.to_time.to_r * TIME_FACTOR).to_i
|
19
|
+
when Time
|
20
|
+
(val.to_r * TIME_FACTOR).to_i
|
21
|
+
end
|
22
|
+
end
|
23
|
+
# rubocop: enable Metrics/AbcSize, Metrics/MethodLength
|
24
|
+
end
|
25
|
+
end
|
@@ -4,6 +4,7 @@ require 'active_support/core_ext/module/delegation'
|
|
4
4
|
require 'influxer/metrics/relation/time_query'
|
5
5
|
require 'influxer/metrics/relation/calculations'
|
6
6
|
require 'influxer/metrics/relation/where_clause'
|
7
|
+
require 'influxer/metrics/quoting/timestamp'
|
7
8
|
|
8
9
|
module Influxer
|
9
10
|
# Relation is used to build queries
|
@@ -11,6 +12,7 @@ module Influxer
|
|
11
12
|
class Relation
|
12
13
|
include Influxer::TimeQuery
|
13
14
|
include Influxer::Calculations
|
15
|
+
include Influxer::TimestampQuoting
|
14
16
|
prepend Influxer::WhereClause
|
15
17
|
|
16
18
|
attr_reader :values
|
@@ -266,15 +268,17 @@ module Influxer
|
|
266
268
|
self
|
267
269
|
end
|
268
270
|
|
271
|
+
# rubocop: disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
269
272
|
def quoted(val, key = nil)
|
270
273
|
if val.is_a?(String) || val.is_a?(Symbol) || @klass.tag?(key)
|
271
274
|
"'#{val}'"
|
272
|
-
elsif val.is_a?(Time) || val.is_a?(DateTime)
|
273
|
-
|
275
|
+
elsif val.is_a?(Time) || val.is_a?(Date) || val.is_a?(DateTime)
|
276
|
+
quote_timestamp val, @instance.client
|
274
277
|
else
|
275
278
|
val.to_s
|
276
279
|
end
|
277
280
|
end
|
281
|
+
# rubocop: enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
278
282
|
|
279
283
|
def get_points(list)
|
280
284
|
return list if normalized?
|
@@ -78,13 +78,25 @@ module Influxer
|
|
78
78
|
buf.join(negate ? ' and ' : ' or ').to_s
|
79
79
|
end
|
80
80
|
|
81
|
+
# rubocop: disable Metrics/AbcSize, Metrics/MethodLength, Style/IfInsideElse
|
81
82
|
def build_range(key, val, negate)
|
82
|
-
if
|
83
|
-
|
83
|
+
if val.exclude_end?
|
84
|
+
# begin...end range
|
85
|
+
if negate
|
86
|
+
"#{key} < #{quoted(val.begin)} or #{key} >= #{quoted(val.end)}"
|
87
|
+
else
|
88
|
+
"#{key} >= #{quoted(val.begin)} and #{key} < #{quoted(val.end)}"
|
89
|
+
end
|
84
90
|
else
|
85
|
-
|
91
|
+
# begin..end range
|
92
|
+
if negate
|
93
|
+
"#{key} < #{quoted(val.begin)} or #{key} > #{quoted(val.end)}"
|
94
|
+
else
|
95
|
+
"#{key} >= #{quoted(val.begin)} and #{key} <= #{quoted(val.end)}"
|
96
|
+
end
|
86
97
|
end
|
87
98
|
end
|
99
|
+
# rubocop: enable Metrics/AbcSize, Metrics/MethodLength, Style/IfInsideElse
|
88
100
|
|
89
101
|
def build_none
|
90
102
|
@null_relation = true
|
data/lib/influxer/version.rb
CHANGED
@@ -67,9 +67,9 @@ describe Influxer::Relation, :query do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
describe "#where" do
|
70
|
-
it "
|
70
|
+
it "generate valid conditions from hash" do
|
71
71
|
Timecop.freeze(Time.now)
|
72
|
-
expect(rel.where(user_id: 1, dummy: 'q', timer: Time.now).to_sql).to eq "select * from \"dummy\" where (user_id = 1) and (dummy = 'q') and (timer = #{Time.now.to_i}
|
72
|
+
expect(rel.where(user_id: 1, dummy: 'q', timer: Time.now).to_sql).to eq "select * from \"dummy\" where (user_id = 1) and (dummy = 'q') and (timer = #{(Time.now.to_r * 1_000_000_000).to_i})"
|
73
73
|
end
|
74
74
|
|
75
75
|
it "generate valid conditions from strings" do
|
@@ -80,8 +80,20 @@ describe Influxer::Relation, :query do
|
|
80
80
|
expect(rel.where(user_id: 1, dummy: /^du.*/).to_sql).to eq "select * from \"dummy\" where (user_id = 1) and (dummy =~ /^du.*/)"
|
81
81
|
end
|
82
82
|
|
83
|
-
it "handle
|
84
|
-
expect(rel.where(
|
83
|
+
it "handle dates" do
|
84
|
+
expect(rel.where(timer: Date.new(2015)).to_sql).to eq "select * from \"dummy\" where (timer = #{(Date.new(2015).to_time.to_r * 1_000_000_000).to_i})"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "handle date times" do
|
88
|
+
expect(rel.where(timer: DateTime.new(2015)).to_sql).to eq "select * from \"dummy\" where (timer = #{(DateTime.new(2015).to_time.to_r * 1_000_000_000).to_i})"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "handle inclusive ranges" do
|
92
|
+
expect(rel.where(user_id: 1..4).to_sql).to eq "select * from \"dummy\" where (user_id >= 1 and user_id <= 4)"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "handle exclusive range" do
|
96
|
+
expect(rel.where(user_id: 1...4).to_sql).to eq "select * from \"dummy\" where (user_id >= 1 and user_id < 4)"
|
85
97
|
end
|
86
98
|
|
87
99
|
it "handle arrays" do
|
@@ -117,10 +129,14 @@ describe Influxer::Relation, :query do
|
|
117
129
|
expect(rel.where.not(user_id: 1, dummy: /^du.*/).to_sql).to eq "select * from \"dummy\" where (user_id <> 1) and (dummy !~ /^du.*/)"
|
118
130
|
end
|
119
131
|
|
120
|
-
it "handle ranges" do
|
132
|
+
it "handle inclusive ranges" do
|
121
133
|
expect(rel.where.not(user_id: 1..4).to_sql).to eq "select * from \"dummy\" where (user_id < 1 or user_id > 4)"
|
122
134
|
end
|
123
135
|
|
136
|
+
it "handle exclusive ranges" do
|
137
|
+
expect(rel.where.not(user_id: 1...4).to_sql).to eq "select * from \"dummy\" where (user_id < 1 or user_id >= 4)"
|
138
|
+
end
|
139
|
+
|
124
140
|
it "handle arrays" do
|
125
141
|
expect(rel.where.not(user_id: [1, 2, 3]).to_sql).to eq "select * from \"dummy\" where (user_id <> 1 and user_id <> 2 and user_id <> 3)"
|
126
142
|
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.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Dem
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -204,6 +204,7 @@ files:
|
|
204
204
|
- lib/influxer/engine.rb
|
205
205
|
- lib/influxer/metrics/active_model3/model.rb
|
206
206
|
- lib/influxer/metrics/metrics.rb
|
207
|
+
- lib/influxer/metrics/quoting/timestamp.rb
|
207
208
|
- lib/influxer/metrics/relation.rb
|
208
209
|
- lib/influxer/metrics/relation/calculations.rb
|
209
210
|
- lib/influxer/metrics/relation/time_query.rb
|