Skip to content

Commit cfb602a

Browse files
authored
Fix BigQuery data extraction in BigQueryToMySqlOperator (#18073)
closes: #17198
1 parent 2767781 commit cfb602a

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

airflow/providers/google/cloud/transfers/bigquery_to_mysql.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,17 @@ def _bq_get_data(self):
129129
impersonation_chain=self.impersonation_chain,
130130
)
131131

132-
conn = hook.get_conn()
133-
cursor = conn.cursor()
134132
i = 0
135133
while True:
136-
response = cursor.get_tabledata(
134+
response = hook.list_rows(
137135
dataset_id=self.dataset_id,
138136
table_id=self.table_id,
139137
max_results=self.batch_size,
140138
selected_fields=self.selected_fields,
141139
start_index=i * self.batch_size,
142140
)
143-
144-
if 'rows' in response:
145-
rows = response['rows']
146-
else:
141+
rows = [dict(r) for r in response]
142+
if len(rows) == 0:
147143
self.log.info('Job Finished')
148144
return
149145

tests/providers/google/cloud/transfers/test_bigquery_to_mysql.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ def test_execute_good_request_to_bq(self, mock_hook):
3939

4040
operator.execute(None)
4141
# fmt: off
42-
mock_hook.return_value.get_conn.return_value.cursor.return_value.get_tabledata\
43-
.assert_called_once_with(
44-
dataset_id=TEST_DATASET,
45-
table_id=TEST_TABLE_ID,
46-
max_results=1000,
47-
selected_fields=None,
48-
start_index=0,
49-
)
42+
mock_hook.return_value.list_rows.assert_called_once_with(
43+
dataset_id=TEST_DATASET,
44+
table_id=TEST_TABLE_ID,
45+
max_results=1000,
46+
selected_fields=None,
47+
start_index=0,
48+
)
5049
# fmt: on

0 commit comments

Comments
 (0)