Class: Google::Cloud::Bigquery::Table::AsyncInserter::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/bigquery/table/async_inserter.rb

Overview

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.

Examples:

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!

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorError? (readonly)

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

Returns:

  • (Error, nil)

    the current value of error



391
392
393
# File 'lib/google/cloud/bigquery/table/async_inserter.rb', line 391

def error
  @error
end

#insert_responseGoogle::Cloud::Bigquery::InsertResponse? (readonly)

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

Returns:



391
392
393
# File 'lib/google/cloud/bigquery/table/async_inserter.rb', line 391

def insert_response
  @insert_response
end

Instance Method Details

#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.



408
409
410
# File 'lib/google/cloud/bigquery/table/async_inserter.rb', line 408

def error?
  !error.nil?
end

#error_countInteger?

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.



445
446
447
448
# File 'lib/google/cloud/bigquery/table/async_inserter.rb', line 445

def error_count
  return nil if error?
  insert_response.error_count
end

#error_rowsArray<Hash>?

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.



467
468
469
470
# File 'lib/google/cloud/bigquery/table/async_inserter.rb', line 467

def error_rows
  return nil if error?
  insert_response.error_rows
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.

Parameters:

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



497
498
499
500
# File 'lib/google/cloud/bigquery/table/async_inserter.rb', line 497

def errors_for row
  return nil if error?
  insert_response.errors_for row
end

#index_for(row) ⇒ Integer?

Returns the index for a row that was not inserted.

Parameters:

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



511
512
513
514
# File 'lib/google/cloud/bigquery/table/async_inserter.rb', line 511

def index_for row
  return nil if error?
  insert_response.index_for row
end

#insert_countInteger?

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.



434
435
436
437
# File 'lib/google/cloud/bigquery/table/async_inserter.rb', line 434

def insert_count
  return nil if error?
  insert_response.insert_count
end

#insert_error_for(row) ⇒ InsertError?

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

Parameters:

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



481
482
483
484
# File 'lib/google/cloud/bigquery/table/async_inserter.rb', line 481

def insert_error_for row
  return nil if error?
  insert_response.insert_error_for row
end

#insert_errorsArray<InsertError>?

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.



456
457
458
459
# File 'lib/google/cloud/bigquery/table/async_inserter.rb', line 456

def insert_errors
  return nil if error?
  insert_response.insert_errors
end

#success?Boolean?

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.



422
423
424
425
# File 'lib/google/cloud/bigquery/table/async_inserter.rb', line 422

def success?
  return nil if error?
  insert_response.success?
end