lib/gcloud/bigquery/insert_response.rb in gcloud-0.11.0 vs lib/gcloud/bigquery/insert_response.rb in gcloud-0.12.0
- old
+ new
@@ -11,10 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+require "json"
+
module Gcloud
module Bigquery
##
# InsertResponse
class InsertResponse
@@ -27,43 +29,39 @@
def success?
error_count.zero?
end
def insert_count
- @insert_count ||= @rows.count - error_count
+ @rows.count - error_count
end
def error_count
- @error_count ||= Array(@gapi["insertErrors"]).count
+ Array(@gapi.insert_errors).count
end
def insert_errors
- @insert_errors ||= begin
- Array(@gapi["insertErrors"]).map do |ie|
- row = @rows[ie["index"]]
- errors = ie["errors"]
- InsertError.new row, errors
- end
+ 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
def error_rows
- @error_rows ||= begin
- Array(@gapi["insertErrors"]).map do |ie|
- @rows[ie["index"]]
- end
+ Array(@gapi.insert_errors).map do |ie|
+ @rows[ie.index]
end
end
def errors_for row
ie = insert_errors.detect { |e| e.row == row }
return ie.errors if ie
[]
end
- # @private
+ # @private New InsertResponse from the inserted rows and a
+ # Google::Apis::BigqueryV2::InsertAllTableDataResponse object.
def self.from_gapi rows, gapi
- gapi = gapi.to_hash if gapi.respond_to? :to_hash
new rows, gapi
end
##
# InsertError