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

Add configure_job method to BigQuery job tasks #3098

Merged
merged 1 commit into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 36 additions & 0 deletions luigi/contrib/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,16 @@ def allow_quoted_new_lines(self):
""" Indicates if BigQuery should allow quoted data sections that contain newline characters in a CSV file. The default value is false."""
return False

def configure_job(self, configuration):
"""Set additional job configuration.

This allows to specify job configuration parameters that are not exposed via Task properties.

:param configuration: Current configuration.
:return: New or updated configuration.
"""
return configuration

def run(self):
output = self.output()
assert isinstance(output, BigQueryTarget), 'Output must be a BigQueryTarget, not %s' % (output)
Expand Down Expand Up @@ -565,6 +575,8 @@ def run(self):
else:
job['configuration']['load']['autodetect'] = True

job['configuration'] = self.configure_job(job['configuration'])

bq_client.run_job(output.table.project_id, job, dataset=output.table.dataset)


Expand Down Expand Up @@ -610,6 +622,16 @@ def use_legacy_sql(self):
"""
return True

def configure_job(self, configuration):
"""Set additional job configuration.

This allows to specify job configuration parameters that are not exposed via Task properties.

:param configuration: Current configuration.
:return: New or updated configuration.
"""
return configuration

def run(self):
output = self.output()
assert isinstance(output, BigQueryTarget), 'Output must be a BigQueryTarget, not %s' % (output)
Expand Down Expand Up @@ -643,6 +665,8 @@ def run(self):
}
}

job['configuration'] = self.configure_job(job['configuration'])

bq_client.run_job(output.table.project_id, job, dataset=output.table.dataset)


Expand Down Expand Up @@ -739,6 +763,16 @@ def compression(self):
"""Whether to use compression."""
return Compression.NONE

def configure_job(self, configuration):
"""Set additional job configuration.

This allows to specify job configuration parameters that are not exposed via Task properties.

:param configuration: Current configuration.
:return: New or updated configuration.
"""
return configuration

def run(self):
input = luigi.task.flatten(self.input())[0]
assert (
Expand Down Expand Up @@ -775,6 +809,8 @@ def run(self):
job['configuration']['extract']['fieldDelimiter'] = \
self.field_delimiter

job['configuration'] = self.configure_job(job['configuration'])

bq_client.run_job(
input.table.project_id,
job,
Expand Down
Loading