|
17 | 17 | # under the License. |
18 | 18 | """This module contains Google BigQuery to Google Cloud Storage operator.""" |
19 | 19 | import warnings |
20 | | -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Union |
21 | | - |
22 | | -from google.cloud.bigquery.table import TableReference |
| 20 | +from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, Union |
23 | 21 |
|
24 | 22 | from airflow.models import BaseOperator |
25 | 23 | from airflow.providers.google.cloud.hooks.bigquery import BigQueryHook |
@@ -128,26 +126,12 @@ def execute(self, context: 'Context'): |
128 | 126 | location=self.location, |
129 | 127 | impersonation_chain=self.impersonation_chain, |
130 | 128 | ) |
131 | | - |
132 | | - table_ref = TableReference.from_string(self.source_project_dataset_table, hook.project_id) |
133 | | - |
134 | | - configuration: Dict[str, Any] = { |
135 | | - 'extract': { |
136 | | - 'sourceTable': table_ref.to_api_repr(), |
137 | | - 'compression': self.compression, |
138 | | - 'destinationUris': self.destination_cloud_storage_uris, |
139 | | - 'destinationFormat': self.export_format, |
140 | | - } |
141 | | - } |
142 | | - |
143 | | - if self.labels: |
144 | | - configuration['labels'] = self.labels |
145 | | - |
146 | | - if self.export_format == 'CSV': |
147 | | - # Only set fieldDelimiter and printHeader fields if using CSV. |
148 | | - # Google does not like it if you set these fields for other export |
149 | | - # formats. |
150 | | - configuration['extract']['fieldDelimiter'] = self.field_delimiter |
151 | | - configuration['extract']['printHeader'] = self.print_header |
152 | | - |
153 | | - hook.insert_job(configuration=configuration) |
| 129 | + hook.run_extract( |
| 130 | + source_project_dataset_table=self.source_project_dataset_table, |
| 131 | + destination_cloud_storage_uris=self.destination_cloud_storage_uris, |
| 132 | + compression=self.compression, |
| 133 | + export_format=self.export_format, |
| 134 | + field_delimiter=self.field_delimiter, |
| 135 | + print_header=self.print_header, |
| 136 | + labels=self.labels, |
| 137 | + ) |
0 commit comments