Class: Gcloud::Bigquery::InsertResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/bigquery/insert_response.rb

Overview

InsertResponse

Defined Under Namespace

Classes: InsertError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows, gapi) ⇒ InsertResponse

Returns a new instance of InsertResponse.



24
25
26
27
# File 'lib/gcloud/bigquery/insert_response.rb', line 24

def initialize rows, gapi
  @rows = rows
  @gapi = gapi
end

Class Method Details

.from_gapi(rows, gapi) ⇒ Object

Google::Apis::BigqueryV2::InsertAllTableDataResponse object.



63
64
65
# File 'lib/gcloud/bigquery/insert_response.rb', line 63

def self.from_gapi rows, gapi
  new rows, gapi
end

Instance Method Details

#error_countObject



37
38
39
# File 'lib/gcloud/bigquery/insert_response.rb', line 37

def error_count
  Array(@gapi.insert_errors).count
end

#error_rowsObject



49
50
51
52
53
# File 'lib/gcloud/bigquery/insert_response.rb', line 49

def error_rows
  Array(@gapi.insert_errors).map do |ie|
    @rows[ie.index]
  end
end

#errors_for(row) ⇒ Object



55
56
57
58
59
# File 'lib/gcloud/bigquery/insert_response.rb', line 55

def errors_for row
  ie = insert_errors.detect { |e| e.row == row }
  return ie.errors if ie
  []
end

#insert_countObject



33
34
35
# File 'lib/gcloud/bigquery/insert_response.rb', line 33

def insert_count
  @rows.count - error_count
end

#insert_errorsObject



41
42
43
44
45
46
47
# File 'lib/gcloud/bigquery/insert_response.rb', line 41

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 row, errors
  end
end

#success?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/gcloud/bigquery/insert_response.rb', line 29

def success?
  error_count.zero?
end