ruby-druid 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -192,6 +192,17 @@ This filter creates a set of equals filters in an and filter.
192
192
  ```ruby
193
193
  Druid::Query.new('service/source').filter{dimension.in(1,2,3)}
194
194
  ```
195
+ #### Geographic filter
196
+
197
+ These filters have to be combined with time_series and do only work when coordinates is a spatial dimension [GeographicQueries](http://druid.io/docs/0.6.73/GeographicQueries.html)
198
+
199
+ ```ruby
200
+ Druid::Query.new('service/source').time_series().long_sum([:aggregate1]).filter{coordinates.in_rec [[50.0,13.0],[54.0,15.0]]}
201
+ ```
202
+
203
+ ```ruby
204
+ Druid::Query.new('service/source').time_series().long_sum([:aggregate1]).filter{coordinates.in_circ [[53.0,13.0], 5.0]}
205
+ ```
195
206
 
196
207
  #### Hash syntax
197
208
 
data/lib/druid/console.rb CHANGED
@@ -28,7 +28,9 @@ Ripl::Shell.class_eval do
28
28
 
29
29
  def format_result(result)
30
30
  if result.is_a?(Druid::Query)
31
+ start = Time.now.to_f
31
32
  puts format_query_result(result.send, result)
33
+ puts "Response Time: #{(Time.now.to_f - start).round(3)}s"
32
34
  else
33
35
  ap(result)
34
36
  end
data/lib/druid/filter.rb CHANGED
@@ -38,6 +38,14 @@ module Druid
38
38
  @regexp = nil
39
39
  end
40
40
 
41
+ def in_rec(bounds)
42
+ RecFilter.new(@name, bounds)
43
+ end
44
+
45
+ def in_circ(bounds)
46
+ CircFilter.new(@name, bounds)
47
+ end
48
+
41
49
  def eq(value)
42
50
  return self.in(value) if value.is_a? Array
43
51
  return self.regexp(value) if value.is_a? Regexp
@@ -194,6 +202,46 @@ module Druid
194
202
  result
195
203
  end
196
204
  end
205
+
206
+ class RecFilter < FilterDimension
207
+
208
+ def initialize(dimension, bounds)
209
+ @dimension = dimension
210
+ @bounds = bounds
211
+ end
212
+
213
+ def to_hash
214
+ {
215
+ :type => "spatial",
216
+ :dimension => @dimension,
217
+ :bound =>{
218
+ :type => "rectangular",
219
+ :minCoords => @bounds.first,
220
+ :maxCoords => @bounds.last
221
+ }
222
+ }
223
+ end
224
+ end
225
+
226
+ class CircFilter < FilterDimension
227
+
228
+ def initialize(dimension, bounds)
229
+ @dimension = dimension
230
+ @bounds = bounds
231
+ end
232
+
233
+ def to_hash
234
+ {
235
+ :type => "spatial",
236
+ :dimension => @dimension,
237
+ :bound =>{
238
+ :type => "radius",
239
+ :coords => @bounds.first,
240
+ :radius => @bounds.last
241
+ }
242
+ }
243
+ end
244
+ end
197
245
 
198
246
  class FilterJavascript < FilterDimension
199
247
  def initialize(dimension, expression)
data/ruby-druid.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "ruby-druid"
5
- spec.version = "0.1.4"
5
+ spec.version = "0.1.5"
6
6
  spec.authors = ["LiquidM, Inc."]
7
7
  spec.email = ["opensource@liquidm.com"]
8
8
  spec.summary = %q{Ruby client for metamx druid}
@@ -207,6 +207,32 @@ describe Druid::Query do
207
207
  }
208
208
  end
209
209
 
210
+ it 'creates a in_circ filter' do
211
+ @query.filter{a.in_circ [[52.0,13.0], 10.0]}
212
+ JSON.parse(@query.to_json)['filter'].should == {
213
+ "type" => "spatial",
214
+ "dimension" => "a",
215
+ "bound" => {
216
+ "type" => "radius",
217
+ "coords" => [52.0, 13.0],
218
+ "radius" => 10.0
219
+ }
220
+ }
221
+ end
222
+
223
+ it 'creates a in_rec filter' do
224
+ @query.filter{a.in_rec [[10.0, 20.0], [30.0, 40.0]] }
225
+ JSON.parse(@query.to_json)['filter'].should == {
226
+ "type" => "spatial",
227
+ "dimension" => "a",
228
+ "bound" => {
229
+ "type" => "rectangular",
230
+ "minCoords" => [10.0, 20.0],
231
+ "maxCoords" => [30.0, 40.0]
232
+ }
233
+ }
234
+ end
235
+
210
236
  it 'creates an equals filter' do
211
237
  @query.filter{a.eq 1}
212
238
  JSON.parse(@query.to_json)['filter'].should == {"type"=>"selector", "dimension"=>"a", "value"=>1}
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-druid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - LiquidM, Inc.
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-01-13 00:00:00.000000000 Z
12
+ date: 2014-04-17 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: zk
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rest-client
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -71,26 +76,27 @@ files:
71
76
  homepage: https://github.com/liquidm/ruby-druid
72
77
  licenses:
73
78
  - MIT
74
- metadata: {}
75
79
  post_install_message:
76
80
  rdoc_options: []
77
81
  require_paths:
78
82
  - lib
79
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
80
85
  requirements:
81
86
  - - ! '>='
82
87
  - !ruby/object:Gem::Version
83
88
  version: '0'
84
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
85
91
  requirements:
86
92
  - - ! '>='
87
93
  - !ruby/object:Gem::Version
88
94
  version: '0'
89
95
  requirements: []
90
96
  rubyforge_project:
91
- rubygems_version: 2.0.5
97
+ rubygems_version: 1.8.25
92
98
  signing_key:
93
- specification_version: 4
99
+ specification_version: 3
94
100
  summary: Ruby client for metamx druid
95
101
  test_files:
96
102
  - spec/lib/client_spec.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTljYWNlZjVkNjI3OTg4MmRiNDViNDljNGE3YjQ1OTdmNmUxNWIyZA==
5
- data.tar.gz: !binary |-
6
- OTRmNjRmNTQ4YmU2ODg5YzY2ZDlmOTJjZmJkOTFlZTg2ZDY1MGE1ZQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MTc1Njk1NzZjNmUzMDg3ZDczNDkyZjIyYTY3Yzk2YzA0MmRlMzQ4ZWQ3NTRm
10
- M2YzNDkwZTEyOGVjZjNiZjE5YzVjZTg2OWU5NjFjZGEwNjc2ZWM0Yjg5YTgy
11
- ZTc4OThkZDFmMTE1OTA4YzNiMTAxMTM4ZDRlYzE5ZWUzMmNiYTY=
12
- data.tar.gz: !binary |-
13
- NDRkZTFkMTE3MTgxY2ViNTNjMDA2ZjI2MzM4ZGMzNGQ1MWUwYWRiM2Q4YjI4
14
- NWI2NjM0ODdjZDAzNTA4YTYyM2EwODM5OGYwNmI0Y2RhOGY2N2M3N2M1YWU2
15
- ZmRjODM5YjQ2NDZmMGNjMWFlNjU1YmI2YzkyNDQ2NmZlMTc2NDQ=