ソースを参照

Use drill-sergeant for Apache Drill

Andrew Kane 7 年 前
コミット
18ad8fb228
3 ファイル変更9 行追加21 行削除
  1. 4 4
      README.md
  2. 1 1
      app/views/blazer/queries/show.html.erb
  3. 4 16
      lib/blazer/adapters/drill_adapter.rb

+ 4 - 4
README.md

@@ -393,7 +393,7 @@ data_sources:
 - [Presto](#presto)
 - [MongoDB](#mongodb-1) [beta]
 - [Elasticsearch](#elasticsearch) [beta]
-- [Apache Drill](#apache-drill-master) [beta]
+- [Apache Drill](#apache-drill) [beta]
 
 You can also [create an adapter](#creating-an-adapter) for any other data store.
 
@@ -491,12 +491,12 @@ Add [elasticsearch](https://github.com/elastic/elasticsearch-ruby) to your Gemfi
 data_sources:
   my_source:
     adapter: elasticsearch
-    url: http://user:password@hostname:9200/
+    url: http://user:password@hostname:9200
 ```
 
-### Apache Drill [master]
+### Apache Drill
 
-Set:
+Add [drill-sergeant](https://github.com/ankane/drill-sergeant) to your Gemfile and set:
 
 ```yml
 data_sources:

+ 1 - 1
app/views/blazer/queries/show.html.erb

@@ -62,7 +62,7 @@
   </script>
 <% end %>
 
-<% if %w[sql presto].include?(Blazer.data_sources[@query.data_source].adapter) %>
+<% if %w[sql presto drill].include?(Blazer.data_sources[@query.data_source].adapter) %>
   <script>
     // do not highlight really long queries
     // this can lead to performance issues

+ 4 - 16
lib/blazer/adapters/drill_adapter.rb

@@ -6,23 +6,11 @@ module Blazer
         rows = []
         error = nil
 
-        header = {"Content-Type" => "application/json", "Accept" => "application/json"}
-        data = {
-          queryType: "sql",
-          query: statement
-        }
-
-        uri = URI.parse("#{settings["url"]}/query.json")
-        http = Net::HTTP.new(uri.host, uri.port)
-
+        drill = ::Drill.new(url: settings["url"])
         begin
-          response = JSON.parse(http.post(uri.request_uri, data.to_json, header).body)
-          if response["errorMessage"]
-            error = response["errorMessage"]
-          else
-            columns = response["columns"]
-            rows = response["rows"].map { |r| r.values }
-          end
+          response = drill.query(statement)
+          rows = response.map { |r| r.values }
+          columns = rows.any? ? response.first.keys : []
         rescue => e
           error = e.message
         end