Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MaxID logic for GCSToBigQueryOperator #26768

Merged
merged 3 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions airflow/providers/google/cloud/transfers/gcs_to_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,10 @@ def execute(self, context: Context):
location=self.location,
use_legacy_sql=False,
)
row = list(bq_hook.get_job(job_id=job_id, location=self.location).result())
if row:
max_id = row[0] if row[0] else 0
result = bq_hook.get_job(job_id=job_id, location=self.location).result()
row = next(iter(result), None)
if row is not None:
patricker marked this conversation as resolved.
Show resolved Hide resolved
max_id = row[0]
self.log.info(
'Loaded BQ data with max %s.%s=%s',
self.destination_project_dataset_table,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import unittest
from unittest import mock

from google.cloud.bigquery.table import Row

from airflow.providers.google.cloud.transfers.gcs_to_bigquery import GCSToBigQueryOperator

TASK_ID = 'test-gcs-to-bq-operator'
Expand All @@ -43,11 +45,11 @@ def test_execute_explicit_project(self, bq_hook):
max_id_key=MAX_ID_KEY,
)

bq_hook.return_value.get_job.return_value.result.return_value = ('1',)
bq_hook.return_value.get_job.return_value.result.return_value = [Row(('100',), {'f0_': 0})]

result = operator.execute(None)

assert result == '1'
assert result == '100'

bq_hook.return_value.run_query.assert_called_once_with(
sql="SELECT MAX(id) FROM `test-project.dataset.table`",
Expand Down