class Trino::Client::Client

Public Class Methods

new(options) click to toggle source
# File lib/trino/client/client.rb, line 22
def initialize(options)
  @options = options
end

Public Instance Methods

kill(query_id) click to toggle source
# File lib/trino/client/client.rb, line 43
def kill(query_id)
  return Query.kill(query_id, @options)
end
query(query) { |q| ... } click to toggle source
# File lib/trino/client/client.rb, line 26
def query(query, &block)
  q = Query.start(query, @options)
  if block
    begin
      yield q
    ensure
      q.close
    end
  else
    return q
  end
end
resume_query(next_uri) click to toggle source
# File lib/trino/client/client.rb, line 39
def resume_query(next_uri)
  return Query.resume(next_uri, @options)
end
run(query) click to toggle source
# File lib/trino/client/client.rb, line 47
def run(query)
  q = Query.start(query, @options)
  begin
    columns = q.columns
    if columns.empty?
      return [], []
    end
    return columns, q.rows
  ensure
    q.close
  end
end
run_with_names(query) click to toggle source

Accepts the raw response from the Trino Client and returns an array of hashes where you can access the data in each row using the output name specified in the query with AS:

SELECT expression AS output_name
# File lib/trino/client/client.rb, line 64
def run_with_names(query)
  columns, rows = run(query)

  column_names = columns.map(&:name)

  rows.map do |row|
    Hash[column_names.zip(row)]
  end
end