Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add intervals for range queries

  • Loading branch information...
commit 981ea6714d537f5bfc91f8335c0bf6cbb8d6ee64 1 parent 19797a1
@sixtus sixtus authored
View
21 lib/druid/query.rb
@@ -91,13 +91,11 @@ def filter(hash = nil, &block)
end
def interval(from, to = Time.now)
- from = today + from if from.is_a?(Fixnum)
- to = today + to if to.is_a?(Fixnum)
-
- from = DateTime.parse(from.to_s) unless from.respond_to? :iso8601
- to = DateTime.parse(to.to_s) unless to.respond_to? :iso8601
+ intervals([[from, to]])
+ end
- @properties[:intervals] = ["#{from.iso8601}/#{to.iso8601}"]
+ def intervals(is)
+ @properties[:intervals] = is.map{ |ii| mk_interval(ii[0], ii[1]) }
self
end
@@ -130,6 +128,17 @@ def to_json
@properties.to_json
end
+ private
+
+ def mk_interval(from, to)
+ from = today + from if from.is_a?(Fixnum)
+ to = today + to if to.is_a?(Fixnum)
+
+ from = DateTime.parse(from.to_s) unless from.respond_to? :iso8601
+ to = DateTime.parse(to.to_s) unless to.respond_to? :iso8601
+ "#{from.iso8601}/#{to.iso8601}"
+ end
+
end
class PostAggregation
View
4 ruby-druid.gemspec
@@ -2,8 +2,8 @@ require 'rake'
Gem::Specification.new do |gem|
gem.name = 'ruby-druid'
- gem.version = '0.0.7'
- gem.date = '2013-04-17'
+ gem.version = '0.0.8'
+ gem.date = '2013-04-23'
gem.summary = 'Ruby client for druid'
gem.description = 'Ruby client for metamx druid'
gem.authors = ['Hagen Rother', 'Holger Pillmann']
View
5 spec/lib/query_spec.rb
@@ -120,6 +120,11 @@
JSON.parse(@query.to_json)['intervals'].should == ['2013-01-26T00:00:00+00:00/2020-01-26T00:15:00+00:00']
end
+ it 'takes multiple intervals' do
+ @query.intervals([['2013-01-26T0', '2020-01-26T00:15'],['2013-04-23T0', '2013-04-23T15:00']])
+ JSON.parse(@query.to_json)['intervals'].should == ["2013-01-26T00:00:00+00:00/2020-01-26T00:15:00+00:00", "2013-04-23T00:00:00+00:00/2013-04-23T15:00:00+00:00"]
+ end
+
it 'accepts Time objects for intervals' do
@query.interval(a = Time.now, b = Time.now + 1)
JSON.parse(@query.to_json)['intervals'].should == ["#{a.iso8601}/#{b.iso8601}"]
View
3  spec/lib/zoo_handler_spec.rb
@@ -82,6 +82,9 @@ def change(uri, values)
@paths[uri] = values
@registrations[uri].call if @registrations[uri]
end
+
+ def on_expired_session
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.