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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cdb7282b775f1c7230459d0a2479c1e555f951d
4
- data.tar.gz: 1233bc819be136fccf7a3016cd703dc7b84835d1
3
+ metadata.gz: 80d003315bf5824c3353dd3ebd29e9ece7cd2bcd
4
+ data.tar.gz: 93b0259479a5e8dfa5c71ad5b44729f53ce5d9a7
5
5
  SHA512:
6
- metadata.gz: e3f4a2c584488f9cdd57d99d847d735bd705422c912abdf8c6be59e5c363d8b814b6d9497f99b3d29c407207065062bd6f7941a3fe5cd3a21992f621c5f78831
7
- data.tar.gz: a34d46fd69ceb73ebcc876a8bb9dc24c8f2df2e62513c597d5ab9804dc6fc35e65cb8e4158e3bb12370f42471565d2d936f9f790f1cb699a6dba459e27ad4262
6
+ metadata.gz: 693314e6cdddd0341a58fa51cd18c2e3fdce9e493889a5fc76383af6f8deee14c11abf5ffe0f6c85e3d5c4c75c0c5e135356076c92c316b53898ebb66c59d866
7
+ data.tar.gz: 92eea0291ab3c39ea6bc7dde2e7c1c92395a2d1a76f5324fececd35d4bed2c7ebc4b1c709a94a314c579388693227fec08bec0c4d0fc8ecb91cd6c84ad73f654
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.1
2
+
3
+ - Return columns in correct order
4
+
1
5
  ## 0.1.0
2
6
 
3
7
  - First release
data/README.md CHANGED
@@ -18,8 +18,15 @@ gem 'drill-sergeant'
18
18
 
19
19
  ## How to Use
20
20
 
21
+ Create a client
22
+
21
23
  ```ruby
22
24
  drill = Drill.new(url: "http://localhost:8047")
25
+ ```
26
+
27
+ And query away
28
+
29
+ ```ruby
23
30
  drill.query("SELECT * FROM dfs.`/path/to/some/file.csvh`")
24
31
  ```
25
32
 
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
- @uri = URI.parse("#{url}/query.json")
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, header)
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
- body["rows"]
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
@@ -1,3 +1,3 @@
1
1
  class Drill
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drill-sergeant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane