Class: Drill::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/drill/client.rb

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
# File 'lib/drill/client.rb', line 8

def initialize(url: nil, open_timeout: 3, read_timeout: nil)
  url ||= ENV["DRILL_URL"] || "http://localhost:8047"
  # remove trailing slash
  @uri = URI.parse(url.chomp("/"))
  @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

#cancel_query(query_id) ⇒ Object



40
41
42
# File 'lib/drill/client.rb', line 40

def cancel_query(query_id)
  get("profiles/cancel/#{escape_path(query_id)}")
end

#clusterObject



75
76
77
# File 'lib/drill/client.rb', line 75

def cluster
  get("cluster.json")
end

#delete_storage(name) ⇒ Object



71
72
73
# File 'lib/drill/client.rb', line 71

def delete_storage(name)
  delete("storage/#{escape_path(name)}.json")
end

#disable_storage(name) ⇒ Object



53
54
55
# File 'lib/drill/client.rb', line 53

def disable_storage(name)
  get("storage/#{escape_path(name)}/enable/false")
end

#enable_storage(name) ⇒ Object



49
50
51
# File 'lib/drill/client.rb', line 49

def enable_storage(name)
  get("storage/#{escape_path(name)}/enable/true")
end

#inspectObject



97
98
99
# File 'lib/drill/client.rb', line 97

def inspect
  to_s
end

#metricsObject

status does not return json



81
82
83
84
# File 'lib/drill/client.rb', line 81

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

#optionsObject

threads does not return json



88
89
90
# File 'lib/drill/client.rb', line 88

def options
  get("options.json")
end

#profiles(query_id = nil) ⇒ Object



35
36
37
38
# File 'lib/drill/client.rb', line 35

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

#query(statement, limit: nil, default_schema: nil, username: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/drill/client.rb', line 18

def query(statement, limit: nil, default_schema: nil, username: nil)
  options = {}
  if Gem::Version.new(server_version) >= Gem::Version.new("1.19.0")
    options["drill.exec.http.rest.errors.verbose"] = true
  end

  data = {
    query: statement,
    options: options
  }
  data[:autoLimit] = limit if limit
  data[:defaultSchema] = default_schema if default_schema
  data[:userName] = username if username

  run_query(data)
end

#server_versionObject



92
93
94
# File 'lib/drill/client.rb', line 92

def server_version
  @server_version ||= run_query({query: "SELECT version FROM sys.version"})[0]["version"]
end

#storage(name = nil) ⇒ Object



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

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

#update_storage(name, type:, enabled:, connection:, workspaces:, formats:) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/drill/client.rb', line 57

def update_storage(name, type:, enabled:, connection:, workspaces:, formats:)
  data = {
    name: name,
    config: {
      type: type,
      enabled: enabled,
      connection: connection,
      workspaces: workspaces,
      formats: formats
    }
  }
  post("storage/#{escape_path(name)}.json", data)
end