influxer 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -2
- data/.travis.yml +1 -1
- data/Changelog.md +5 -0
- data/README.md +1 -1
- data/gemfiles/rails42.gemfile +0 -3
- data/influxer.gemspec +1 -1
- data/lib/influxer/metrics/metrics.rb +9 -5
- data/lib/influxer/metrics/relation.rb +17 -12
- data/lib/influxer/metrics/relation/calculations.rb +2 -3
- data/lib/influxer/metrics/relation/time_query.rb +5 -5
- data/lib/influxer/metrics/relation/where_clause.rb +11 -5
- data/lib/influxer/metrics/scoping.rb +2 -2
- data/lib/influxer/metrics/scoping/named.rb +1 -1
- data/lib/influxer/model.rb +1 -4
- data/lib/influxer/rails/client.rb +1 -1
- data/lib/influxer/version.rb +1 -1
- data/spec/metrics/metrics_spec.rb +5 -5
- data/spec/metrics/relation_spec.rb +37 -23
- data/spec/metrics/scoping_spec.rb +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a56f1b17d497e12281a8ae86939c49f83d2037dc
|
4
|
+
data.tar.gz: c64d0f15b9a76e2fdd8190be12914c315651d166
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2250060657155d5454d9a4603a1cb5d589f5ce3b66d66091c2d0267ec0e50968ebd0851811bb10bce1f655ab88a239741eb979343321fc4b30b8bd779e4e25a
|
7
|
+
data.tar.gz: 1ada172a89d606bb1d19399318c0976108ff5c7084ed68d274df07954550484dca58d2ec82474e1b3d11f54d6de98425441ccdc7883d1071a96acb196b7aae8c
|
data/.rubocop.yml
CHANGED
@@ -7,10 +7,12 @@ AllCops:
|
|
7
7
|
Exclude:
|
8
8
|
- 'bin/**/*'
|
9
9
|
- 'spec/dummy/**/*'
|
10
|
-
RunRailsCops: true
|
11
10
|
DisplayCopNames: true
|
12
11
|
StyleGuideCopsOnly: false
|
13
12
|
|
13
|
+
Rails:
|
14
|
+
Enabled: true
|
15
|
+
|
14
16
|
Style/AccessorMethodName:
|
15
17
|
Enabled: false
|
16
18
|
|
@@ -47,4 +49,4 @@ Rails/Date:
|
|
47
49
|
Enabled: false
|
48
50
|
|
49
51
|
Rails/TimeZone:
|
50
|
-
Enabled: false
|
52
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/influxer.svg)](https://rubygems.org/gems/influxer) [![Build Status](https://travis-ci.org/palkan/influxer.svg?branch=master)](https://travis-ci.org/palkan/influxer)
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/influxer.svg)](https://rubygems.org/gems/influxer) [![Build Status](https://travis-ci.org/palkan/influxer.svg?branch=master)](https://travis-ci.org/palkan/influxer)
|
2
2
|
## Influxer
|
3
3
|
|
4
4
|
**NOTE**: Version 0.3.x supports InfluxDB >= 0.9.0. For InfluxDB 0.8.x use [version 0.2.5](https://github.com/palkan/influxer/tree/0.2.5).
|
data/gemfiles/rails42.gemfile
CHANGED
data/influxer.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
|
18
18
|
s.add_dependency "activemodel", '>= 4.0'
|
19
|
-
s.add_dependency "influxdb", "~> 0.
|
19
|
+
s.add_dependency "influxdb", "~> 0.3"
|
20
20
|
s.add_dependency "anyway_config", "~>0.3.0"
|
21
21
|
|
22
22
|
s.add_development_dependency "timecop"
|
@@ -40,7 +40,7 @@ module Influxer
|
|
40
40
|
@attributes[name] = val
|
41
41
|
end
|
42
42
|
|
43
|
-
define_method(
|
43
|
+
define_method(name.to_s) do
|
44
44
|
@attributes[name]
|
45
45
|
end
|
46
46
|
end
|
@@ -102,7 +102,7 @@ module Influxer
|
|
102
102
|
quoted_series(val.first)
|
103
103
|
end
|
104
104
|
else
|
105
|
-
'"' + val.to_s.gsub(/\"/) {
|
105
|
+
'"' + val.to_s.gsub(/\"/) { '\"' } + '"'
|
106
106
|
end
|
107
107
|
end
|
108
108
|
# rubocop:enable Metrics/MethodLength
|
@@ -118,9 +118,9 @@ module Influxer
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def write
|
121
|
-
|
121
|
+
raise MetricsError if persisted?
|
122
122
|
|
123
|
-
return false if
|
123
|
+
return false if invalid?
|
124
124
|
|
125
125
|
run_callbacks :write do
|
126
126
|
write_point
|
@@ -129,7 +129,7 @@ module Influxer
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def write!
|
132
|
-
|
132
|
+
raise MetricsInvalid if invalid?
|
133
133
|
write
|
134
134
|
end
|
135
135
|
|
@@ -166,6 +166,8 @@ module Influxer
|
|
166
166
|
|
167
167
|
private
|
168
168
|
|
169
|
+
# rubocop:disable Metrics/MethodLength
|
170
|
+
# rubocop:disable Metrics/AbcSize
|
169
171
|
def parsed_timestamp
|
170
172
|
return @timestamp unless client.time_precision == 'ns'
|
171
173
|
|
@@ -180,6 +182,8 @@ module Influxer
|
|
180
182
|
(@timestamp.to_r * TIME_FACTOR).to_i
|
181
183
|
end
|
182
184
|
end
|
185
|
+
# rubocop:enable Metrics/MethodLength
|
186
|
+
# rubocop:enable Metrics/AbcSize
|
183
187
|
|
184
188
|
def unquote(name)
|
185
189
|
name.gsub(/(\A['"]|['"]\z)/, '')
|
@@ -12,17 +12,17 @@ module Influxer
|
|
12
12
|
|
13
13
|
attr_reader :values
|
14
14
|
|
15
|
-
SUPPORTED_EPOCH_FORMAT =
|
15
|
+
SUPPORTED_EPOCH_FORMAT = %i(h m s ms u ns).freeze
|
16
16
|
|
17
|
-
MULTI_VALUE_METHODS =
|
17
|
+
MULTI_VALUE_METHODS = %i(select where group order).freeze
|
18
18
|
|
19
|
-
MULTI_KEY_METHODS =
|
19
|
+
MULTI_KEY_METHODS = %i(fanout).freeze
|
20
20
|
|
21
|
-
SINGLE_VALUE_METHODS =
|
21
|
+
SINGLE_VALUE_METHODS = %i(fill time limit offset slimit soffset from normalized).freeze
|
22
22
|
|
23
|
-
MULTI_VALUE_SIMPLE_METHODS =
|
23
|
+
MULTI_VALUE_SIMPLE_METHODS = %i(select group).freeze
|
24
24
|
|
25
|
-
SINGLE_VALUE_SIMPLE_METHODS =
|
25
|
+
SINGLE_VALUE_SIMPLE_METHODS = %i(fill limit offset slimit soffset from).freeze
|
26
26
|
|
27
27
|
MULTI_VALUE_METHODS.each do |name|
|
28
28
|
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
@@ -100,7 +100,7 @@ module Influxer
|
|
100
100
|
point
|
101
101
|
end
|
102
102
|
|
103
|
-
|
103
|
+
alias new build
|
104
104
|
|
105
105
|
def normalized
|
106
106
|
@values[:normalized] = true
|
@@ -136,7 +136,7 @@ module Influxer
|
|
136
136
|
sql = ["select"]
|
137
137
|
select_values << "*" if select_values.empty?
|
138
138
|
|
139
|
-
sql << select_values.uniq.join(",")
|
139
|
+
sql << select_values.uniq.join(", ")
|
140
140
|
|
141
141
|
sql << "from #{build_series_name}"
|
142
142
|
|
@@ -145,7 +145,7 @@ module Influxer
|
|
145
145
|
unless group_values.empty? && time_value.nil?
|
146
146
|
group_fields = (time_value.nil? ? [] : ['time(' + @values[:time] + ')']) + group_values
|
147
147
|
group_fields.uniq!
|
148
|
-
sql << "group by #{group_fields.join(',')}"
|
148
|
+
sql << "group by #{group_fields.join(', ')}"
|
149
149
|
end
|
150
150
|
|
151
151
|
sql << "fill(#{fill_value})" unless fill_value.nil?
|
@@ -189,7 +189,11 @@ module Influxer
|
|
189
189
|
end
|
190
190
|
|
191
191
|
def load
|
192
|
-
@records = get_points(
|
192
|
+
@records = get_points(
|
193
|
+
@instance.client.query(
|
194
|
+
to_sql,
|
195
|
+
denormalize: !normalized?,
|
196
|
+
epoch: @values[:epoch]))
|
193
197
|
@loaded = true
|
194
198
|
@records
|
195
199
|
end
|
@@ -207,7 +211,8 @@ module Influxer
|
|
207
211
|
end
|
208
212
|
|
209
213
|
def scoping
|
210
|
-
previous
|
214
|
+
previous = @klass.current_scope
|
215
|
+
@klass.current_scope = self
|
211
216
|
yield
|
212
217
|
ensure
|
213
218
|
@klass.current_scope = previous
|
@@ -237,7 +242,7 @@ module Influxer
|
|
237
242
|
protected
|
238
243
|
|
239
244
|
def build_series_name
|
240
|
-
@instance.series
|
245
|
+
from_value.present? ? @klass.quoted_series(from_value) : @instance.series
|
241
246
|
end
|
242
247
|
|
243
248
|
def loaded?
|
@@ -5,9 +5,8 @@ module Influxer
|
|
5
5
|
:count, :min, :max, :mean,
|
6
6
|
:mode, :median, :distinct, :derivative,
|
7
7
|
:stddev, :sum, :first, :last
|
8
|
-
]
|
8
|
+
].freeze
|
9
9
|
|
10
|
-
# rubocop:disable Metrics/LineLength
|
11
10
|
CALCULATION_METHODS.each do |name|
|
12
11
|
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
13
12
|
def #{name}(val, alias_name = nil) # def count(val)
|
@@ -20,7 +19,7 @@ module Influxer
|
|
20
19
|
|
21
20
|
def percentile(name, val, alias_name = nil)
|
22
21
|
@values[:has_calculations] = true
|
23
|
-
select_values << "percentile(#{name}
|
22
|
+
select_values << "percentile(#{name}, #{val})#{alias_name ? ' as ' + alias_name.to_s : ''}"
|
24
23
|
self
|
25
24
|
end
|
26
25
|
end
|
@@ -24,11 +24,11 @@ module Influxer
|
|
24
24
|
# Metrics.time("4d", fill: 0)
|
25
25
|
# # select * from metrics group by time(4d) fill(0)
|
26
26
|
def time(val, options = {})
|
27
|
-
if val.is_a?(Symbol)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
@values[:time] = if val.is_a?(Symbol)
|
28
|
+
TIME_ALIASES[val] || '1' + val.to_s
|
29
|
+
else
|
30
|
+
val
|
31
|
+
end
|
32
32
|
|
33
33
|
build_fill(options[:fill])
|
34
34
|
self
|
@@ -30,32 +30,38 @@ module Influxer
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
34
|
+
# rubocop:disable Metrics/MethodLength
|
33
35
|
def build_eql(key, val, negate)
|
34
36
|
case val
|
37
|
+
when NilClass
|
38
|
+
build_eql(key, /.*/, !negate)
|
35
39
|
when Regexp
|
36
|
-
"#{key}#{negate ? '!~' : '=~'}#{val.inspect}"
|
40
|
+
"#{key}#{negate ? ' !~ ' : ' =~ '}#{val.inspect}"
|
37
41
|
when Array
|
38
42
|
build_in(key, val, negate)
|
39
43
|
when Range
|
40
44
|
build_range(key, val, negate)
|
41
45
|
else
|
42
|
-
"#{key}#{negate ? '<>' : '='}#{quoted(val, key)}"
|
46
|
+
"#{key}#{negate ? ' <> ' : ' = '}#{quoted(val, key)}"
|
43
47
|
end
|
44
48
|
end
|
49
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
50
|
+
# rubocop:enable Metrics/MethodLength
|
45
51
|
|
46
52
|
def build_in(key, arr, negate)
|
47
53
|
buf = []
|
48
54
|
arr.each do |val|
|
49
55
|
buf << build_eql(key, val, negate)
|
50
56
|
end
|
51
|
-
|
57
|
+
buf.join(negate ? ' and ' : ' or ').to_s
|
52
58
|
end
|
53
59
|
|
54
60
|
def build_range(key, val, negate)
|
55
61
|
if negate
|
56
|
-
"#{key}
|
62
|
+
"#{key} < #{quoted(val.begin)} and #{key} > #{quoted(val.end)}"
|
57
63
|
else
|
58
|
-
"#{key}
|
64
|
+
"#{key} > #{quoted(val.begin)} and #{key} < #{quoted(val.end)}"
|
59
65
|
end
|
60
66
|
end
|
61
67
|
end
|
@@ -27,7 +27,7 @@ module Influxer
|
|
27
27
|
class ScopeRegistry # :nodoc:
|
28
28
|
extend ActiveSupport::PerThreadRegistry
|
29
29
|
|
30
|
-
VALID_SCOPE_TYPES = [:current_scope]
|
30
|
+
VALID_SCOPE_TYPES = [:current_scope].freeze
|
31
31
|
|
32
32
|
def initialize
|
33
33
|
@registry = Hash.new { |hash, key| hash[key] = {} }
|
@@ -49,7 +49,7 @@ module Influxer
|
|
49
49
|
|
50
50
|
def raise_invalid_scope_type!(scope_type)
|
51
51
|
return if VALID_SCOPE_TYPES.include?(scope_type)
|
52
|
-
|
52
|
+
raise ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. \
|
53
53
|
Scope types must be included in VALID_SCOPE_TYPES"
|
54
54
|
end
|
55
55
|
end
|
@@ -7,7 +7,7 @@ module Influxer
|
|
7
7
|
|
8
8
|
module ClassMethods
|
9
9
|
def scope(name, scope)
|
10
|
-
|
10
|
+
raise "Scope not defined: #{name}" if scope.nil? || !scope.respond_to?(:call)
|
11
11
|
singleton_class.send(:define_method, name) do |*args|
|
12
12
|
rel = all
|
13
13
|
rel.merge!(rel.scoping { scope.call(*args) })
|
data/lib/influxer/model.rb
CHANGED
@@ -9,18 +9,15 @@ module Influxer
|
|
9
9
|
# rubocop:disable Style/PredicateName
|
10
10
|
# rubocop:disable Metrics/MethodLength
|
11
11
|
# rubocop:disable Metrics/AbcSize
|
12
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
13
12
|
def has_metrics(*args, **params)
|
14
13
|
metrics_name = args.empty? ? "metrics" : args.first.to_s
|
15
14
|
|
16
15
|
klass = params[:class_name].present? ? params[:class_name] : "#{self}Metrics"
|
17
16
|
klass = klass.constantize
|
18
17
|
|
19
|
-
attrs = nil
|
20
|
-
|
21
18
|
attrs = params[:inherits] if params[:inherits].present?
|
22
19
|
|
23
|
-
foreign_key = params.
|
20
|
+
foreign_key = params.fetch(:foreign_key, to_s.foreign_key)
|
24
21
|
|
25
22
|
define_method(metrics_name) do
|
26
23
|
rel_attrs = foreign_key ? { foreign_key => id } : {}
|
@@ -19,7 +19,7 @@ module Influxer
|
|
19
19
|
res = yield
|
20
20
|
duration = (Time.now - start_ts) * 1000
|
21
21
|
|
22
|
-
name
|
22
|
+
name = "InfluxDB SQL (#{duration.round(1)}ms)"
|
23
23
|
|
24
24
|
# bold black name and blue query string
|
25
25
|
msg = "\e[1m\e[30m#{name}\e[0m \e[34m#{sql}\e[0m"
|
data/lib/influxer/version.rb
CHANGED
@@ -193,8 +193,8 @@ describe Influxer::Metrics, :query do
|
|
193
193
|
timestamp_test = Time.now
|
194
194
|
expected_time = (timestamp_test.to_r * 1_000_000_000).to_i
|
195
195
|
|
196
|
-
expect(client)
|
197
|
-
to receive(:write_point).with("dummies", tags: { dummy_id: 2, host: 'test' }, values: { user_id: 1 }, timestamp: expected_time)
|
196
|
+
expect(client)
|
197
|
+
.to receive(:write_point).with("dummies", tags: { dummy_id: 2, host: 'test' }, values: { user_id: 1 }, timestamp: expected_time)
|
198
198
|
|
199
199
|
point = dummy_metrics.write(user_id: 1, dummy_id: 2, host: 'test', timestamp: timestamp_test)
|
200
200
|
expect(point.persisted?).to be_truthy
|
@@ -205,10 +205,10 @@ describe Influxer::Metrics, :query do
|
|
205
205
|
|
206
206
|
it "test write data with string time" do
|
207
207
|
base_time = Time.now
|
208
|
-
timestamp_test =
|
208
|
+
timestamp_test = base_time.to_s
|
209
209
|
|
210
|
-
expect(client)
|
211
|
-
to receive(:write_point).with("dummies", tags: { dummy_id: 2, host: 'test' }, values: { user_id: 1 }, timestamp: (base_time.to_i * 1_000_000_000).to_i)
|
210
|
+
expect(client)
|
211
|
+
.to receive(:write_point).with("dummies", tags: { dummy_id: 2, host: 'test' }, values: { user_id: 1 }, timestamp: (base_time.to_i * 1_000_000_000).to_i)
|
212
212
|
|
213
213
|
point = dummy_metrics.write(user_id: 1, dummy_id: 2, host: 'test', timestamp: timestamp_test)
|
214
214
|
expect(point.persisted?).to be_truthy
|
@@ -27,15 +27,15 @@ describe Influxer::Relation, :query do
|
|
27
27
|
r2 = Influxer::Relation.new(DummyMetrics).where.not(user_id: 0).group(:user_id).order(user_id: :asc)
|
28
28
|
r1.merge!(r2)
|
29
29
|
expect(r1.to_sql)
|
30
|
-
.to eq "select * from \"dummy\" where (id=1 or id=2) and (dummy='qwe') and (user_id<>0) " \
|
31
|
-
"group by time(1h),user_id order by user_id asc"
|
30
|
+
.to eq "select * from \"dummy\" where (id = 1 or id = 2) and (dummy = 'qwe') and (user_id <> 0) " \
|
31
|
+
"group by time(1h), user_id order by user_id asc"
|
32
32
|
end
|
33
33
|
|
34
34
|
it "merge single values" do
|
35
35
|
r1 = rel.time(:hour, fill: 0).slimit(10)
|
36
36
|
r2 = Influxer::Relation.new(DummyMetrics).group(:dummy_id).offset(10).slimit(5)
|
37
37
|
r1.merge!(r2)
|
38
|
-
expect(r1.to_sql).to eq "select * from \"dummy\" group by time(1h),dummy_id fill(0) offset 10 slimit 5"
|
38
|
+
expect(r1.to_sql).to eq "select * from \"dummy\" group by time(1h), dummy_id fill(0) offset 10 slimit 5"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -44,11 +44,15 @@ describe Influxer::Relation, :query do
|
|
44
44
|
it "generates valid from if no conditions" do
|
45
45
|
expect(rel.to_sql).to eq "select * from \"dummy\""
|
46
46
|
end
|
47
|
+
|
48
|
+
it "generates sql using custom from clause" do
|
49
|
+
expect(rel.from(:doomy).to_sql).to eq "select * from \"doomy\""
|
50
|
+
end
|
47
51
|
end
|
48
52
|
|
49
53
|
describe "#select" do
|
50
54
|
it "select array of symbols" do
|
51
|
-
expect(rel.select(:user_id, :dummy_id).to_sql).to eq "select user_id,dummy_id from \"dummy\""
|
55
|
+
expect(rel.select(:user_id, :dummy_id).to_sql).to eq "select user_id, dummy_id from \"dummy\""
|
52
56
|
end
|
53
57
|
|
54
58
|
it "select string" do
|
@@ -63,7 +67,7 @@ describe Influxer::Relation, :query do
|
|
63
67
|
describe "#where" do
|
64
68
|
it "sgenerate valid conditions from hash" do
|
65
69
|
Timecop.freeze(Time.now)
|
66
|
-
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
|
70
|
+
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}s)"
|
67
71
|
end
|
68
72
|
|
69
73
|
it "generate valid conditions from strings" do
|
@@ -71,43 +75,53 @@ describe Influxer::Relation, :query do
|
|
71
75
|
end
|
72
76
|
|
73
77
|
it "handle regexps" do
|
74
|
-
expect(rel.where(user_id: 1, dummy: /^du.*/).to_sql).to eq "select * from \"dummy\" where (user_id=1) and (dummy
|
78
|
+
expect(rel.where(user_id: 1, dummy: /^du.*/).to_sql).to eq "select * from \"dummy\" where (user_id = 1) and (dummy =~ /^du.*/)"
|
75
79
|
end
|
76
80
|
|
77
81
|
it "handle ranges" do
|
78
|
-
expect(rel.where(user_id: 1..4).to_sql).to eq "select * from \"dummy\" where (user_id>1 and user_id<4)"
|
82
|
+
expect(rel.where(user_id: 1..4).to_sql).to eq "select * from \"dummy\" where (user_id > 1 and user_id < 4)"
|
79
83
|
end
|
80
84
|
|
81
85
|
it "handle arrays" do
|
82
|
-
expect(rel.where(user_id: [1, 2, 3]).to_sql).to eq "select * from \"dummy\" where (user_id=1 or user_id=2 or user_id=3)"
|
86
|
+
expect(rel.where(user_id: [1, 2, 3]).to_sql).to eq "select * from \"dummy\" where (user_id = 1 or user_id = 2 or user_id = 3)"
|
83
87
|
end
|
84
88
|
|
85
89
|
context "with tags" do
|
86
90
|
it "integer tag values" do
|
87
|
-
expect(rel.where(dummy_id: 10).to_sql).to eq "select * from \"dummy\" where (dummy_id='10')"
|
91
|
+
expect(rel.where(dummy_id: 10).to_sql).to eq "select * from \"dummy\" where (dummy_id = '10')"
|
88
92
|
end
|
89
93
|
|
90
94
|
it "array tag values" do
|
91
|
-
expect(rel.where(dummy_id: [10, 'some']).to_sql).to eq "select * from \"dummy\" where (dummy_id='10' or dummy_id='some')"
|
95
|
+
expect(rel.where(dummy_id: [10, 'some']).to_sql).to eq "select * from \"dummy\" where (dummy_id = '10' or dummy_id = 'some')"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "nil value" do
|
99
|
+
expect(rel.where(dummy_id: nil).to_sql).to eq "select * from \"dummy\" where (dummy_id !~ /.*/)"
|
92
100
|
end
|
93
101
|
end
|
94
102
|
end
|
95
103
|
|
96
104
|
describe "#not" do
|
97
105
|
it "negate simple values" do
|
98
|
-
expect(rel.where.not(user_id: 1, dummy: :a).to_sql).to eq "select * from \"dummy\" where (user_id<>1) and (dummy<>'a')"
|
106
|
+
expect(rel.where.not(user_id: 1, dummy: :a).to_sql).to eq "select * from \"dummy\" where (user_id <> 1) and (dummy <> 'a')"
|
99
107
|
end
|
100
108
|
|
101
109
|
it "handle regexp" do
|
102
|
-
expect(rel.where.not(user_id: 1, dummy: /^du.*/).to_sql).to eq "select * from \"dummy\" where (user_id<>1) and (dummy
|
110
|
+
expect(rel.where.not(user_id: 1, dummy: /^du.*/).to_sql).to eq "select * from \"dummy\" where (user_id <> 1) and (dummy !~ /^du.*/)"
|
103
111
|
end
|
104
112
|
|
105
113
|
it "handle ranges" do
|
106
|
-
expect(rel.where.not(user_id: 1..4).to_sql).to eq "select * from \"dummy\" where (user_id<1 and user_id>4)"
|
114
|
+
expect(rel.where.not(user_id: 1..4).to_sql).to eq "select * from \"dummy\" where (user_id < 1 and user_id > 4)"
|
107
115
|
end
|
108
116
|
|
109
117
|
it "handle arrays" do
|
110
|
-
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)"
|
118
|
+
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)"
|
119
|
+
end
|
120
|
+
|
121
|
+
context "with tags" do
|
122
|
+
it "nil value" do
|
123
|
+
expect(rel.not(dummy_id: nil).to_sql).to eq "select * from \"dummy\" where (dummy_id =~ /.*/)"
|
124
|
+
end
|
111
125
|
end
|
112
126
|
end
|
113
127
|
|
@@ -137,7 +151,7 @@ describe Influxer::Relation, :query do
|
|
137
151
|
|
138
152
|
describe "#group" do
|
139
153
|
it "generate valid groups" do
|
140
|
-
expect(rel.group(:user_id, "time(1m) fill(0)").to_sql).to eq "select * from \"dummy\" group by user_id,time(1m) fill(0)"
|
154
|
+
expect(rel.group(:user_id, "time(1m) fill(0)").to_sql).to eq "select * from \"dummy\" group by user_id, time(1m) fill(0)"
|
141
155
|
end
|
142
156
|
|
143
157
|
context "group by time predefined values" do
|
@@ -189,11 +203,11 @@ describe Influxer::Relation, :query do
|
|
189
203
|
end
|
190
204
|
|
191
205
|
it "group by time and other fields with fill zero" do
|
192
|
-
expect(rel.time("4d", fill: 0).group(:dummy_id).to_sql).to eq "select * from \"dummy\" group by time(4d),dummy_id fill(0)"
|
206
|
+
expect(rel.time("4d", fill: 0).group(:dummy_id).to_sql).to eq "select * from \"dummy\" group by time(4d), dummy_id fill(0)"
|
193
207
|
end
|
194
208
|
|
195
209
|
it "group by time and other fields with fill negative" do
|
196
|
-
expect(rel.time("4d", fill: -1).group(:dummy_id).to_sql).to eq "select * from \"dummy\" group by time(4d),dummy_id fill(-1)"
|
210
|
+
expect(rel.time("4d", fill: -1).group(:dummy_id).to_sql).to eq "select * from \"dummy\" group by time(4d), dummy_id fill(-1)"
|
197
211
|
end
|
198
212
|
end
|
199
213
|
|
@@ -241,7 +255,7 @@ describe Influxer::Relation, :query do
|
|
241
255
|
describe "##{method}" do
|
242
256
|
specify do
|
243
257
|
expect(rel.where(user_id: 1).calc(method, :column_name).to_sql)
|
244
|
-
.to eq "select #{method}(column_name) from \"dummy\" where (user_id=1)"
|
258
|
+
.to eq "select #{method}(column_name) from \"dummy\" where (user_id = 1)"
|
245
259
|
end
|
246
260
|
end
|
247
261
|
end
|
@@ -253,7 +267,7 @@ describe Influxer::Relation, :query do
|
|
253
267
|
end
|
254
268
|
|
255
269
|
it "select percentile as alias" do
|
256
|
-
expect(rel.percentile(:val, 90, 'p1').to_sql).to eq "select percentile(val,90) as p1 from \"dummy\""
|
270
|
+
expect(rel.percentile(:val, 90, 'p1').to_sql).to eq "select percentile(val, 90) as p1 from \"dummy\""
|
257
271
|
end
|
258
272
|
end
|
259
273
|
end
|
@@ -261,19 +275,19 @@ describe Influxer::Relation, :query do
|
|
261
275
|
context "complex queries" do
|
262
276
|
it "group + where" do
|
263
277
|
expect(rel.count('user_id').group(:traffic_source).fill(0).where(user_id: 123).past('28d').to_sql)
|
264
|
-
.to eq "select count(user_id) from \"dummy\" where (user_id=123) and (time > now() - 28d) " \
|
278
|
+
.to eq "select count(user_id) from \"dummy\" where (user_id = 123) and (time > now() - 28d) " \
|
265
279
|
"group by traffic_source fill(0)"
|
266
280
|
end
|
267
281
|
|
268
282
|
it "where + group + order + limit" do
|
269
283
|
expect(rel.group(:user_id).where(account_id: 123).order(account_id: :desc).limit(10).offset(10).to_sql)
|
270
|
-
.to eq "select * from \"dummy\" where (account_id=123) group by user_id " \
|
284
|
+
.to eq "select * from \"dummy\" where (account_id = 123) group by user_id " \
|
271
285
|
"order by account_id desc limit 10 offset 10"
|
272
286
|
end
|
273
287
|
|
274
288
|
it "offset + slimit" do
|
275
289
|
expect(rel.where(account_id: 123).slimit(10).offset(10).to_sql)
|
276
|
-
.to eq "select * from \"dummy\" where (account_id=123) " \
|
290
|
+
.to eq "select * from \"dummy\" where (account_id = 123) " \
|
277
291
|
"offset 10 slimit 10"
|
278
292
|
end
|
279
293
|
end
|
@@ -310,7 +324,7 @@ describe Influxer::Relation, :query do
|
|
310
324
|
|
311
325
|
it "with tags" do
|
312
326
|
expect(rel.where(dummy_id: 1, host: 'eu').delete_all)
|
313
|
-
.to eq "drop series from \"dummy\" where (dummy_id='1') and (host='eu')"
|
327
|
+
.to eq "drop series from \"dummy\" where (dummy_id = '1') and (host = 'eu')"
|
314
328
|
end
|
315
329
|
end
|
316
330
|
|
@@ -42,14 +42,14 @@ describe Influxer::Metrics, :query do
|
|
42
42
|
|
43
43
|
it "works with several defaults" do
|
44
44
|
expect(dappy.where(user_id: 1).to_sql)
|
45
|
-
.to eq "select * from \"dummy\" where (user_id=1) group by time(1h) limit 100"
|
45
|
+
.to eq "select * from \"dummy\" where (user_id = 1) group by time(1h) limit 100"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
describe "named scope" do
|
50
50
|
it "works with named scope" do
|
51
51
|
expect(doomy.by_user(1).to_sql)
|
52
|
-
.to eq "select * from \"dummy\" where (user_id=1) group by time(1h) limit 100"
|
52
|
+
.to eq "select * from \"dummy\" where (user_id = 1) group by time(1h) limit 100"
|
53
53
|
end
|
54
54
|
|
55
55
|
it "works with named scope with empty relation" do
|
@@ -58,7 +58,7 @@ describe Influxer::Metrics, :query do
|
|
58
58
|
|
59
59
|
it "works with several scopes" do
|
60
60
|
expect(doomy.where(dummy_id: 100).by_user([1, 2, 3]).daily.to_sql)
|
61
|
-
.to eq "select * from \"dummy\" where (dummy_id=100) and (user_id=1 or user_id=2 or user_id=3) group by time(1d) limit 100"
|
61
|
+
.to eq "select * from \"dummy\" where (dummy_id = 100) and (user_id = 1 or user_id = 2 or user_id = 3) group by time(1d) limit 100"
|
62
62
|
end
|
63
63
|
end
|
64
64
|
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: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Dem
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: '0.3'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: '0.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: anyway_config
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|