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: GCS To BigQuery source_object #16160

Merged
merged 4 commits into from
May 31, 2021

Conversation

tegardp
Copy link
Contributor

@tegardp tegardp commented May 29, 2021

Fixes #16008 GCS To BigQuery Operator's parameter source_object to accept both str and list


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.

Fix GCS To BigQuery source_object to accept both str and list
@tegardp tegardp requested a review from turbaszek as a code owner May 29, 2021 15:19
@boring-cyborg boring-cyborg bot added area:providers provider:google Google (including GCP) related issues labels May 29, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented May 29, 2021

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, pylint and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@potiuk
Copy link
Member

potiuk commented May 29, 2021

Could you please add a test for that @tegardp

@tegardp
Copy link
Contributor Author

tegardp commented May 29, 2021

Could you please add a test for that @tegardp

ah, okay

EDIT: I already checked the test_gcs_to_bigquery.py, but I a little bit confused about how to write the test. Would you mind giving me a hint? @potiuk

@@ -286,7 +286,7 @@ def execute(self, context):
else:
schema_fields = self.schema_fields

source_uris = [f'gs://{self.bucket}/{source_object}' for source_object in self.source_objects]
source_uris = [f'gs://{self.bucket}/{source_object}' for source_object in self.source_objects] if type(self.source_objects) is list else [f'gs://{self.bucket}/{self.source_objects}']
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to convert the string to list and then the code will work just fine without a special case for string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But if the input is a list, wouldn't it be converted to a 2-dimensional list?

self.source_objects = "file1.csv"
source_object = [self.source_objects]
output: ["file1.csv"]

self.source_objects = ["file1.csv", "file2.csv", "file3.csv"]
source_object = [self.source_objects]
output: [["file1.csv", "file2.csv", "file3.csv"]]

Copy link
Contributor

Choose a reason for hiding this comment

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

No. I was thinking of converting the type to List (if needed) so the logic part of the code won't need any modification as it works fine with List type. something like:

if isinstance(obj, str):
   obj=[obj]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh, I was thinking about that solution too. So, it doesn't have to be one line code?

@eladkal eladkal changed the title Fix: GCS To BigQuery source_object #16008 Fix: GCS To BigQuery source_object May 30, 2021
converting source_objects to list instead of modifying the logic part

Copy link
Contributor

Choose a reason for hiding this comment

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

please remove this white space

@eladkal
Copy link
Contributor

eladkal commented May 30, 2021

Also please add a test to https://github.com/apache/airflow/blob/master/tests/providers/google/cloud/transfers/test_gcs_to_bigquery.py I think just a test that verify once with list and once with string is enough

@potiuk
Copy link
Member

potiuk commented May 30, 2021

EDIT: I already checked the test_gcs_to_bigquery.py, but I a little bit confused about how to write the test. Would you mind giving me a hint? @potiuk

@eladkal is correct - just add a test where the source_object is string /list of strings. In the current test TEST_SOURCE_OBJECTS is list of strings, but you can create another TEST_SOURCE_OBJECTS_AS_STRING (with string value) and copy one of the existing tests just using this new constant.

@tegardp
Copy link
Contributor Author

tegardp commented May 30, 2021

Thanks, @potiuk @eladkal, I pushed my tests. Did I do it correctly?

@potiuk
Copy link
Member

potiuk commented May 30, 2021

Looks good :). Running the workflow now !

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label May 31, 2021
@github-actions
Copy link

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest master or amend the last commit of the PR, and push it with --force-with-lease.

@eladkal eladkal merged commit 99d1535 into apache:master May 31, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented May 31, 2021

Awesome work, congrats on your first merged pull request!

@linchun3
Copy link

hey, @tegardp I noticed that this change could be missing an edge case when retrieving a list of files from x_com:

Example:

default_args = {
"render_template_as_native_obj": True
} 

...

# retrieval of files from x_com
files = ["file1.txt", "file2.txt", "file3.txt"]

since the rendering to native object only happens on execute, the value retrieve from x_comms would still be
"["file1.txt", "file2.txt", "file3.txt"]" on initialisation and self.source_objects of the operator would be ["["file1.txt", "file2.txt", "file3.txt"]"] which is not the intended behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers okay to merge It's ok to merge this PR as it does not require more tests provider:google Google (including GCP) related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GoogleCloudStorageToBigQueryOperator reads string as a list in parameter source_objects
4 participants