Skip to content

Commit

Permalink
Related abronte#40. Thanks to @nashyeung
Browse files Browse the repository at this point in the history
  • Loading branch information
kysnm committed Apr 20, 2016
1 parent e5bb214 commit b8de40a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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

0 comments on commit b8de40a

Please sign in to comment.