MCPcopy
hub / github.com/google/clusterfuzz / insert

Method insert

src/clusterfuzz/_internal/google_cloud_utils/big_query.py:364–396  ·  view source on GitHub ↗

Insert the given rows and batch them if needed. Args: inserts: a list of Inserts, each of which represents a row. Returns: A json explained here: https://cloud.google.com/bigquery/docs/reference/rest/v2/tabledata/insertAll

(self, inserts)

Source from the content-addressed store, hash-verified

362
363 @environment.local_noop
364 def insert(self, inserts):
365 # pylint: disable=line-too-long
366 """Insert the given rows and batch them if needed.
367
368 Args:
369 inserts: a list of Inserts, each of which represents a row.
370
371 Returns:
372 A json explained here:
373 https://cloud.google.com/bigquery/docs/reference/rest/v2/tabledata/insertAll
374 """
375 result = {}
376 for i in range(0, len(inserts), INSERT_BATCH_SIZE):
377 response = self._insert_batch(
378 inserts[i:min(len(inserts), i + INSERT_BATCH_SIZE)])
379
380 # There is also quota for the total number of requests / rows per second.
381 time.sleep(1)
382
383 if not result:
384 # Use result from the first batch, appending errors from the rest.
385 result = response
386 continue
387
388 # If there are new errors from the current batch, append to the result.
389 new_errors = response.get('insertErrors')
390 if not new_errors:
391 continue
392
393 # Apparently result may not have errors, use |setdefault| to be careful.
394 result.setdefault('insertErrors', []).extend(new_errors)
395
396 return result

Callers 15

write_rangeFunction · 0.95
test_insertMethod · 0.95
butler.pyFile · 0.80
_setupFunction · 0.80
get_components_listFunction · 0.80
_patch_rpathMethod · 0.80

Calls 3

_insert_batchMethod · 0.95
extendMethod · 0.80
getMethod · 0.45

Tested by 5

test_insertMethod · 0.76
test_executeMethod · 0.64
executeFunction · 0.64