BigQuery API - Class Google::Cloud::Bigquery::Table::AsyncInserter::Result (v1.48.0)

Reference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::Table::AsyncInserter::Result.

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 Google::Cloud::Bigquery::Table#insert_async.

Inherits

  • Object

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!

Methods

#error

def error() -> Error, nil

The error from the insert operation if any error was encountered, otherwise nil.

Returns
  • (Error, nil) — the current value of error

#error?

def error?() -> Boolean

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.

Returns
  • (Boolean) — true when an error is present, false otherwise.

#error_count

def error_count() -> Integer, nil

The count of errors for rows that were not inserted.

Returns
  • (Integer, nil) — The number of errors, or nil if the insert operation encountered an error.

#error_rows

def error_rows() -> Array<Hash>, nil

The rows that were not inserted.

Returns
  • (Array<Hash>, nil) — An array of hash objects containing the row data, or nil if the insert operation encountered an error.

#errors_for

def errors_for(row) -> Array<Hash>, nil

Returns the error hashes for a row that was not inserted. Each error hash contains the following keys: reason, location, debugInfo, and message.

Parameter
  • row (Hash, nil) — A hash containing the data for a row.
Returns
  • (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.

#index_for

def index_for(row) -> Integer, nil

Returns the index for a row that was not inserted.

Parameter
  • row (Hash, nil) — A hash containing the data for a row.
Returns
  • (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.

#insert_count

def insert_count() -> Integer, nil

The count of rows in the response, minus the count of errors for rows that were not inserted.

Returns
  • (Integer, nil) — The number of rows inserted, or nil if the insert operation encountered an error.

#insert_error_for

def insert_error_for(row) -> InsertError, nil

Returns the error object for a row that was not inserted.

Parameter
  • row (Hash) — A hash containing the data for a row.
Returns
  • (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.

#insert_errors

def insert_errors() -> Array<InsertError>, nil

The error objects for rows that were not inserted.

Returns
  • (Array<InsertError>, nil) — An array containing error objects, or nil if the insert operation encountered an error.

#insert_response

def insert_response() -> Google::Cloud::Bigquery::InsertResponse, nil

The response from the insert operation if no error was encountered, or nil if the insert operation encountered an error.

Returns

#success?

def success?() -> Boolean, nil

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.

Returns
  • (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.