Skip to content
This repository was archived by the owner on Jun 12, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/big_query/client/tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def table_data(table_id, dataset_id = @dataset, options = {})
# @param opts [Hash] field value hash to be inserted
# @return [Hash]
def insert(table_id, opts)
request = Google::Apis::BigqueryV2::InsertAllTableDataRequest.new
row = Google::Apis::BigqueryV2::InsertAllTableDataRequest::Row.new
if opts.class == Array
request.rows = opts.map{|x| row.json = x; row}
rows = opts.map do |x|
Google::Apis::BigqueryV2::InsertAllTableDataRequest::Row.new(json: x)
end
else
row.json = opts
request.rows = [row]
rows = [Google::Apis::BigqueryV2::InsertAllTableDataRequest::Row.new(json: opts)]
end
request = Google::Apis::BigqueryV2::InsertAllTableDataRequest.new(rows: rows)

api(
@client.insert_all_table_data(
Expand Down
5 changes: 5 additions & 0 deletions test/bigquery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ def test_for_insert_array
result = @bq.insert('test' , data)

assert_equal result['kind'], "bigquery#tableDataInsertAllResponse"

# You can check the results. However, the test is slightly slower
# sleep 5
# result = @bq.query("SELECT * FROM [#{config['dataset']}.test]")
# assert_equal result['totalRows'], "2"
end

def test_for_insert_job
Expand Down