drill-sergeant 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -4
- data/LICENSE.txt +1 -1
- data/README.md +11 -2
- data/lib/drill/version.rb +1 -1
- data/lib/drill-sergeant.rb +36 -17
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9a45ee9fd9196539d55c04641748ea43915edc39b2de7a57acc066ec829a493
|
4
|
+
data.tar.gz: d38d61d15324267e96a19d93284cece7fdf37a035dccdc5eb7f3a73e0872c9fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bd8f5dc9e71be3bb905f092794ea5d91effae2dd80420f11d998382d5cee12d2945b856d06ae1f8248f27b7fbae4261a5280a72d53ea6c5501c479bdd538799
|
7
|
+
data.tar.gz: f4fc88b864649e84dbb3115e15703897bd24e50f0eefc9c956b4163fbe6da8bb4c20a89f5008b06a915ad611f0a5539c35ba1096d314305c6c1d19190471c043
|
data/CHANGELOG.md
CHANGED
@@ -1,16 +1,21 @@
|
|
1
|
-
## 0.1.
|
1
|
+
## 0.1.4 (2022-01-16)
|
2
|
+
|
3
|
+
- Added `server_version` method
|
4
|
+
- Fixed error with failed queries with Drill 1.19+
|
5
|
+
|
6
|
+
## 0.1.3 (2019-08-10)
|
2
7
|
|
3
8
|
- Added more endpoints
|
4
9
|
|
5
|
-
## 0.1.2
|
10
|
+
## 0.1.2 (2018-07-22)
|
6
11
|
|
7
12
|
- Added support for HTTPS
|
8
13
|
- Added `open_timeout` and `read_timeout` options
|
9
14
|
|
10
|
-
## 0.1.1
|
15
|
+
## 0.1.1 (2017-03-24)
|
11
16
|
|
12
17
|
- Return columns in correct order
|
13
18
|
|
14
|
-
## 0.1.0
|
19
|
+
## 0.1.0 (2017-03-24)
|
15
20
|
|
16
21
|
- First release
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Ruby client for Apache Drill
|
4
4
|
|
5
|
-
[![Build Status](https://
|
5
|
+
[![Build Status](https://github.com/ankane/drill-sergeant/workflows/build/badge.svg?branch=master)](https://github.com/ankane/drill-sergeant/actions)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -16,7 +16,7 @@ drill-embedded
|
|
16
16
|
And add this line to your application’s Gemfile:
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
gem
|
19
|
+
gem "drill-sergeant"
|
20
20
|
```
|
21
21
|
|
22
22
|
## How to Use
|
@@ -99,3 +99,12 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
|
|
99
99
|
- Fix bugs and [submit pull requests](https://github.com/ankane/drill-sergeant/pulls)
|
100
100
|
- Write, clarify, or fix documentation
|
101
101
|
- Suggest or add new features
|
102
|
+
|
103
|
+
To get started with development:
|
104
|
+
|
105
|
+
```sh
|
106
|
+
git clone https://github.com/ankane/drill-sergeant.git
|
107
|
+
cd drill-sergeant
|
108
|
+
bundle install
|
109
|
+
bundle exec rake test
|
110
|
+
```
|
data/lib/drill/version.rb
CHANGED
data/lib/drill-sergeant.rb
CHANGED
@@ -6,6 +6,7 @@ require "net/http"
|
|
6
6
|
# modules
|
7
7
|
require "drill/version"
|
8
8
|
|
9
|
+
# TODO make module and move to client
|
9
10
|
class Drill
|
10
11
|
class Error < StandardError; end
|
11
12
|
|
@@ -17,7 +18,7 @@ class Drill
|
|
17
18
|
def initialize(url: nil, open_timeout: 3, read_timeout: nil)
|
18
19
|
url ||= ENV["DRILL_URL"] || "http://localhost:8047"
|
19
20
|
# remove trailing slash
|
20
|
-
@uri = URI.parse(url.
|
21
|
+
@uri = URI.parse(url.chomp("/"))
|
21
22
|
@http = Net::HTTP.new(@uri.host, @uri.port)
|
22
23
|
@http.use_ssl = true if @uri.scheme == "https"
|
23
24
|
@http.open_timeout = open_timeout if open_timeout
|
@@ -25,20 +26,11 @@ class Drill
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def query(statement)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
|
-
body = post("query.json", data)
|
34
|
-
|
35
|
-
# return columns in order
|
36
|
-
result = []
|
37
|
-
columns = body["columns"]
|
38
|
-
body["rows"].each do |row|
|
39
|
-
result << columns.each_with_object({}) { |c, memo| memo[c] = row[c] }
|
29
|
+
options = {}
|
30
|
+
if Gem::Version.new(server_version) >= Gem::Version.new("1.19.0")
|
31
|
+
options["drill.exec.http.rest.errors.verbose"] = true
|
40
32
|
end
|
41
|
-
|
33
|
+
run_query(statement, options)
|
42
34
|
end
|
43
35
|
|
44
36
|
def profiles(query_id = nil)
|
@@ -64,8 +56,35 @@ class Drill
|
|
64
56
|
get("options.json")
|
65
57
|
end
|
66
58
|
|
59
|
+
def server_version
|
60
|
+
@server_version ||= run_query("SELECT version FROM sys.version", {})[0]["version"]
|
61
|
+
end
|
62
|
+
|
67
63
|
private
|
68
64
|
|
65
|
+
def run_query(statement, options)
|
66
|
+
data = {
|
67
|
+
queryType: "sql",
|
68
|
+
query: statement,
|
69
|
+
options: options
|
70
|
+
}
|
71
|
+
|
72
|
+
body = post("query.json", data)
|
73
|
+
|
74
|
+
# errors return 200 with Drill 1.19+
|
75
|
+
if body["queryState"] != "COMPLETED"
|
76
|
+
raise Error, body["errorMessage"] || "Bad state: #{body["queryState"]}"
|
77
|
+
end
|
78
|
+
|
79
|
+
# return columns in order
|
80
|
+
result = []
|
81
|
+
columns = body["columns"]
|
82
|
+
body["rows"].each do |row|
|
83
|
+
result << columns.each_with_object({}) { |c, memo| memo[c] = row[c] }
|
84
|
+
end
|
85
|
+
result
|
86
|
+
end
|
87
|
+
|
69
88
|
def get(path)
|
70
89
|
handle_response do
|
71
90
|
@http.get("#{@uri.request_uri}#{path}", HEADERS)
|
@@ -82,13 +101,13 @@ class Drill
|
|
82
101
|
begin
|
83
102
|
response = yield
|
84
103
|
rescue Errno::ECONNREFUSED => e
|
85
|
-
raise
|
104
|
+
raise Error, e.message
|
86
105
|
end
|
87
106
|
|
88
107
|
unless response.kind_of?(Net::HTTPSuccess)
|
89
|
-
body = JSON.parse(response.body) rescue
|
108
|
+
body = JSON.parse(response.body) rescue {}
|
90
109
|
message = body["errorMessage"] || "Bad response: #{response.code}"
|
91
|
-
raise
|
110
|
+
raise Error, message
|
92
111
|
end
|
93
112
|
|
94
113
|
JSON.parse(response.body)
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email: andrew@chartkick.com
|
57
57
|
executables: []
|
58
58
|
extensions: []
|
@@ -67,7 +67,7 @@ homepage: https://github.com/ankane/drill-sergeant
|
|
67
67
|
licenses:
|
68
68
|
- MIT
|
69
69
|
metadata: {}
|
70
|
-
post_install_message:
|
70
|
+
post_install_message:
|
71
71
|
rdoc_options: []
|
72
72
|
require_paths:
|
73
73
|
- lib
|
@@ -82,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
rubygems_version: 3.
|
86
|
-
signing_key:
|
85
|
+
rubygems_version: 3.3.3
|
86
|
+
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Ruby client for Apache Drill
|
89
89
|
test_files: []
|