Prechádzať zdrojové kódy

Added beta support for Apache Drill

Andrew Kane 7 rokov pred
rodič
commit
e5cfa0faf9
4 zmenil súbory, kde vykonal 48 pridanie a 0 odobranie
  1. 4 0
      CHANGELOG.md
  2. 12 0
      README.md
  3. 2 0
      lib/blazer.rb
  4. 30 0
      lib/blazer/adapters/drill_adapter.rb

+ 4 - 0
CHANGELOG.md

@@ -1,3 +1,7 @@
+## 1.7.9 [unreleased]
+
+- Added beta support for Apache Drill
+
 ## 1.7.8
 
 - Added support for custom adapters

+ 12 - 0
README.md

@@ -393,6 +393,7 @@ data_sources:
 - [Presto](#presto)
 - [MongoDB](#mongodb-1) [beta]
 - [Elasticsearch](#elasticsearch) [beta]
+- [Apache Drill](#apache-drill-master)[beta]
 
 You can also [create an adapter](#creating-an-adapter) for any other data store.
 
@@ -493,6 +494,17 @@ data_sources:
     url: http://user:password@hostname:9200/
 ```
 
+### Apache Drill [master]
+
+Set:
+
+```yml
+data_sources:
+  my_source:
+    adapter: drill
+    url: http://hostname:8047
+```
+
 ## Creating an Adapter
 
 Create an adapter for any data store with:

+ 2 - 0
lib/blazer.rb

@@ -7,6 +7,7 @@ require "blazer/data_source"
 require "blazer/result"
 require "blazer/run_statement"
 require "blazer/adapters/base_adapter"
+require "blazer/adapters/drill_adapter"
 require "blazer/adapters/elasticsearch_adapter"
 require "blazer/adapters/mongodb_adapter"
 require "blazer/adapters/presto_adapter"
@@ -158,6 +159,7 @@ module Blazer
   end
 end
 
+Blazer.register_adapter "drill", Blazer::Adapters::DrillAdapter
 Blazer.register_adapter "elasticsearch", Blazer::Adapters::ElasticsearchAdapter
 Blazer.register_adapter "mongodb", Blazer::Adapters::MongodbAdapter
 Blazer.register_adapter "presto", Blazer::Adapters::PrestoAdapter

+ 30 - 0
lib/blazer/adapters/drill_adapter.rb

@@ -0,0 +1,30 @@
+module Blazer
+  module Adapters
+    class DrillAdapter < BaseAdapter
+      def run_statement(statement, comment)
+        columns = []
+        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)
+
+        begin
+          response = JSON.parse(http.post(uri.request_uri, data.to_json, header).body)
+          columns = response["columns"]
+          rows = response["rows"].map { |r| r.values }
+        rescue => e
+          error = e.message
+        end
+
+        [columns, rows, error]
+      end
+    end
+  end
+end