BigQuery API - Class Google::Cloud::Bigquery::InsertResponse (v1.48.1)

Reference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::InsertResponse.

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.

Inherits

  • Object

Example

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"

rows = [
  { "first_name" => "Alice", "age" => 21 },
  { "first_name" => "Bob", "age" => 22 }
]

insert_response = dataset.insert "my_table", rows

Methods

#error_count

def error_count() -> Integer

The count of errors for rows that were not inserted.

Returns
  • (Integer) — The number of errors.

#error_rows

def error_rows() -> Array<Hash>

The rows that were not inserted.

Returns
  • (Array<Hash>) — An array of hash objects containing the row data.

#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) — A hash containing the data for a row.
Returns
  • (Array<Hash>, nil) — An array of error hashes, or nil if no errors are found in the response for the row.

#index_for

def index_for(row) -> Integer, nil

Returns the index for a row that was not inserted.

Parameter
  • row (Hash) — A hash containing the data for a row.
Returns
  • (Integer, nil) — An error object, or nil if no error is found in the response for the row.

#insert_count

def insert_count() -> Integer

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

Returns
  • (Integer) — The number of rows inserted.

#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, or nil if no error is found in the response for the row.

#insert_errors

def insert_errors() -> Array<InsertError>

The error objects for rows that were not inserted.

Returns
  • (Array<InsertError>) — An array containing error objects.

#success?

def success?() -> Boolean

Checks if the error count is zero, meaning that all of the rows were inserted. Use #insert_errors to access the errors.

Returns
  • (Boolean) — true when the error count is zero, false otherwise.