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

Resolves ENGA-932 "Modify BigQueryExporter class export() method to accept a pull_date" #5

Merged
merged 8 commits into from
Nov 28, 2023
31 changes: 28 additions & 3 deletions bigquery_exporter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,35 @@ def __init__(self):
raise ValueError(f'Custom field {field} is not defined')
echan217 marked this conversation as resolved.
Show resolved Hide resolved

def define_queryset(self):
return self.model.objects.all()
"""
Returns the queryset for exporting data to BigQuery.

def export(self):
pull_time = datetime.datetime.now()
This method can be overridden in subclasses to specify additional filters or ordering
for the queryset. For example, you can use this method to filter data based on date ranges
or status fields.

It is important to note that if the queryset is larger than the class's batch size,
it must be ordered to avoid ordering bugs when accessing different segments of the queryset.

Returns:
QuerySet: The queryset for exporting data to BigQuery.
"""
return self.model.objects.all().order_by('id')

def export(self, pull_date=None, *args, **kwargs):
"""
Export data to BigQuery.

Args:
pull_date (datetime.datetime, optional): The datetime used to populate the pull_date field. If not provided, the current date and time will be used.

Raises:
Exception: If an error occurs while exporting the data.

Returns:
None
"""
pull_time = datetime.datetime.now() if not pull_date else pull_date
try:
queryset = self.define_queryset()
for start, end, total, qs in batch_qs(queryset, self.batch):
Expand Down