Class: DruidClient::Cli::Sql

Inherits:
Object
  • Object
show all
Defined in:
lib/druid_client/cli/sql.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent: nil) ⇒ Sql

Returns a new instance of Sql.



8
9
10
# File 'lib/druid_client/cli/sql.rb', line 8

def initialize(parent: nil)
  @parent = parent
end

Instance Method Details

#clientObject



34
35
36
# File 'lib/druid_client/cli/sql.rb', line 34

def client
  @parent.client
end

#display_error(status_code:, error_message:) ⇒ Object



30
31
32
# File 'lib/druid_client/cli/sql.rb', line 30

def display_error(status_code: , error_message: )
  puts "failed: status_code:#{status_code}, message:#{error_message}"
end

#query(query:, options: {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/druid_client/cli/sql.rb', line 12

def query(query:, options: {})
  query_body = { query: query }
  query_response = client.sql.query(
    **query_body
  )

  unless  query_response.success?
    display_error(
      status_code: query_response.status_code,
      error_message: query_response.body
    )
    return
  end

  formater = DruidClient::CLi::OutputFormatFactory.create(options.fetch(:format, :table))
  puts formater.format(query_response.body)
end