|
@@ -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
|