Class: Fluent::CrateClient

Inherits:
CrateRuby::Client
  • Object
show all
Defined in:
lib/fluent/plugin/out_cratedb.rb

Instance Method Summary collapse

Constructor Details

#initialize(servers = [], opts = {}) ⇒ CrateClient

Returns a new instance of CrateClient.



84
85
86
# File 'lib/fluent/plugin/out_cratedb.rb', line 84

def initialize(servers = [], opts = {})
  super(servers, opts)
end

Instance Method Details

#execute(sql, args = nil, bulk_args = nil, http_options = {}) ⇒ ResultSet

Copy from github.com/crate/crate_ruby/blob/master/lib/crate_ruby/client.rb#L95

Executes a SQL statement against the Crate HTTP REST endpoint.

Parameters:

  • sql (String)

    statement to execute

  • args (Array) (defaults to: nil)

    Array of values used for parameter substitution

  • Net::HTTP (Hash)

    options (open_timeout, read_timeout)

Returns:

  • (ResultSet)


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/fluent/plugin/out_cratedb.rb', line 95

def execute(sql, args = nil, bulk_args = nil, http_options = {})
  @logger.debug sql
  req = Net::HTTP::Post.new("/_sql", initheader = {'Content-Type' => 'application/json'})
  body = {"stmt" => sql}
  body.merge!({'args' => args}) if args
  body.merge!({'bulk_args' => bulk_args}) if bulk_args
  req.body = body.to_json
  response = request(req, http_options)
  @logger.debug response.body
  success = case response.code
              when /^2\d{2}/
                ResultSet.new response.body
              else
                @logger.info(response.body)
                raise CrateRuby::CrateError.new(response.body)
            end
  success
end