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 autodetect arg in BQCreateExternalTable Operator #22710

Merged
merged 3 commits into from
Apr 4, 2022

Conversation

hankehly
Copy link
Contributor

@hankehly hankehly commented Apr 3, 2022

Closes #22129

This PR adds an autodetect flag (with a backward compatible default value) to the BigQueryCreateExternalTableOperator constructor. If schema_fields and schema_object are blank, and the autodetect flag is set to True, BigQuery will attempt to auto-detect the input data schema.

Todo:

  • update code
  • update documentation
  • update unit tests
  • check manually

Documentation updates

Added the following line to the Google provider package docs.

update

Manual checks

I uploaded a CSV file containing the following to a Google Cloud Storage bucket in the us-east1 region.

name,age
Bill,42
Sally,15

I then ran a test DAG to create an external table based on the above CSV file. I enable BigQuery schema auto-detection by setting the autodetect flag to True.

BigQueryCreateExternalTableOperator(
    task_id="test",
    bucket="***",
    source_objects=["test.csv"],
    destination_project_dataset_table = "***",
    source_format = "CSV",
    autodetect = True,
    skip_leading_rows=1,
    location = "us-east1",
)

The table is created with the correct field names and types. The table configuration also shows that schema auto-detection was enabled.

Screen Shot 2022-04-04 at 13 31 03

Screen Shot 2022-04-04 at 13 29 29

@boring-cyborg boring-cyborg bot added area:providers provider:google Google (including GCP) related issues labels Apr 3, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 3, 2022

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/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, mypy 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

@hankehly hankehly changed the title Feature/issue 22129 Add autodetect arg in BQCreateExternalTable Operator Apr 4, 2022
@hankehly hankehly force-pushed the feature/issue-22129 branch from f1910fc to 6994d60 Compare April 4, 2022 00:29
@hankehly hankehly marked this pull request as ready for review April 4, 2022 04:47
@hankehly
Copy link
Contributor Author

hankehly commented Apr 4, 2022

@turbaszek @mik-laj Please review this PR at your earliest convenience.

@github-actions
Copy link

github-actions bot commented Apr 4, 2022

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 main or amend the last commit of the PR, and push it with --force-with-lease.

@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 Apr 4, 2022
@mik-laj mik-laj merged commit f9e1847 into apache:main Apr 4, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 4, 2022

Awesome work, congrats on your first merged pull request!

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.

Add autodetect arg in BQCreateExternalTable Operator
3 participants