Skip to content

Commit

Permalink
BigQuery extract table method (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinweisgrau authored Jun 21, 2024
1 parent 7bc9b0f commit 061bb89
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions parsons/google/google_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,26 @@ def table(self, table_name):

return BigQueryTable(self, table_name)

def extract(
self,
dataset: str,
table_name: str,
gcs_bucket: str,
gcs_blob_name: str,
project: Optional[str] = None,
) -> None:
dataset_ref = bigquery.DatasetReference(project or self.client.project, dataset)
table_ref = dataset_ref.table(table_name)
gs_destination = f"gs://{gcs_bucket}/{gcs_blob_name}"

extract_job = self.client.extract_table(
table_ref,
gs_destination,
)
extract_job.result() # Waits for job to complete.

logger.info(f"Finished exporting query result to {gs_destination}.")


class BigQueryTable(BaseTable):
"""BigQuery table object."""
Expand Down

0 comments on commit 061bb89

Please sign in to comment.