Skip to content

Commit fcc18ac

Browse files
committed
Merge pull request abronte#43 from kysnm/fix_insert_all_table_data
Fix insert_all_table_data
2 parents e5bb214 + b8de40a commit fcc18ac

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/big_query/client/tables.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ def table_data(table_id, dataset_id = @dataset, options = {})
6969
# @param opts [Hash] field value hash to be inserted
7070
# @return [Hash]
7171
def insert(table_id, opts)
72-
request = Google::Apis::BigqueryV2::InsertAllTableDataRequest.new
73-
row = Google::Apis::BigqueryV2::InsertAllTableDataRequest::Row.new
7472
if opts.class == Array
75-
request.rows = opts.map{|x| row.json = x; row}
73+
rows = opts.map do |x|
74+
Google::Apis::BigqueryV2::InsertAllTableDataRequest::Row.new(json: x)
75+
end
7676
else
77-
row.json = opts
78-
request.rows = [row]
77+
rows = [Google::Apis::BigqueryV2::InsertAllTableDataRequest::Row.new(json: opts)]
7978
end
79+
request = Google::Apis::BigqueryV2::InsertAllTableDataRequest.new(rows: rows)
8080

8181
api(
8282
@client.insert_all_table_data(

test/bigquery.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ def test_for_insert_array
213213
result = @bq.insert('test' , data)
214214

215215
assert_equal result['kind'], "bigquery#tableDataInsertAllResponse"
216+
217+
# You can check the results. However, the test is slightly slower
218+
# sleep 5
219+
# result = @bq.query("SELECT * FROM [#{config['dataset']}.test]")
220+
# assert_equal result['totalRows'], "2"
216221
end
217222

218223
def test_for_insert_job

0 commit comments

Comments
 (0)