Class: Google::Cloud::Bigquery::InsertResponse
- Inherits:
-
Object
- Object
- Google::Cloud::Bigquery::InsertResponse
- Defined in:
- lib/google/cloud/bigquery/insert_response.rb
Overview
InsertResponse
Represents the response from BigQuery when data is inserted into a table for near-immediate querying, without the need to complete a load operation before the data can appear in query results. See Dataset#insert and Table#insert.
Defined Under Namespace
Classes: InsertError
Instance Method Summary collapse
-
#error_count ⇒ Integer
The count of errors for rows that were not inserted.
-
#error_rows ⇒ Array<Hash>
The rows that were not inserted.
-
#errors_for(row) ⇒ Array<Hash>?
Returns the error hashes for a row that was not inserted.
-
#index_for(row) ⇒ Integer?
Returns the index for a row that was not inserted.
-
#insert_count ⇒ Integer
The count of rows in the response, minus the count of errors for rows that were not inserted.
-
#insert_error_for(row) ⇒ InsertError?
Returns the error object for a row that was not inserted.
-
#insert_errors ⇒ Array<InsertError>
The error objects for rows that were not inserted.
-
#success? ⇒ Boolean
Checks if the error count is zero, meaning that all of the rows were inserted.
Instance Method Details
#error_count ⇒ Integer
The count of errors for rows that were not inserted.
80 81 82 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 80 def error_count Array(@gapi.insert_errors).count end |
#error_rows ⇒ Array<Hash>
The rows that were not inserted.
103 104 105 106 107 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 103 def error_rows Array(@gapi.insert_errors).map do |ie| @rows[ie.index] end end |
#errors_for(row) ⇒ Array<Hash>?
Returns the error hashes for a row that was not inserted. Each error
hash contains the following keys: reason
, location
, debugInfo
,
and message
.
131 132 133 134 135 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 131 def errors_for row ie = insert_error_for row return ie.errors if ie [] end |
#index_for(row) ⇒ Integer?
Returns the index for a row that was not inserted.
145 146 147 148 149 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 145 def index_for row ie = insert_error_for row return ie.index if ie nil end |
#insert_count ⇒ Integer
The count of rows in the response, minus the count of errors for rows that were not inserted.
70 71 72 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 70 def insert_count @rows.count - error_count end |
#insert_error_for(row) ⇒ InsertError?
Returns the error object for a row that was not inserted.
117 118 119 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 117 def insert_error_for row insert_errors.detect { |e| e.row == row } end |
#insert_errors ⇒ Array<InsertError>
The error objects for rows that were not inserted.
89 90 91 92 93 94 95 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 89 def insert_errors Array(@gapi.insert_errors).map do |ie| row = @rows[ie.index] errors = ie.errors.map { |e| JSON.parse e.to_json } InsertError.new ie.index, row, errors end end |
#success? ⇒ Boolean
Checks if the error count is zero, meaning that all of the rows were inserted. Use #insert_errors to access the errors.
59 60 61 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 59 def success? error_count.zero? end |