class InfluxDB2::QueryApi
The client of the InfluxDB 2.0 that implement Query
HTTP API endpoint.
Constants
- DEFAULT_DIALECT
Public Class Methods
new(options:)
click to toggle source
@param [Hash] options The options to be used by the client.
Calls superclass method
InfluxDB2::DefaultApi::new
# File lib/influxdb2/client/query_api.rb, line 33 def initialize(options:) super(options: options) end
Public Instance Methods
query(query: nil, org: nil, dialect: DEFAULT_DIALECT)
click to toggle source
@param [Object] query the flux query to execute. The data could be represent by [String], [Query] @param [String] org specifies the source organization @return [Array] list of FluxTables which are matched the query
# File lib/influxdb2/client/query_api.rb, line 47 def query(query: nil, org: nil, dialect: DEFAULT_DIALECT) response = query_raw(query: query, org: org, dialect: dialect) parser = InfluxDB2::FluxCsvParser.new(response) parser.parse parser.tables end
query_raw(query: nil, org: nil, dialect: DEFAULT_DIALECT)
click to toggle source
@param [Object] query the flux query to execute. The data could be represent by [String], [Query] @param [String] org specifies the source organization @return [String] result of query
# File lib/influxdb2/client/query_api.rb, line 40 def query_raw(query: nil, org: nil, dialect: DEFAULT_DIALECT) _post_query(query: query, org: org, dialect: dialect).read_body end
query_stream(query: nil, org: nil, dialect: DEFAULT_DIALECT)
click to toggle source
@param [Object] query the flux query to execute. The data could be represent by [String], [Query] @param [String] org specifies the source organization @return stream of Flux Records
# File lib/influxdb2/client/query_api.rb, line 58 def query_stream(query: nil, org: nil, dialect: DEFAULT_DIALECT) response = _post_query(query: query, org: org, dialect: dialect) InfluxDB2::FluxCsvParser.new(response, stream: true) end
Private Instance Methods
_generate_payload(query, dialect)
click to toggle source
# File lib/influxdb2/client/query_api.rb, line 79 def _generate_payload(query, dialect) if query.nil? nil elsif query.is_a?(Query) query elsif query.is_a?(String) if query.empty? nil else Query.new(query: query, dialect: dialect, type: nil) end end end
_post_query(query: nil, org: nil, dialect: DEFAULT_DIALECT)
click to toggle source
# File lib/influxdb2/client/query_api.rb, line 66 def _post_query(query: nil, org: nil, dialect: DEFAULT_DIALECT) org_param = org || @options[:org] _check('org', org_param) payload = _generate_payload(query, dialect) return nil if payload.nil? uri = _parse_uri('/api/v2/query') uri.query = URI.encode_www_form(org: org_param) _post_json(payload.to_body.to_json, uri) end