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 validation for BQ label values for BigQueryInsertJobOperator #39568

Merged
merged 2 commits into from
May 12, 2024

Conversation

kisssam
Copy link
Contributor

@kisssam kisssam commented May 11, 2024


This updates the label value validation logic for BigQuery label values as documented in the public documentation

closes: #39567

@boring-cyborg boring-cyborg bot added area:providers provider:google Google (including GCP) related issues labels May 11, 2024
Copy link

boring-cyborg bot commented May 11, 2024

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 Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, 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.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    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

@kisssam
Copy link
Contributor Author

kisssam commented May 12, 2024

Setting the regex as LABEL_REGEX = re.compile(r"^[\w-]{0,63}$") since the documentation [1] indicates that label values can start with numbers, hyphen and underscore as well.

Values can be empty, and have a maximum length of 63 characters.

... values can contain only lowercase letters, numeric characters, underscores, and dashes

[1] https://cloud.google.com/bigquery/docs/labels-intro#requirements

@shahar1
Copy link
Contributor

shahar1 commented May 12, 2024

Setting the regex as LABEL_REGEX = re.compile(r"^[\w-]{0,63}$") since the documentation [1] indicates that label values can start with numbers, hyphen and underscore as well.

Values can be empty, and have a maximum length of 63 characters.

... values can contain only lowercase letters, numeric characters, underscores, and dashes

[1] https://cloud.google.com/bigquery/docs/labels-intro#requirements

What about Keys must start with a lowercase letter or international character.?

@kisssam
Copy link
Contributor Author

kisssam commented May 12, 2024

Setting the regex as LABEL_REGEX = re.compile(r"^[\w-]{0,63}$") since the documentation [1] indicates that label values can start with numbers, hyphen and underscore as well.

Values can be empty, and have a maximum length of 63 characters.

... values can contain only lowercase letters, numeric characters, underscores, and dashes

[1] https://cloud.google.com/bigquery/docs/labels-intro#requirements

What about Keys must start with a lowercase letter or international character.?

As mentioned in this line, as part of the label addition logic, the label keys used will be static, i.e. airflow-dag and airflow-task - hence the validation is only needed for the label values being passed, which the above validation regex will take care of.

@eladkal eladkal merged commit ffa523f into apache:main May 12, 2024
40 checks passed
Copy link

boring-cyborg bot commented May 12, 2024

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@kisssam
Copy link
Contributor Author

kisssam commented May 13, 2024

On testing on a Cloud Composer environment with apache-airflow-providers-google==10.18.0rc2, all other test cases except the scenario where a task starts with a hyphen fails.

However, this appears to be because Airflow DAG names and task IDs do not work well if they start with hyphen as seen in the below example:

dags_starting_with_hyphen_not_parseable

However, I can confirm as seen below for a example BigQuery job that I created that BigQuery labels support labels starting with hyphens as mentioned above.

bq show output for job with labels starting with hyphen

But the BigQueryInsertJobOperator would not be able to create jobs with label values starting with hyphen since it appears that task IDs cannot start with hyphens.

Hence, can you please let me know if this makes sense to remove the test case for the task starting with a hyphen since although Airflow allows to create a DAG/task starting with hyphen, it is not going to work as expected ? @eladkal

pateash pushed a commit to pateash/airflow that referenced this pull request May 13, 2024
romsharon98 pushed a commit to romsharon98/airflow that referenced this pull request Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers provider:google Google (including GCP) related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BigQueryInsertJobOperator fails for task IDs with 64 characters
3 participants