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.
78 79 80 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 78 def error_count Array(@gapi.insert_errors).count end |
#error_rows ⇒ Array<Hash>
The rows that were not inserted.
101 102 103 104 105 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 101 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
.
129 130 131 132 133 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 129 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.
143 144 145 146 147 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 143 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.
69 70 71 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 69 def insert_count @rows.count - error_count end |
#insert_error_for(row) ⇒ InsertError?
Returns the error object for a row that was not inserted.
115 116 117 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 115 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.
87 88 89 90 91 92 93 |
# File 'lib/google/cloud/bigquery/insert_response.rb', line 87 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 |