drill_adapter.rb 767 B

123456789101112131415161718192021222324252627282930
  1. module Blazer
  2. module Adapters
  3. class DrillAdapter < BaseAdapter
  4. def run_statement(statement, comment)
  5. columns = []
  6. rows = []
  7. error = nil
  8. header = {"Content-Type" => "application/json", "Accept" => "application/json"}
  9. data = {
  10. queryType: "sql",
  11. query: statement
  12. }
  13. uri = URI.parse("#{settings["url"]}/query.json")
  14. http = Net::HTTP.new(uri.host, uri.port)
  15. begin
  16. response = JSON.parse(http.post(uri.request_uri, data.to_json, header).body)
  17. columns = response["columns"]
  18. rows = response["rows"].map { |r| r.values }
  19. rescue => e
  20. error = e.message
  21. end
  22. [columns, rows, error]
  23. end
  24. end
  25. end
  26. end