def Flush(self):
    self.bigquery = bigquery.GetBigQueryClient()
    # BigQuery job ids must be alphanum plus dash and underscore.
    urn_str = self.state.source_urn.RelativeName(
        "aff4:/").replace("/", "_").replace(":", "").replace(".", "-")

    for tracker in self.temp_output_trackers.values():
      # Close out the gzip handle and pass the original file handle to the
      # bigquery client so it sees the gzip'd content.
      tracker.gzip_filehandle.write("\n")
      tracker.gzip_filehandle.close()
      tracker.gzip_filehandle_parent.seek(0)

      # e.g. job_id: hunts_HFFE1D044_Results_ExportedFile_1446056474
      job_id = "{0}_{1}_{2}".format(
          urn_str, tracker.output_type,
          rdfvalue.RDFDatetime().Now().AsSecondsFromEpoch())

      # If we have a job id stored, that means we failed last time. Re-use the
      # job id and append to the same file if it continues to fail. This avoids
      # writing many files on failure.
      job_id = self.state.output_jobids.setdefault(tracker.output_type, job_id)

      if self.state.failure_count >= config_lib.CONFIG[
          "BigQuery.max_upload_failures"]:
        logging.error("Exceeded BigQuery.max_upload_failures for %s. Giving up "
                      "on BigQuery and writing to AFF4.", self.state.source_urn)
        self._WriteToAFF4(job_id, tracker.schema,
                          tracker.gzip_filehandle_parent, self.token)

      else:
        try:
          self.bigquery.InsertData(tracker.output_type,
                                   tracker.gzip_filehandle_parent,
                                   tracker.schema, job_id)
          self.state.failure_count = max(0, self.state.failure_count - 1)
          self.state.output_jobids.pop(tracker.output_type)
        except bigquery.BigQueryJobUploadError:
          self.state.failure_count += 1
          self._WriteToAFF4(job_id, tracker.schema,
                            tracker.gzip_filehandle_parent, self.token)

    # Now that everything is in bigquery we can remove the output streams
    self.temp_output_trackers = {}
Tests ``category_detail`` view.
dataset/ETHPy150Open google/grr/grr/lib/output_plugins/bigquery_plugin.py/BigQueryOutputPlugin.Flush--crossover with--dataset/ETHPy150Open ionyse/ionyweb/ionyweb/page_app/page_blog/tests.py/BlogTest.test_category_detail