diff --git a/lib/big_query/client/tables.rb b/lib/big_query/client/tables.rb index ae1ee39..1b97691 100644 --- a/lib/big_query/client/tables.rb +++ b/lib/big_query/client/tables.rb @@ -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( diff --git a/test/bigquery.rb b/test/bigquery.rb index 60a73fd..b1c3946 100644 --- a/test/bigquery.rb +++ b/test/bigquery.rb @@ -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