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

[AIRFLOW-3059] PostgresToGCS Log the number of rows read #3898

Closed
wants to merge 1 commit into from

Conversation

Fokko
Copy link
Contributor

@Fokko Fokko commented Sep 13, 2018

Make sure you have checked all steps below.

Jira

Description

  • Here are some details about my PR, including screenshots of any UI changes:

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:

Commits

  • My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • When adding new operators/hooks/sensors, the autoclass documentation generation needs to be added.

Code Quality

  • Passes git diff upstream/master -u -- "*.py" | flake8 --diff

@Fokko Fokko changed the title Fd add counter [AIRFLOW-3059] PostgresToGCS Log the number of rows read Sep 13, 2018
@Fokko Fokko force-pushed the fd-add-counter branch 2 times, most recently from 3ede533 to 61b781c Compare September 14, 2018 07:41
@@ -134,6 +134,7 @@ def _write_local_data_files(self, cursor):
"""
schema = list(map(lambda schema_tuple: schema_tuple[0], cursor.description))
file_no = 0
row_no = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a dump question, but why we initialize the variable as 1 not 0? I am not very familiiar with this operator but if the cursor doesn't return any row, the log will still print Received 1 rows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo I guess, this should be 0 indeed, thanks!

@@ -155,6 +156,9 @@ def _write_local_data_files(self, cursor):
file_no += 1
tmp_file_handle = NamedTemporaryFile(delete=True)
tmp_file_handles[self.filename.format(file_no)] = tmp_file_handle
row_no += 1

self.log.info('Received %s rows over %s files', row_no, file_no + 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be just file_no and not file_no + 1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line156 already increments the file_no variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file_no indicates how many files are being written, to avoid that files grow too big. The row_no should indicate how many lines are being written. So I understand the confusion. The thing is, if no files are being rolled, file_no will still be 0. But if no rows are being written it will say, written 0 rows over 1 file. Let me make this more clear.

To know how many data is being read from Postgres, it is nice to
log this to the Airflow log
@Fokko
Copy link
Contributor Author

Fokko commented Sep 15, 2018

@kaxil I've refactored the code a bit, let me know what you think. This changes the behaviour though, the main question is, do we want to create a file if there is nothing to write?

@kaxil
Copy link
Member

kaxil commented Sep 15, 2018

I agree with this logic. Can we add tests to check that the file is not created when there are no rows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants