Class: Drill

Inherits:
Object
  • Object
show all
Defined in:
lib/drill/version.rb,
lib/drill-sergeant.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.3"
HEADERS =
{
  "Content-Type" => "application/json",
  "Accept" => "application/json"
}

Instance Method Summary collapse

Constructor Details

#initialize(url: nil, open_timeout: 3, read_timeout: nil) ⇒ Drill

Returns a new instance of Drill.



17
18
19
20
21
22
23
24
25
# File 'lib/drill-sergeant.rb', line 17

def initialize(url: nil, open_timeout: 3, read_timeout: nil)
  url ||= ENV["DRILL_URL"] || "http://localhost:8047"
  # remove trailing slash
  @uri = URI.parse(url.sub(/\/\z/, ""))
  @http = Net::HTTP.new(@uri.host, @uri.port)
  @http.use_ssl = true if @uri.scheme == "https"
  @http.open_timeout = open_timeout if open_timeout
  @http.read_timeout = read_timeout if read_timeout
end

Instance Method Details

#clusterObject



54
55
56
# File 'lib/drill-sergeant.rb', line 54

def cluster
  get("cluster.json")
end

#metricsObject



58
59
60
61
# File 'lib/drill-sergeant.rb', line 58

def metrics
  # no .json suffix
  get("status/metrics")
end

#optionsObject



63
64
65
# File 'lib/drill-sergeant.rb', line 63

def options
  get("options.json")
end

#profiles(query_id = nil) ⇒ Object



44
45
46
47
# File 'lib/drill-sergeant.rb', line 44

def profiles(query_id = nil)
  path = query_id ? "profiles/#{escape_path(query_id)}.json" : "profiles.json"
  get(path)
end

#query(statement) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/drill-sergeant.rb', line 27

def query(statement)
  data = {
    queryType: "sql",
    query: statement
  }

  body = post("query.json", data)

  # return columns in order
  result = []
  columns = body["columns"]
  body["rows"].each do |row|
    result << columns.each_with_object({}) { |c, memo| memo[c] = row[c] }
  end
  result
end

#storage(name = nil) ⇒ Object



49
50
51
52
# File 'lib/drill-sergeant.rb', line 49

def storage(name = nil)
  path = name ? "storage/#{escape_path(name)}.json" : "storage.json"
  get(path)
end