Class: ATSD::SeriesQuery
- Defined in:
- lib/atsd/queries/series_query.rb
Overview
Class for building and executing Series Query
Constant Summary
Constants inherited from BaseQuery
BaseQuery::TO_MILLISECONDS_LAMBDA
Instance Attribute Summary
Attributes inherited from BaseQuery
Instance Method Summary collapse
-
#execute ⇒ Array<Series>
Executes query and sets ‘result` attribute.
-
#execute_with(*others) ⇒ Array<Series>
Executes multiple queries at the same time.
- #result ⇒ Array<Series>
-
#tag_add(name, values) ⇒ self
Add tag to ‘tags` parameter.
Methods inherited from BaseQuery
#initialize, #to_request_hash, #type
Constructor Details
This class inherits a constructor from ATSD::BaseQuery
Instance Method Details
#execute ⇒ Array<Series>
Executes query and sets ‘result` attribute.
30 31 32 33 |
# File 'lib/atsd/queries/series_query.rb', line 30 def execute result = @client.series_query to_request_hash @result = result.map { |series_json| Series.new series_json } end |
#execute_with(*others) ⇒ Array<Series>
Executes multiple queries at the same time. Adds ‘request_id` parameter to each query if necessary. All queries will have a corresponding `series` attribute set.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/atsd/queries/series_query.rb', line 41 def execute_with(*others) others ||= [] queries = [self] + others queries_by_id = {} if queries.count > 1 queries.each_with_index do |query, index| query.request_id("query_#{index}") unless query.request_id query.result = [] queries_by_id[query[:request_id]] = query end end results = @client.series_query queries.map {|q| q.to_request_hash} results.map! { |json| Series.new(json) } results.each { |r| queries_by_id[r.request_id].result << r } end |
#result ⇒ Array<Series>
12 13 14 |
# File 'lib/atsd/queries/series_query.rb', line 12 def result super end |
#tag_add(name, values) ⇒ self
Add tag to ‘tags` parameter
22 23 24 25 |
# File 'lib/atsd/queries/series_query.rb', line 22 def tag_add(name, values) self[:tags][name] = Utils.ensure_array(values) self end |