Class: Google::Cloud::Bigquery::Data
- Inherits:
-
Array
- Object
- Array
- Google::Cloud::Bigquery::Data
- Defined in:
- lib/google/cloud/bigquery/data.rb
Overview
Data
Represents Table Data as a list of name/value pairs.
Also contains metadata such as etag
and total
.
Direct Known Subclasses
Class Method Summary collapse
-
.format_rows(rows, fields) ⇒ Object
rubocop:disable all Disabled rubocop because this implementation will not last.
- .format_values(field_types, values) ⇒ Object
Instance Method Summary collapse
- #all(request_limit: nil) {|row| ... } ⇒ Enumerator
-
#etag ⇒ Object
The etag.
-
#kind ⇒ Object
The resource type of the API response.
-
#next ⇒ Data
Retrieve the next page of data.
-
#next? ⇒ Boolean
Whether there is a next page of data.
-
#raw ⇒ Object
Represents Table Data as a list of positional values (array of arrays).
-
#token ⇒ Object
A token used for paging results.
-
#total ⇒ Object
The total number of rows in the complete table.
Class Method Details
.format_rows(rows, fields) ⇒ Object
rubocop:disable all Disabled rubocop because this implementation will not last.
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/google/cloud/bigquery/data.rb', line 202 def self.format_rows rows, fields headers = Array(fields).map { |f| f.name } field_types = Array(fields).map { |f| f.type } Array(rows).map do |row| values = row.f.map { |f| f.v } formatted_values = format_values field_types, values Hash[headers.zip formatted_values] end end |
.format_values(field_types, values) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/google/cloud/bigquery/data.rb', line 213 def self.format_values field_types, values field_types.zip(values).map do |type, value| begin if value.nil? nil elsif type == "INTEGER" Integer value elsif type == "FLOAT" Float value elsif type == "BOOLEAN" (value == "true" ? true : (value == "false" ? false : nil)) else value end rescue value end end end |
Instance Method Details
#all(request_limit: nil) {|row| ... } ⇒ Enumerator
Retrieves all rows by repeatedly loading #next until #next?
returns false
. Calls the given block once for each row, which is
passed as the parameter.
An Enumerator is returned if no block is given.
This method may make several API calls until all rows are retrieved. Be sure to use as narrow a search criteria as possible. Please use with caution.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/google/cloud/bigquery/data.rb', line 163 def all request_limit: nil request_limit = request_limit.to_i if request_limit unless block_given? return enum_for(:all, request_limit: request_limit) end results = self loop do results.each { |r| yield r } if request_limit request_limit -= 1 break if request_limit < 0 end break unless results.next? results = results.next end end |
#etag ⇒ Object
The etag.
51 52 53 |
# File 'lib/google/cloud/bigquery/data.rb', line 51 def etag @gapi.etag end |
#kind ⇒ Object
The resource type of the API response.
45 46 47 |
# File 'lib/google/cloud/bigquery/data.rb', line 45 def kind @gapi.kind end |
#next ⇒ Data
Retrieve the next page of data.
106 107 108 109 110 |
# File 'lib/google/cloud/bigquery/data.rb', line 106 def next return nil unless next? ensure_table! table.data token: token end |
#next? ⇒ Boolean
Whether there is a next page of data.
85 86 87 |
# File 'lib/google/cloud/bigquery/data.rb', line 85 def next? !token.nil? end |
#raw ⇒ Object
Represents Table Data as a list of positional values (array of arrays). No type conversion is made, e.g. numbers are formatted as strings.
184 185 186 |
# File 'lib/google/cloud/bigquery/data.rb', line 184 def raw Array(gapi.rows).map { |row| row.f.map(&:v) } end |
#token ⇒ Object
A token used for paging results.
57 58 59 |
# File 'lib/google/cloud/bigquery/data.rb', line 57 def token @gapi.page_token end |
#total ⇒ Object
The total number of rows in the complete table.
62 63 64 65 66 |
# File 'lib/google/cloud/bigquery/data.rb', line 62 def total Integer @gapi.total_rows rescue nil end |