class Daru::TD::ResultProxy
Attributes
engine[R]
job[R]
Public Class Methods
new(engine, job)
click to toggle source
# File lib/daru/td/result_proxy.rb, line 11 def initialize(engine, job) @engine = engine @job = job @http = nil end
Public Instance Methods
description()
click to toggle source
# File lib/daru/td/result_proxy.rb, line 30 def description if !job.finished? job.wait() end job.hive_result_schema end
each_record(&block)
click to toggle source
# File lib/daru/td/result_proxy.rb, line 42 def each_record(&block) MessagePack::Unpacker.new(self).each(&block) end
readpartial(len=16384, outbuf="")
click to toggle source
# File lib/daru/td/result_proxy.rb, line 37 def readpartial(len=16384, outbuf="") @result_io ||= open_result_io() @result_io.readpartial(len, outbuf) end
size()
click to toggle source
# File lib/daru/td/result_proxy.rb, line 23 def size if !job.finished? job.wait() end job.result_size end
status()
click to toggle source
# File lib/daru/td/result_proxy.rb, line 19 def status job.status end
to_dataframe(parse_dates: nil)
click to toggle source
# File lib/daru/td/result_proxy.rb, line 46 def to_dataframe(parse_dates: nil) fields = description.map {|c| c[0].to_sym } Daru::DataFrame.new([], order: fields).tap do |df| each_record do |record| df.add_row(record) end if parse_dates parse_date_fields(df, parse_dates) end if engine.clear_progress IRuby::Display.clear_output() end end end
Private Instance Methods
content_downloader()
click to toggle source
# File lib/daru/td/result_proxy.rb, line 75 def content_downloader ContentDownloader.new(self, job_result_uri, http_header) do |downloader| engine.wait_callback(job, downloader.downloaded_size) end end
http_header()
click to toggle source
# File lib/daru/td/result_proxy.rb, line 89 def http_header { 'Authorization' => "TD1 #{self.engine.connection.apikey}", 'Accept-Encoding' => 'deflate, gzip', 'User-Agent' => "daru-td/#{Daru::TD::VERSION} (Ruby #{RUBY_VERSION})", } end
job_result_uri()
click to toggle source
# File lib/daru/td/result_proxy.rb, line 81 def job_result_uri endpoint_uri = URI.parse(self.engine.connection.endpoint) unless endpoint_uri.scheme endpoint_uri = URI.parse("https://#{endpoint_uri}") end URI.join(endpoint_uri, "v3/job/result/#{job.job_id}?format=msgpack.gz") end
open_result_io()
click to toggle source
# File lib/daru/td/result_proxy.rb, line 71 def open_result_io Zlib::GzipReader.new(content_downloader()) end
parse_date_fields(df, fields)
click to toggle source
# File lib/daru/td/result_proxy.rb, line 63 def parse_date_fields(df, fields) fields.each do |name| parsed_values = df[name].map {|v| DateTime.parse(v) } df[name] = Daru::Vector.new(parsed_values, name: name) end df end