Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: allow setting table labels in to_gbq #941

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

Merged
merged 26 commits into from
Sep 5, 2024
Merged

Conversation

mattyopl
Copy link
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • 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 b/312727426 🦕

@mattyopl mattyopl self-assigned this Aug 30, 2024
@mattyopl mattyopl requested review from a team as code owners August 30, 2024 14:08
@mattyopl mattyopl requested a review from chelsea-lin August 30, 2024 14:08
@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. labels Aug 30, 2024
@mattyopl
Copy link
Contributor Author

@mattyopl mattyopl requested a review from GarrettWu August 30, 2024 14:12
bigframes/dataframe.py Show resolved Hide resolved
@product-auto-label product-auto-label bot added size: s Pull request size is small. and removed size: xs Pull request size is extra small. labels Aug 30, 2024
@mattyopl mattyopl requested a review from chelsea-lin August 30, 2024 19:03
Copy link
Contributor

@chelsea-lin chelsea-lin left a comment

Choose a reason for hiding this comment

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

Overall looks good to me, if Garrett wants to take another look.

bigframes/dataframe.py Show resolved Hide resolved
Copy link
Contributor

@GarrettWu GarrettWu left a comment

Choose a reason for hiding this comment

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

The PR title should be "feat".

bigframes/dataframe.py Outdated Show resolved Hide resolved
@mattyopl mattyopl changed the title chore: allow setting table labels in to_gbq feat: allow setting table labels in to_gbq Aug 30, 2024
tests/system/small/test_dataframe.py Outdated Show resolved Hide resolved
@@ -3106,6 +3107,12 @@ def to_gbq(
+ constants.DEFAULT_EXPIRATION,
)

if len(labels) != 0:
client = self._session.bqclient
Copy link
Contributor

Choose a reason for hiding this comment

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

Setting up labels currently requires additional client calls, which is acceptable but not ideal for performance. Could you try setting the label directly at the bigquery.table.TableReference destination? While TableReference doesn't have a public API for this, you can experiment with the internal call similar to Table.label. If this works, we can explore adding a new public API to TableReference. +@tswast has more experience with the Python client API and could provide additional insights.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed one client call by using the TableReference returned by the Query job, but as far as I can tell we might still have to make another API call for update_table. Looking at seeing if I can change table labels upon creation but I haven't found where that's being done yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for exploring it.

@mattyopl mattyopl requested a review from chelsea-lin September 4, 2024 19:41
@chelsea-lin chelsea-lin added the owlbot:run Add this label to trigger the Owlbot post processor. label Sep 5, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Sep 5, 2024
@mattyopl mattyopl merged commit cccc6ca into googleapis:main Sep 5, 2024
23 checks passed
@mattyopl mattyopl deleted the dev branch September 5, 2024 15:18
@@ -4657,6 +4657,17 @@ def test_to_gbq_and_create_dataset(session, scalars_df_index, dataset_id_not_cre
assert not loaded_scalars_df_index.empty


def test_to_gbq_table_labels(scalars_df_index):
destination_table = "bigframes-dev.bigframes_tests_sys.table_labels"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally the test should not be hard coupled with a project/dataset. Do we have to use a fixed table name? I think the test would still serve its purpose if we did to_gbq without an explicit table arg and asserted labels on the returned anonymous table.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in #968!

@@ -467,6 +468,9 @@ def to_gbq(
clustering order within the Index/DataFrame columns follows the order
specified in `clustering_columns`.

labels (dict[str, str], default None):
Specifies table labels within BigQuery
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, (but since this goes in the public doc) should end with the period .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in #968!

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-dataframes API. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.