class BigQuery::Jobs::RunQuery
Public Class Methods
new(client, query, options)
click to toggle source
# File lib/bigquery-client/run_query.rb, line 4 def initialize(client, query, options) @client, @query, @options = client, query, options end
Public Instance Methods
call()
click to toggle source
# File lib/bigquery-client/run_query.rb, line 8 def call @result = ResultSet.new execute_query fetch_pagenated_result @result end
Private Instance Methods
execute_query()
click to toggle source
# File lib/bigquery-client/run_query.rb, line 17 def execute_query response = @client.jobs_query(@query, @options) @page_token = response['pageToken'] fields = response['schema']['fields'] @result.job_id = response['jobReference']['jobId'] @result.column_names = fields.map {|field| field['name'] } @result.column_types = fields.map {|field| field['type'] } @result.records = extract_records(response) end
extract_records(response)
click to toggle source
# File lib/bigquery-client/run_query.rb, line 35 def extract_records(response) (response['rows'] || []).map {|row| row['f'].map {|record| record['v'] } } end
fetch_pagenated_result()
click to toggle source
# File lib/bigquery-client/run_query.rb, line 27 def fetch_pagenated_result while @page_token response = @client.query_results(@result.job_id, { pageToken: @page_token }.merge(@options)) @result.records += extract_records(response) @page_token = response['pageToken'] end end