drill-sergeant 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -3
- data/lib/drill-sergeant.rb +64 -12
- data/lib/drill/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeb08242b5c896d36dd67b9af8c14d7eaa989643898939d9b6d6c81e03a4c578
|
4
|
+
data.tar.gz: a35e5e3b79f54a896490bab937c05ee0018175887d9659a466d2bc24bb9ee75f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9a459e815fe4abe80b8b8057f58f6e324011a9391b4dc50ace0522bcdac387e0712125419e787d7c1d59d0dc72a4e0a485b5d6ed4bd6a05c2a3619be06fc18d
|
7
|
+
data.tar.gz: 5ba841223a2be425a9b414c7ee0ffb52e60fdcc891d82f07aa3d1db317ab621ba8e1928a9ef299f7833786728c94bb0f4ee1e41e68c9f1a19dae8461a5bf7035
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2017-2019 Andrew Kane
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -2,15 +2,18 @@
|
|
2
2
|
|
3
3
|
Ruby client for Apache Drill
|
4
4
|
|
5
|
+
[](https://travis-ci.org/ankane/drill-sergeant)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
|
-
First, [
|
9
|
+
First, [install Apache Drill](https://drill.apache.org/docs/installing-drill-on-linux-and-mac-os-x/). For Homebrew, use:
|
8
10
|
|
9
11
|
```sh
|
10
|
-
|
12
|
+
brew install apache-drill
|
13
|
+
drill-embedded
|
11
14
|
```
|
12
15
|
|
13
|
-
|
16
|
+
And add this line to your application’s Gemfile:
|
14
17
|
|
15
18
|
```ruby
|
16
19
|
gem 'drill-sergeant'
|
@@ -30,6 +33,52 @@ And query away
|
|
30
33
|
drill.query("SELECT * FROM dfs.`/path/to/some/file.csvh`")
|
31
34
|
```
|
32
35
|
|
36
|
+
## Endpoints
|
37
|
+
|
38
|
+
[API docs](https://drill.apache.org/docs/rest-api-introduction/)
|
39
|
+
|
40
|
+
Get profiles
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
drill.profiles
|
44
|
+
```
|
45
|
+
|
46
|
+
Get profile by query id
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
drill.profiles(query_id)
|
50
|
+
```
|
51
|
+
|
52
|
+
Get storage
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
drill.storage
|
56
|
+
```
|
57
|
+
|
58
|
+
Get storage by name
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
drill.storage(name)
|
62
|
+
```
|
63
|
+
|
64
|
+
Get cluster info
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
drill.cluster
|
68
|
+
```
|
69
|
+
|
70
|
+
Get metrics
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
drill.metrics
|
74
|
+
```
|
75
|
+
|
76
|
+
Get options
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
drill.options
|
80
|
+
```
|
81
|
+
|
33
82
|
## Reference
|
34
83
|
|
35
84
|
Set timeouts
|
data/lib/drill-sergeant.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# dependencies
|
2
|
+
require "cgi"
|
1
3
|
require "json"
|
2
4
|
require "net/http"
|
5
|
+
|
6
|
+
# modules
|
3
7
|
require "drill/version"
|
4
8
|
|
5
9
|
class Drill
|
@@ -12,8 +16,8 @@ class Drill
|
|
12
16
|
|
13
17
|
def initialize(url: nil, open_timeout: 3, read_timeout: nil)
|
14
18
|
url ||= ENV["DRILL_URL"] || "http://localhost:8047"
|
15
|
-
#
|
16
|
-
@uri = URI.parse(
|
19
|
+
# remove trailing slash
|
20
|
+
@uri = URI.parse(url.sub(/\/\z/, ""))
|
17
21
|
@http = Net::HTTP.new(@uri.host, @uri.port)
|
18
22
|
@http.use_ssl = true if @uri.scheme == "https"
|
19
23
|
@http.open_timeout = open_timeout if open_timeout
|
@@ -26,16 +30,7 @@ class Drill
|
|
26
30
|
query: statement
|
27
31
|
}
|
28
32
|
|
29
|
-
|
30
|
-
response = @http.post(@uri.request_uri, data.to_json, HEADERS)
|
31
|
-
rescue Errno::ECONNREFUSED => e
|
32
|
-
raise Drill::Error, e.message
|
33
|
-
end
|
34
|
-
|
35
|
-
body = JSON.parse(response.body)
|
36
|
-
if body["errorMessage"]
|
37
|
-
raise Drill::Error, body["errorMessage"].split("\n")[0]
|
38
|
-
end
|
33
|
+
body = post("query.json", data)
|
39
34
|
|
40
35
|
# return columns in order
|
41
36
|
result = []
|
@@ -45,4 +40,61 @@ class Drill
|
|
45
40
|
end
|
46
41
|
result
|
47
42
|
end
|
43
|
+
|
44
|
+
def profiles(query_id = nil)
|
45
|
+
path = query_id ? "profiles/#{escape_path(query_id)}.json" : "profiles.json"
|
46
|
+
get(path)
|
47
|
+
end
|
48
|
+
|
49
|
+
def storage(name = nil)
|
50
|
+
path = name ? "storage/#{escape_path(name)}.json" : "storage.json"
|
51
|
+
get(path)
|
52
|
+
end
|
53
|
+
|
54
|
+
def cluster
|
55
|
+
get("cluster.json")
|
56
|
+
end
|
57
|
+
|
58
|
+
def metrics
|
59
|
+
# no .json suffix
|
60
|
+
get("status/metrics")
|
61
|
+
end
|
62
|
+
|
63
|
+
def options
|
64
|
+
get("options.json")
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def get(path)
|
70
|
+
handle_response do
|
71
|
+
@http.get("#{@uri.request_uri}#{path}", HEADERS)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def post(path, data)
|
76
|
+
handle_response do
|
77
|
+
@http.post("#{@uri.request_uri}#{path}", data.to_json, HEADERS)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def handle_response
|
82
|
+
begin
|
83
|
+
response = yield
|
84
|
+
rescue Errno::ECONNREFUSED => e
|
85
|
+
raise Drill::Error, e.message
|
86
|
+
end
|
87
|
+
|
88
|
+
unless response.kind_of?(Net::HTTPSuccess)
|
89
|
+
body = JSON.parse(response.body) rescue nil
|
90
|
+
message = body["errorMessage"] || "Bad response: #{response.code}"
|
91
|
+
raise Drill::Error, message
|
92
|
+
end
|
93
|
+
|
94
|
+
JSON.parse(response.body)
|
95
|
+
end
|
96
|
+
|
97
|
+
def escape_path(path)
|
98
|
+
CGI.escape(path).gsub("+", "%20")
|
99
|
+
end
|
48
100
|
end
|
data/lib/drill/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drill-sergeant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,6 +59,7 @@ extensions: []
|
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
61
|
- CHANGELOG.md
|
62
|
+
- LICENSE.txt
|
62
63
|
- README.md
|
63
64
|
- lib/drill-sergeant.rb
|
64
65
|
- lib/drill/version.rb
|
@@ -74,15 +75,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
75
|
requirements:
|
75
76
|
- - ">="
|
76
77
|
- !ruby/object:Gem::Version
|
77
|
-
version: '2.
|
78
|
+
version: '2.4'
|
78
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
81
|
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
83
84
|
requirements: []
|
84
|
-
|
85
|
-
rubygems_version: 2.7.7
|
85
|
+
rubygems_version: 3.0.4
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Ruby client for Apache Drill
|