Permalink
Browse files

Add intervals for range queries

  • Loading branch information...
1 parent 19797a1 commit 981ea6714d537f5bfc91f8335c0bf6cbb8d6ee64 @sixtus sixtus committed Apr 23, 2013
Showing with 25 additions and 8 deletions.
  1. +15 −6 lib/druid/query.rb
  2. +2 −2 ruby-druid.gemspec
  3. +5 −0 spec/lib/query_spec.rb
  4. +3 −0 spec/lib/zoo_handler_spec.rb
View
@@ -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
@@ -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']
@@ -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}"]
@@ -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

0 comments on commit 981ea67

Please sign in to comment.