import collections


def _format_for_bq(rows):
  """Formats BigQueryRow entities and metadata for the BigQuery API.

  Args:
    rows: List[BigQueryRow], a list of rows to format for the BigQuery API.

  Returns:
    A Dictionary keyed by model type with rows for a given table.
  """
  tables = collections.defaultdict(list)
  for row in rows:
    entity_dict = row.to_json_dict()
    tables[row.model_type].append(
        (entity_dict['ndb_key'], entity_dict['timestamp'],
         entity_dict['actor'], entity_dict['method'], entity_dict['summary'],
         entity_dict['entity']))
  return tables