drill-sergeant 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +7 -0
- data/lib/drill.rb +15 -4
- data/lib/drill/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80d003315bf5824c3353dd3ebd29e9ece7cd2bcd
|
4
|
+
data.tar.gz: 93b0259479a5e8dfa5c71ad5b44729f53ce5d9a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 693314e6cdddd0341a58fa51cd18c2e3fdce9e493889a5fc76383af6f8deee14c11abf5ffe0f6c85e3d5c4c75c0c5e135356076c92c316b53898ebb66c59d866
|
7
|
+
data.tar.gz: 92eea0291ab3c39ea6bc7dde2e7c1c92395a2d1a76f5324fececd35d4bed2c7ebc4b1c709a94a314c579388693227fec08bec0c4d0fc8ecb91cd6c84ad73f654
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/drill.rb
CHANGED
@@ -5,21 +5,26 @@ require "drill/version"
|
|
5
5
|
class Drill
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
8
|
+
HEADERS = {
|
9
|
+
"Content-Type" => "application/json",
|
10
|
+
"Accept" => "application/json"
|
11
|
+
}
|
12
|
+
|
8
13
|
def initialize(url: nil)
|
9
14
|
url ||= ENV["DRILL_URL"] || "http://localhost:8047"
|
10
|
-
|
15
|
+
# strip trailing slash if exists
|
16
|
+
@uri = URI.parse("#{url.sub(/\/\z/, "")}/query.json")
|
11
17
|
@http = Net::HTTP.new(@uri.host, @uri.port)
|
12
18
|
end
|
13
19
|
|
14
20
|
def query(statement)
|
15
|
-
header = {"Content-Type" => "application/json", "Accept" => "application/json"}
|
16
21
|
data = {
|
17
22
|
queryType: "sql",
|
18
23
|
query: statement
|
19
24
|
}
|
20
25
|
|
21
26
|
begin
|
22
|
-
response = @http.post(@uri.request_uri, data.to_json,
|
27
|
+
response = @http.post(@uri.request_uri, data.to_json, HEADERS)
|
23
28
|
rescue Errno::ECONNREFUSED => e
|
24
29
|
raise Drill::Error, e.message
|
25
30
|
end
|
@@ -29,6 +34,12 @@ class Drill
|
|
29
34
|
raise Drill::Error, body["errorMessage"].split("\n")[0]
|
30
35
|
end
|
31
36
|
|
32
|
-
|
37
|
+
# return columns in order
|
38
|
+
result = []
|
39
|
+
columns = body["columns"]
|
40
|
+
body["rows"].each do |row|
|
41
|
+
result << columns.each_with_object({}) { |c, memo| memo[c] = row[c] }
|
42
|
+
end
|
43
|
+
result
|
33
44
|
end
|
34
45
|
end
|
data/lib/drill/version.rb
CHANGED