Class: InfluxDB2::QueryApi

Inherits:
DefaultApi show all
Defined in:
lib/influxdb2/client/query_api.rb

Overview

The client of the InfluxDB 2.x that implement Query HTTP API endpoint.

Constant Summary collapse

DEFAULT_DIALECT =
InfluxDB2::Dialect.new(header: true, delimiter: ',', comment_prefix: '#',
annotations: %w[datatype group default])

Constants inherited from DefaultApi

DefaultApi::DEFAULT_REDIRECT_COUNT, DefaultApi::DEFAULT_TIMEOUT, DefaultApi::HEADER_CONTENT_TYPE

Instance Method Summary collapse

Methods inherited from DefaultApi

create_logger, #log

Constructor Details

#initialize(options:) ⇒ QueryApi

Returns a new instance of QueryApi.

Parameters:

  • options (Hash)

    The options to be used by the client.



33
34
35
# File 'lib/influxdb2/client/query_api.rb', line 33

def initialize(options:)
  super(options: options)
end

Instance Method Details

#query(query: nil, org: nil, dialect: DEFAULT_DIALECT, params: nil) ⇒ Array

Returns list of FluxTables which are matched the query.

Parameters:

  • query (Object) (defaults to: nil)

    the flux query to execute. The data could be represent by [String], [Query]

  • org (String) (defaults to: nil)

    specifies the source organization

  • params (Enumerable) (defaults to: nil)

    represent key/value pairs parameters to be injected into query

Returns:

  • (Array)

    list of FluxTables which are matched the query



49
50
51
52
53
54
55
# File 'lib/influxdb2/client/query_api.rb', line 49

def query(query: nil, org: nil, dialect: DEFAULT_DIALECT, params: nil)
  response = query_raw(query: query, org: org, dialect: dialect, params: params)
  parser = InfluxDB2::FluxCsvParser.new(response)

  parser.parse
  parser.tables
end

#query_raw(query: nil, org: nil, dialect: DEFAULT_DIALECT, params: nil) ⇒ String

Returns result of query.

Parameters:

  • query (Object) (defaults to: nil)

    the flux query to execute. The data could be represent by [String], [Query]

  • org (String) (defaults to: nil)

    specifies the source organization

  • params (Enumerable) (defaults to: nil)

    represent key/value pairs parameters to be injected into query

Returns:

  • (String)

    result of query



41
42
43
# File 'lib/influxdb2/client/query_api.rb', line 41

def query_raw(query: nil, org: nil, dialect: DEFAULT_DIALECT, params: nil)
  _post_query(query: query, org: org, dialect: dialect, params: params).read_body
end

#query_stream(query: nil, org: nil, dialect: DEFAULT_DIALECT, params: nil) ⇒ Object

Returns stream of Flux Records.

Parameters:

  • query (Object) (defaults to: nil)

    the flux query to execute. The data could be represent by [String], [Query]

  • org (String) (defaults to: nil)

    specifies the source organization

  • params (Enumerable) (defaults to: nil)

    represent key/value pairs parameters to be injected into query

Returns:

  • stream of Flux Records



61
62
63
64
65
# File 'lib/influxdb2/client/query_api.rb', line 61

def query_stream(query: nil, org: nil, dialect: DEFAULT_DIALECT, params: nil)
  response = _post_query(query: query, org: org, dialect: dialect, params: params)

  InfluxDB2::FluxCsvParser.new(response, stream: true)
end