class Google::Cloud::Bigquery::Table::AsyncInserter::Result
Represents the result from BigQuery, including any error encountered, when data is asynchronously inserted into a table for near-immediate querying. See {Dataset#insert_async} and {Table#insert_async}.
@see cloud.google.com/bigquery/streaming-data-into-bigquery
Streaming Data Into BigQuery
@attr_reader [Google::Cloud::Bigquery::InsertResponse, nil]
insert_response The response from the insert operation if no error was encountered, or `nil` if the insert operation encountered an error.
@attr_reader [Error, nil] error The error from the insert operation
if any error was encountered, otherwise `nil`.
@example
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new dataset = bigquery.dataset "my_dataset" table = dataset.table "my_table" inserter = table.insert_async do |result| if result.error? log_error result.error else log_insert "inserted #{result.insert_count} rows " \ "with #{result.error_count} errors" end end rows = [ { "first_name" => "Alice", "age" => 21 }, { "first_name" => "Bob", "age" => 22 } ] inserter.insert rows inserter.stop.wait!
Attributes
Public Class Methods
@private
# File lib/google/cloud/bigquery/table/async_inserter.rb, line 420 def initialize insert_response, error = nil @insert_response = insert_response @error = error end
Public Instance Methods
Checks if an error is present, meaning that the insert operation encountered an error. Use {#error} to access the error. For row-level errors, see {#success?} and {#insert_errors}.
@return [Boolean] `true` when an error is present, `false`
otherwise.
# File lib/google/cloud/bigquery/table/async_inserter.rb, line 436 def error? !error.nil? end
The count of errors for rows that were not inserted.
@return [Integer, nil] The number of errors, or `nil` if the
insert operation encountered an error.
# File lib/google/cloud/bigquery/table/async_inserter.rb, line 473 def error_count return nil if error? insert_response.error_count end
The rows that were not inserted.
@return [Array<Hash>, nil] An array of hash objects containing the
row data, or `nil` if the insert operation encountered an error.
# File lib/google/cloud/bigquery/table/async_inserter.rb, line 495 def error_rows return nil if error? insert_response.error_rows end
Returns the error hashes for a row that was not inserted. Each error hash contains the following keys: `reason`, `location`, `debugInfo`, and `message`.
@param [Hash, nil] row A hash containing the data for a row.
@return [Array<Hash>, nil] An array of error hashes, `nil` if no
errors are found in the response for the row, or `nil` if the insert operation encountered an error.
# File lib/google/cloud/bigquery/table/async_inserter.rb, line 525 def errors_for row return nil if error? insert_response.errors_for row end
Returns the index for a row that was not inserted.
@param [Hash, nil] row A hash containing the data for a row.
@return [Integer, nil] An error object, `nil` if no error is
found in the response for the row, or `nil` if the insert operation encountered an error.
# File lib/google/cloud/bigquery/table/async_inserter.rb, line 539 def index_for row return nil if error? insert_response.index_for row end
The count of rows in the response, minus the count of errors for rows that were not inserted.
@return [Integer, nil] The number of rows inserted, or `nil` if
the insert operation encountered an error.
# File lib/google/cloud/bigquery/table/async_inserter.rb, line 462 def insert_count return nil if error? insert_response.insert_count end
Returns the error object for a row that was not inserted.
@param [Hash] row A hash containing the data for a row.
@return [InsertError, nil] An error object, `nil` if no error is
found in the response for the row, or `nil` if the insert operation encountered an error.
# File lib/google/cloud/bigquery/table/async_inserter.rb, line 509 def insert_error_for row return nil if error? insert_response.insert_error_for row end
The error objects for rows that were not inserted.
@return [Array<InsertError>, nil] An array containing error
objects, or `nil` if the insert operation encountered an error.
# File lib/google/cloud/bigquery/table/async_inserter.rb, line 484 def insert_errors return nil if error? insert_response.insert_errors end
Checks if the error count for row-level errors is zero, meaning that all of the rows were inserted. Use {#insert_errors} to access the row-level errors. To check for and access any operation-level error, use {#error?} and {#error}.
@return [Boolean, nil] `true` when the error count is zero,
`false` when the error count is positive, or `nil` if the insert operation encountered an error.
# File lib/google/cloud/bigquery/table/async_inserter.rb, line 450 def success? return nil if error? insert_response.success? end