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

feat: resource tags in dataset #2090

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

keunsoopark
Copy link

@keunsoopark keunsoopark commented Dec 19, 2024

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #2091 🦕

@keunsoopark keunsoopark requested review from a team as code owners December 19, 2024 13:26
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Dec 19, 2024
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Dec 19, 2024
@keunsoopark keunsoopark marked this pull request as draft December 19, 2024 13:50
@keunsoopark keunsoopark marked this pull request as ready for review December 19, 2024 13:50
@keunsoopark keunsoopark marked this pull request as draft December 19, 2024 15:38
@keunsoopark keunsoopark marked this pull request as ready for review December 19, 2024 15:38
Copy link
Contributor

@Linchin Linchin left a comment

Choose a reason for hiding this comment

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

Thank you so much for adding resource tags in dataset! The PR looks great overall, I just made some minor modifications. I wonder if you could add a system test, as well as a unit test for setter with None? Please let us know if you need any help. Happy holidays!

@Linchin Linchin added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Dec 20, 2024
@Linchin Linchin assigned Linchin and unassigned yirutang Dec 20, 2024
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Dec 20, 2024
@keunsoopark
Copy link
Author

system test

Hi @Linchin, thanks for the review.

I added system tests in system/test_clients.py

I fixed unittests for None, and added more tests for invalid values. See test_resource_tags_setter_bad_value.

Merry Christmas and happy new year!

@Linchin Linchin added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 7, 2025
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 7, 2025
@Linchin Linchin added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 8, 2025
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 8, 2025
@@ -278,33 +286,72 @@ def test_create_dataset_with_default_rounding_mode(self):
self.assertTrue(_dataset_exists(dataset))
self.assertEqual(dataset.default_rounding_mode, "ROUND_HALF_EVEN")

def _create_resource_tag_key_and_values(self, key, values):
Copy link
Author

@keunsoopark keunsoopark Jan 8, 2025

Choose a reason for hiding this comment

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

Got inspired from this implementation. Just took out this method to be used in both dataset & test implementation.

Do you have any tips on how to run system test locally, @Linchin? There is some setup to the actual project required, but this explanation is too vague to follow.

Copy link
Contributor

Choose a reason for hiding this comment

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

In general you can just use pytest to run system tests, it's slightly easier than nox, and should be able to run on any python version:

pytest tests/system/test_client.py

You can specify the test class or method too:

pytest tests/system/test_client.py::TestBigQuery::test_update_dataset

This should make it faster.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you also need to run lint, that will need to use nox:

nox -r -s lint

Copy link
Author

@keunsoopark keunsoopark Jan 9, 2025

Choose a reason for hiding this comment

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

Thanks I ran linting locally.

I still could not run system tests locally still. I think I need to specify GOOGLE_APPLICATION_CREDENTIALS env var (see here) anyway, but not sure what credentials I can use.
I tried to use the credentials of a service account in my personal Google Cloud project, which has a owner role in this project, but I got all PERMISSION_DENIED errors for dataset creation, table creation etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think if you run pytest instead of nox, you don't have to have GOOGLE_APPLICATION_CREDENTIALS set up, because we are bypassing noxfile.py.

Copy link
Author

@keunsoopark keunsoopark Jan 10, 2025

Choose a reason for hiding this comment

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

Ok I managed running system test locally. This is how:

  • Make a python script, install_dependencies.py parsing all dependencies in specifiednoxfile.py, to install dependencies in my local pip.
  • For some reason, google-cloud-testutils was not installed in this manner, as specified here, so install this one manually.
  • Configure gcloud auth to my personal GCP project
  • Run pytest

@Linchin Linchin added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 8, 2025
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 8, 2025
)
try:
tag_key = tag_key_client.create_tag_key(tag_key=new_tag_key).result()
except AlreadyExists: # When system tests runs in parallel for multiple Python versions, the tag key may already exist
Copy link
Author

@keunsoopark keunsoopark Jan 9, 2025

Choose a reason for hiding this comment

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

Since we run multiple system tests at the same time for different Python versions, we got AlreadyExists error. We got this error only in 3.12 test, but not in 3.8 test (Does not matter on which Python version, but whatever comes later I assume).

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, thank you for fixing this!

@Linchin Linchin added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 10, 2025
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 10, 2025
@Linchin Linchin added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 10, 2025
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attach resource tags on datasets
4 participants