Class: Gcloud::Bigquery::QueryJob
- Defined in:
- lib/gcloud/bigquery/query_job.rb
Overview
QueryJob
A Job subclass representing a query operation that may be performed on a Table. A QueryJob instance is created when you call Project#query_job, Dataset#query_job, or View#data.
See Querying Data and the Jobs API reference for details.
Instance Attribute Summary
Attributes inherited from Job
Instance Method Summary collapse
-
#batch? ⇒ Boolean
Checks if the priority for the query is
BATCH
. -
#bytes_processed ⇒ Object
The number of bytes processed by the query.
-
#cache? ⇒ Boolean
Checks if the query job looks for an existing result in the query cache.
-
#cache_hit? ⇒ Boolean
Checks if the query results are from the query cache.
-
#destination ⇒ Object
The table in which the query results are stored.
-
#flatten? ⇒ Boolean
Checks if the query job flattens nested and repeated fields in the query results.
-
#interactive? ⇒ Boolean
Checks if the priority for the query is
INTERACTIVE
. -
#large_results? ⇒ Boolean
Checks if the the query job allows arbitrarily large results at a slight cost to performance.
-
#query_results(options = {}) ⇒ Object
Retrieves the query results for the job.
Methods inherited from Job
#configuration, #created_at, #done?, #ended_at, #error, #errors, #failed?, from_gapi, #initialize, #job_id, #pending?, #project_id, #refresh!, #rerun!, #running?, #started_at, #state, #statistics, #status
Constructor Details
This class inherits a constructor from Gcloud::Bigquery::Job
Instance Method Details
#batch? ⇒ Boolean
Checks if the priority for the query is BATCH
.
33 34 35 36 |
# File 'lib/gcloud/bigquery/query_job.rb', line 33 def batch? val = config["query"]["priority"] val == "BATCH" end |
#bytes_processed ⇒ Object
The number of bytes processed by the query.
83 84 85 |
# File 'lib/gcloud/bigquery/query_job.rb', line 83 def bytes_processed stats["query"]["totalBytesProcessed"] end |
#cache? ⇒ Boolean
Checks if the query job looks for an existing result in the query cache. For more information, see Query Caching.
59 60 61 62 63 |
# File 'lib/gcloud/bigquery/query_job.rb', line 59 def cache? val = config["query"]["useQueryCache"] return false if val.nil? val end |
#cache_hit? ⇒ Boolean
Checks if the query results are from the query cache.
77 78 79 |
# File 'lib/gcloud/bigquery/query_job.rb', line 77 def cache_hit? stats["query"]["cacheHit"] end |
#destination ⇒ Object
The table in which the query results are stored.
89 90 91 92 93 94 95 |
# File 'lib/gcloud/bigquery/query_job.rb', line 89 def destination table = config["query"]["destinationTable"] return nil unless table retrieve_table table["projectId"], table["datasetId"], table["tableId"] end |
#flatten? ⇒ Boolean
Checks if the query job flattens nested and repeated fields in the query results. The default is true
. If the value is false
, #large_results? should return true
.
69 70 71 72 73 |
# File 'lib/gcloud/bigquery/query_job.rb', line 69 def flatten? val = config["query"]["flattenResults"] return true if val.nil? val end |
#interactive? ⇒ Boolean
Checks if the priority for the query is INTERACTIVE
.
40 41 42 43 44 |
# File 'lib/gcloud/bigquery/query_job.rb', line 40 def interactive? val = config["query"]["priority"] return true if val.nil? val == "INTERACTIVE" end |
#large_results? ⇒ Boolean
Checks if the the query job allows arbitrarily large results at a slight cost to performance.
49 50 51 52 53 |
# File 'lib/gcloud/bigquery/query_job.rb', line 49 def large_results? val = config["query"]["preserveNulls"] return false if val.nil? val end |
#query_results(options = {}) ⇒ Object
Retrieves the query results for the job.
Parameters
options
-
An optional Hash for controlling additional behavior. (
Hash
) options[:token]
-
Page token, returned by a previous call, identifying the result set. (
String
) options[:max]
-
Maximum number of results to return. (
Integer
) options[:start]
-
Zero-based index of the starting row to read. (
Integer
) options[:timeout]
-
How long to wait for the query to complete, in milliseconds, before returning. Default is 10,000 milliseconds (10 seconds). (
Integer
)
Returns
Gcloud::Bigquery::QueryData
Example
require "gcloud"
gcloud = Gcloud.new
bigquery = gcloud.bigquery
q = "SELECT word FROM publicdata:samples.shakespeare"
job = bigquery.query_job q
loop do
break if job.done?
sleep 1
job.refresh!
end
data = job.query_results
data.each do |row|
puts row["word"]
end
data = data.next if data.next?
140 141 142 143 144 145 146 147 148 |
# File 'lib/gcloud/bigquery/query_job.rb', line 140 def query_results = {} ensure_connection! resp = connection.job_query_results job_id, if resp.success? QueryData.from_gapi resp.data, connection else fail ApiError.from_response(resp) end end |