Class: InfluxDB2::QueryApi

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

Overview

The client of the InfluxDB 2.0 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:

  • 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) ⇒ Array

Returns list of FluxTables which are matched the query.

Parameters:

  • (defaults to: nil)

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

  • (defaults to: nil)

    specifies the source organization

Returns:

  • list of FluxTables which are matched the query



47
48
49
50
51
52
53
# 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) ⇒ String

Returns result of query.

Parameters:

  • (defaults to: nil)

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

  • (defaults to: nil)

    specifies the source organization

Returns:

  • result of query



40
41
42
# 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) ⇒ Object

Returns stream of Flux Records.

Parameters:

  • (defaults to: nil)

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

  • (defaults to: nil)

    specifies the source organization

Returns:

  • stream of Flux Records



58
59
60
61
62
# 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