ruby-druid 0.10.2 → 0.11.1
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 +5 -5
- data/README.md +10 -0
- data/lib/druid/aggregation.rb +28 -0
- data/lib/druid/filter.rb +37 -1
- data/lib/druid/query.rb +13 -0
- data/lib/druid/version.rb +1 -1
- data/ruby-druid.gemspec +1 -1
- data/spec/lib/query_spec.rb +26 -0
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0f5eb5f76213ef418c72e7a23982396bd2191bfcb1c8e45f246c956d2c31736a
|
4
|
+
data.tar.gz: 6d2e0f22836c012242e177d283a6ec846a21bb102c20f5d81680fb9888ea7be7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4da2d77ab40643ed4050ae3536880a38e3d03215c46fee9e67851d04c2618b3f3cc17ada6d8f77d67b13bcac847a3a3bcc0114708eaf3029fda7105060e2d694
|
7
|
+
data.tar.gz: e2c000c181b04bc74bb4a949bbb2dfba189771fd6c2fb4abd1f98bc45cfb588f4e47818ec1aa2b6938154ba9a7c85ded82ab7f8092e0788baf802511aa9c86b1
|
data/README.md
CHANGED
@@ -92,6 +92,16 @@ Druid::Query::Builder.new.js_aggregation(:aggregate, [:x, :y],
|
|
92
92
|
)
|
93
93
|
```
|
94
94
|
|
95
|
+
#### filtered aggregation
|
96
|
+
|
97
|
+
A filtered aggregator wraps any given aggregator, but only aggregates the values for which the given dimension filter matches.
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
Druid::Query::Builder.new.filtered_aggregation(:aggregate1, :aggregate_1_name, :longSum) do
|
101
|
+
dimension1.neq 1 & dimension2.neq 2
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
95
105
|
### Post Aggregations
|
96
106
|
|
97
107
|
A simple syntax for post aggregations with +,-,/,* can be used like:
|
data/lib/druid/aggregation.rb
CHANGED
@@ -59,6 +59,34 @@ module Druid
|
|
59
59
|
attr_accessor :byRow
|
60
60
|
validates :byRow, allow_nil: true, inclusion: { in: [true, false] }
|
61
61
|
|
62
|
+
class FilterValidator < ActiveModel::EachValidator
|
63
|
+
TYPES = %w[filtered].freeze
|
64
|
+
def validate_each(record, attribute, value)
|
65
|
+
if TYPES.include?(record.type)
|
66
|
+
record.errors.add(attribute, 'may not be blank') if value.blank?
|
67
|
+
else
|
68
|
+
record.errors.add(attribute, "is not supported by type=#{record.type}") if value
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
attr_accessor :filter
|
74
|
+
validates :filter, filter: true
|
75
|
+
|
76
|
+
class AggregatorValidator < ActiveModel::EachValidator
|
77
|
+
TYPES = %w[filtered].freeze
|
78
|
+
def validate_each(record, attribute, value)
|
79
|
+
if TYPES.include?(record.type)
|
80
|
+
record.errors.add(attribute, 'may not be blank') if value.blank?
|
81
|
+
else
|
82
|
+
record.errors.add(attribute, "is not supported by type=#{record.type}") if value
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
attr_accessor :aggregator
|
88
|
+
validates :aggregator, aggregator: true
|
89
|
+
|
62
90
|
def as_json(options = {})
|
63
91
|
super(options.merge(except: %w(errors validation_context)))
|
64
92
|
end
|
data/lib/druid/filter.rb
CHANGED
@@ -166,6 +166,14 @@ module Druid
|
|
166
166
|
CircFilter.new(@dimension, bounds)
|
167
167
|
end
|
168
168
|
|
169
|
+
def bound(params)
|
170
|
+
BoundFilter.new(@dimension, params)
|
171
|
+
end
|
172
|
+
|
173
|
+
def search(params)
|
174
|
+
SearchFilter.new(@dimension, params)
|
175
|
+
end
|
176
|
+
|
169
177
|
def eq(value)
|
170
178
|
case value
|
171
179
|
when ::Array
|
@@ -299,7 +307,35 @@ module Druid
|
|
299
307
|
@bound = {
|
300
308
|
type: 'radius',
|
301
309
|
coords: bounds.first,
|
302
|
-
radius: bounds.last
|
310
|
+
radius: bounds.last
|
311
|
+
}
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
class BoundFilter < Filter
|
316
|
+
include BooleanOperators
|
317
|
+
|
318
|
+
def initialize(dimension, params)
|
319
|
+
super()
|
320
|
+
@type = 'bound'
|
321
|
+
@dimension = dimension
|
322
|
+
@ordering = params[:ordering]
|
323
|
+
@upper = params[:upper]
|
324
|
+
@upperStrict = params[:upperStrict]
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
class SearchFilter < Filter
|
329
|
+
include BooleanOperators
|
330
|
+
|
331
|
+
def initialize(dimension, params)
|
332
|
+
super()
|
333
|
+
@type = 'search'
|
334
|
+
@dimension = dimension
|
335
|
+
@query = {
|
336
|
+
type: 'contains',
|
337
|
+
value: params[:value],
|
338
|
+
caseSensitive: params[:case_sensitive] || false
|
303
339
|
}
|
304
340
|
end
|
305
341
|
end
|
data/lib/druid/query.rb
CHANGED
@@ -451,6 +451,19 @@ module Druid
|
|
451
451
|
self
|
452
452
|
end
|
453
453
|
|
454
|
+
def filtered_aggregation(metric, name, aggregation_type, &filter)
|
455
|
+
@query.aggregations << Aggregation.new(
|
456
|
+
type: 'filtered',
|
457
|
+
filter: Filter.new.instance_exec(&filter),
|
458
|
+
aggregator: Aggregation.new(
|
459
|
+
type: aggregation_type.to_s.camelize(:lower),
|
460
|
+
name: name,
|
461
|
+
fieldName: metric
|
462
|
+
)
|
463
|
+
) unless @query.contains_aggregation?(name)
|
464
|
+
self
|
465
|
+
end
|
466
|
+
|
454
467
|
## post aggregations
|
455
468
|
|
456
469
|
def postagg(type = :long_sum, &block)
|
data/lib/druid/version.rb
CHANGED
data/ruby-druid.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_dependency "multi_json", "~> 1.0"
|
26
26
|
spec.add_dependency "rest-client", ">= 1.8", "< 3.0"
|
27
27
|
spec.add_dependency "zk", "~> 1.9"
|
28
|
-
spec.add_development_dependency "bundler", ">= 1.3.0", "< 2.
|
28
|
+
spec.add_development_dependency "bundler", ">= 1.3.0", "< 2.2"
|
29
29
|
spec.add_development_dependency "rake", "~> 11.2"
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.4"
|
31
31
|
spec.add_development_dependency "webmock", "~> 2.1"
|
data/spec/lib/query_spec.rb
CHANGED
@@ -209,6 +209,32 @@ describe Druid::Query do
|
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
212
|
+
describe '#filtered_aggregation' do
|
213
|
+
it 'builds filtered aggregations' do
|
214
|
+
@query.filtered_aggregation(:a, :a_filtered, :longSum) do
|
215
|
+
b.eq(2) & c.neq(3)
|
216
|
+
end
|
217
|
+
expect(JSON.parse(@query.query.to_json)['aggregations']).to eq [
|
218
|
+
{
|
219
|
+
'type' => 'filtered',
|
220
|
+
'filter' => {
|
221
|
+
'type' => 'and',
|
222
|
+
'fields' => [
|
223
|
+
{ 'dimension' => 'b', 'type' => 'selector', 'value' => 2 },
|
224
|
+
{
|
225
|
+
'type' => 'not',
|
226
|
+
'field' => {
|
227
|
+
'dimension' => 'c', 'type' => 'selector', 'value' => 3
|
228
|
+
}
|
229
|
+
}
|
230
|
+
]
|
231
|
+
},
|
232
|
+
'aggregator' => { 'type' => 'longSum', 'name' => 'a_filtered', 'fieldName' => 'a' }
|
233
|
+
}
|
234
|
+
]
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
212
238
|
it 'appends long_sum properties from aggregations on calling long_sum again' do
|
213
239
|
@query.long_sum(:a, :b, :c)
|
214
240
|
@query.double_sum(:x,:y)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-druid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruby Druid Community
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: 1.3.0
|
110
110
|
- - "<"
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version: '2.
|
112
|
+
version: '2.2'
|
113
113
|
type: :development
|
114
114
|
prerelease: false
|
115
115
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -119,7 +119,7 @@ dependencies:
|
|
119
119
|
version: 1.3.0
|
120
120
|
- - "<"
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version: '2.
|
122
|
+
version: '2.2'
|
123
123
|
- !ruby/object:Gem::Dependency
|
124
124
|
name: rake
|
125
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,7 +165,7 @@ dependencies:
|
|
165
165
|
description: |2
|
166
166
|
ruby-druid is a Ruby client for Druid. It includes a Squeel-like query DSL
|
167
167
|
and generates a JSON query that can be sent to Druid directly.
|
168
|
-
email:
|
168
|
+
email:
|
169
169
|
executables: []
|
170
170
|
extensions: []
|
171
171
|
extra_rdoc_files: []
|
@@ -195,7 +195,7 @@ homepage: https://github.com/ruby-druid/ruby-druid
|
|
195
195
|
licenses:
|
196
196
|
- MIT
|
197
197
|
metadata: {}
|
198
|
-
post_install_message:
|
198
|
+
post_install_message:
|
199
199
|
rdoc_options: []
|
200
200
|
require_paths:
|
201
201
|
- lib
|
@@ -210,14 +210,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
210
|
- !ruby/object:Gem::Version
|
211
211
|
version: '0'
|
212
212
|
requirements: []
|
213
|
-
|
214
|
-
|
215
|
-
signing_key:
|
213
|
+
rubygems_version: 3.0.3
|
214
|
+
signing_key:
|
216
215
|
specification_version: 4
|
217
216
|
summary: A Ruby client for Druid
|
218
217
|
test_files:
|
219
218
|
- spec/spec_helper.rb
|
220
|
-
- spec/lib/query_spec.rb
|
221
|
-
- spec/lib/data_source_spec.rb
|
222
219
|
- spec/lib/client_spec.rb
|
223
220
|
- spec/lib/zk_spec.rb
|
221
|
+
- spec/lib/data_source_spec.rb
|
222
|
+
- spec/lib/query_spec.rb
|