-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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(bigquery): add table/view samples to cloud-client (3/3) #10036
base: main
Are you sure you want to change the base?
feat(bigquery): add table/view samples to cloud-client (3/3) #10036
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @alarconesparza, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request adds samples to the google-cloud-java BigQuery client library for managing table and view access policies. Specifically, it introduces samples for viewing, granting, and revoking access to tables or views. The changes include the addition of new Java files containing the sample code, a pom.xml
file for managing dependencies, and integration tests to verify the functionality of the samples.
Highlights
- New Samples: Adds samples for viewing, granting, and revoking access to BigQuery tables and views.
- IAM Policy Management: Demonstrates how to programmatically manage IAM policies for BigQuery resources using the Java client library.
- Integration Tests: Includes integration tests to ensure the samples function correctly in a real BigQuery environment.
Changelog
Click here to see the changelog
- bigquery/cloud-client/snippets/pom.xml
- Added a new pom.xml file to manage dependencies for the BigQuery samples.
- Configured the project with necessary dependencies like google-cloud-bigquery, junit, and google-truth.
- Set the parent pom to the latest shared-configuration version 1.2.0.
- bigquery/cloud-client/snippets/src/main/java/com/example/bigquery/GetTableOrViewAccessPolicy.java
- Created a new sample to view the access policy of a BigQuery table or view.
- Uses BigQueryOptions to initialize the BigQuery client.
- Retrieves the IAM policy for a given table or view using TableId.
- Prints the IAM policy details to the console.
- bigquery/cloud-client/snippets/src/main/java/com/example/bigquery/GrantAccessToTableOrView.java
- Created a new sample to grant access to a BigQuery table or view.
- Adds a new user identity to the current IAM policy with a specified role.
- Updates the IAM policy using bigquery.setIamPolicy().
- bigquery/cloud-client/snippets/src/main/java/com/example/bigquery/RevokeAccessToTableOrView.java
- Created a new sample to revoke access to a BigQuery table or view.
- Removes specified identities or roles from the IAM policy bindings.
- Updates the IAM policy using bigquery.setIamPolicy().
- Handles cases where roles or identities might be empty after removal.
- bigquery/cloud-client/snippets/src/test/java/com/example/bigquery/GetTableOrViewAccessPolicyIT.java
- Added integration tests for the GetTableOrViewAccessPolicy sample.
- Sets up temporary datasets, tables, and views for testing.
- Verifies that the sample retrieves the IAM policy successfully.
- Uses RemoteBigQueryHelper to manage BigQuery resources.
- bigquery/cloud-client/snippets/src/test/java/com/example/bigquery/GrantAccessToTableOrViewIT.java
- Added integration tests for the GrantAccessToTableOrView sample.
- Sets up temporary datasets, tables, and views for testing.
- Verifies that the sample grants access successfully.
- Uses RemoteBigQueryHelper to manage BigQuery resources.
- bigquery/cloud-client/snippets/src/test/java/com/example/bigquery/RevokeAccessToTableOrViewIT.java
- Added integration tests for the RevokeAccessToTableOrView sample.
- Sets up temporary datasets, tables, and views for testing.
- Verifies that the sample revokes access successfully.
- Uses RemoteBigQueryHelper to manage BigQuery resources.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Trivia time!
What is the primary use case for BigQuery?
Click here for the answer
BigQuery is primarily used for analyzing large datasets. It is often used for business intelligence, data warehousing, and ad-hoc querying.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request introduces new samples for managing BigQuery table/view access policies. The code is generally well-structured and follows common Java conventions. However, there are a few areas that could be improved for clarity and correctness.
Summary of Findings
- TODO comments: The code contains
TODO
comments that should be addressed before merging. Consider providing a more specific implementation or removing the comment if it's no longer relevant. - Inmutable vs Immutable: There is a typo in the
RevokeAccessToTableOrView.java
file, whereinmutable
should beimmutable
.
Merge Readiness
The pull request is not quite ready for merging. The TODO
comments should be addressed, and the typo in RevokeAccessToTableOrView.java
should be fixed. Once these issues are resolved, the code should be ready for another review and potential merging. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.
// TODO(developer): Replace these variables before running the sample. | ||
// Project, dataset and resource (table or view) from which to get the access policy. | ||
String projectId = "MY_PROJECT_ID"; | ||
String datasetName = "MY_DATASET_NAME"; | ||
String resourceName = "MY_RESOURCE_NAME"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using environment variables for these values instead of hardcoding them, to make the sample more configurable and secure. This would also align with the checklist item regarding environment variables.
// TODO(developer): Replace these variables before running the sample. | |
// Project, dataset and resource (table or view) from which to get the access policy. | |
String projectId = "MY_PROJECT_ID"; | |
String datasetName = "MY_DATASET_NAME"; | |
String resourceName = "MY_RESOURCE_NAME"; | |
// Project, dataset and resource (table or view) from which to get the access policy. | |
String projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); | |
String datasetName = System.getenv("BIGQUERY_DATASET_NAME"); | |
String resourceName = System.getenv("BIGQUERY_RESOURCE_NAME"); |
// TODO(developer): Replace these variables before running the sample. | ||
// Project, dataset and resource (table or view) from which to get the access policy. | ||
String projectId = "MY_PROJECT_ID"; | ||
String datasetName = "MY_DATASET_NAME"; | ||
String resourceName = "MY_TABLE_NAME"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using environment variables for these values instead of hardcoding them, to make the sample more configurable and secure. This would also align with the checklist item regarding environment variables.
// TODO(developer): Replace these variables before running the sample. | |
// Project, dataset and resource (table or view) from which to get the access policy. | |
String projectId = "MY_PROJECT_ID"; | |
String datasetName = "MY_DATASET_NAME"; | |
String resourceName = "MY_TABLE_NAME"; | |
// Project, dataset and resource (table or view) from which to get the access policy. | |
String projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); | |
String datasetName = System.getenv("BIGQUERY_DATASET_NAME"); | |
String resourceName = System.getenv("BIGQUERY_RESOURCE_NAME"); |
Role role = Role.of("roles/bigquery.dataViewer"); | ||
// Identity to add to the policy access | ||
Identity identity = Identity.user("[email protected]"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using environment variables for these values instead of hardcoding them, to make the sample more configurable and secure. This would also align with the checklist item regarding environment variables.
Role role = Role.of("roles/bigquery.dataViewer"); | |
// Identity to add to the policy access | |
Identity identity = Identity.user("[email protected]"); | |
// Role to add to the policy access | |
Role role = Role.of(System.getenv("BIGQUERY_ROLE")); | |
// Identity to add to the policy access | |
Identity identity = Identity.user(System.getenv("BIGQUERY_USER")); |
// TODO(developer): Replace these variables before running the sample. | ||
// Project, dataset and resource (table or view) from which to get the access policy | ||
String projectId = "MY_PROJECT_ID"; | ||
String datasetName = "MY_DATASET_NAME"; | ||
String resourceName = "MY_RESOURCE_NAME"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using environment variables for these values instead of hardcoding them, to make the sample more configurable and secure. This would also align with the checklist item regarding environment variables.
// TODO(developer): Replace these variables before running the sample. | |
// Project, dataset and resource (table or view) from which to get the access policy | |
String projectId = "MY_PROJECT_ID"; | |
String datasetName = "MY_DATASET_NAME"; | |
String resourceName = "MY_RESOURCE_NAME"; | |
// Project, dataset and resource (table or view) from which to get the access policy | |
String projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); | |
String datasetName = System.getenv("BIGQUERY_DATASET_NAME"); | |
String resourceName = System.getenv("BIGQUERY_RESOURCE_NAME"); |
Role role = Role.of("roles/bigquery.dataViewer"); | ||
// Identity to remove from the access policy | ||
Identity user = Identity.user("[email protected]"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using environment variables for these values instead of hardcoding them, to make the sample more configurable and secure. This would also align with the checklist item regarding environment variables.
Role role = Role.of("roles/bigquery.dataViewer"); | |
// Identity to remove from the access policy | |
Identity user = Identity.user("[email protected]"); | |
// Role to remove from the access policy | |
Role role = Role.of(System.getenv("BIGQUERY_ROLE")); | |
// Identity to remove from the access policy | |
Identity user = Identity.user(System.getenv("BIGQUERY_USER")); |
// Remove either identities or roles, or both from bindings and replace it in | ||
// the current IAM policy. | ||
Policy policy = bigquery.getIamPolicy(tableId); | ||
// Create a copy of a inmutable map. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Remove one identity in all the existing roles. | ||
for (Role roleKey : bindings.keySet()) { | ||
if (bindings.get(roleKey).contains(identity)) { | ||
// Create a copy of a inmutable set if the identity is present in the role. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the summary of changes. You are about to add 3 region tags.
This comment is generated by snippet-bot.
|
Description
Part of internal b/394478489
Third part of bigquery cloud-client (3/3).
(#10034, #10035, #10036)
This part adds samples 2, 4 and 6 from the following list:
Samples
Some of the samples are part of java-bigquery/.../bigquery repo, but are deprecated or the content does not match the docs.
Checklist
pom.xml
parent set to latestshared-configuration
mvn clean verify
requiredmvn -P lint checkstyle:check
requiredmvn -P lint clean compile pmd:cpd-check spotbugs:check
advisory only