class Blazer::Adapters::HiveAdapter

Public Instance Methods

parameter_binding() click to toggle source

has variable substitution, but sets for session cwiki.apache.org/confluence/display/Hive/LanguageManual+VariableSubstitution

# File lib/blazer/adapters/hive_adapter.rb, line 35
def parameter_binding
end
preview_statement() click to toggle source
# File lib/blazer/adapters/hive_adapter.rb, line 24
def preview_statement
  "SELECT * FROM {table} LIMIT 10"
end
quoting() click to toggle source

cwiki.apache.org/confluence/display/Hive/LanguageManual+Types#LanguageManualTypes-StringsstringStrings

# File lib/blazer/adapters/hive_adapter.rb, line 29
def quoting
  :backslash_escape
end
run_statement(statement, comment) click to toggle source
# File lib/blazer/adapters/hive_adapter.rb, line 4
def run_statement(statement, comment)
  columns = []
  rows = []
  error = nil

  begin
    result = client.execute("#{statement} /*#{comment}*/")
    columns = result.any? ? result.first.keys : []
    rows = result.map(&:values)
  rescue => e
    error = e.message
  end

  [columns, rows, error]
end
tables() click to toggle source
# File lib/blazer/adapters/hive_adapter.rb, line 20
def tables
  client.execute("SHOW TABLES").map { |r| r["tab_name"] }
end

Protected Instance Methods

client() click to toggle source
# File lib/blazer/adapters/hive_adapter.rb, line 40
def client
  @client ||= begin
    uri = URI.parse(settings["url"])
    Hexspace::Client.new(
      host: uri.host,
      port: uri.port,
      username: uri.user,
      password: uri.password,
      database: uri.path.delete_prefix("/"),
      mode: uri.scheme.to_sym
    )
  end
end