-
Notifications
You must be signed in to change notification settings - Fork 126
feat: support biglake tables in pandas_gbq.sample #1014
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @tswast, 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! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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. Footnotes
|
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
This pull request adds the initial structure to support sampling from BigLake tables in pandas_gbq.sample. It refactors the existing sampling logic into separate functions for BigQuery and BigLake tables and introduces a new biglake.py module to interact with the BigLake REST API.
My review has identified a few critical issues. The core logic for sampling BigLake tables is not yet implemented. The new biglake.py module contains a critical bug in URL construction and lacks proper error handling for API requests. I've also noted some areas for improvement regarding the robustness of table ID parsing and documentation. Please address these points to complete the feature.
| return session.get( | ||
| f"{_ICEBERG_REST_CATALOG_URI}.{path}", | ||
| headers={ | ||
| "x-goog-user-project": billing_project_id, | ||
| "Content-Type": "application/json; charset=utf-8", | ||
| # TODO(tswast): parameter for this option (or get from catalog metadata?) | ||
| # /iceberg/{$api_version}/restcatalog/extensions/{name=projects/*/catalogs/*} | ||
| "X-Iceberg-Access-Delegation": "vended-credentials", | ||
| }, | ||
| ).json() |
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.
The URL for the BigLake REST API is constructed incorrectly. There's an extra . between the base URI and the path, which will lead to a 404 Not Found error. The path already starts with a /. Additionally, the response from session.get is not checked for errors before attempting to parse it as JSON. This can lead to unhelpful JSONDecodeError exceptions on HTTP failures. You should call response.raise_for_status() to handle non-2xx responses gracefully.
response = session.get(
f"{_ICEBERG_REST_CATALOG_URI}{path}",
headers={
"x-goog-user-project": billing_project_id,
"Content-Type": "application/json; charset=utf-8",
# TODO(tswast): parameter for this option (or get from catalog metadata?)
# /iceberg/{$api_version}/restcatalog/extensions/{name=projects/*/catalogs/*}
"X-Iceberg-Access-Delegation": "vended-credentials",
},
)
response.raise_for_status()
return response.json()| def _sample_biglake_table( | ||
| *, | ||
| table_id: str, | ||
| credentials: google.oauth2.credentials.Credentials, | ||
| bqclient: google.cloud.bigquery.Client, | ||
| target_bytes: int, | ||
| progress_bar_type: str | None, | ||
| use_bqstorage_api: bool, | ||
| ) -> Optional[pandas.DataFrame]: | ||
| pass |
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.
The function _sample_biglake_table is a stub with a pass statement. The PR title suggests support for BigLake tables is being added, but the core implementation is missing. This function needs to be implemented to fulfill the feature's goal. Additionally, corresponding unit tests should be added to verify its functionality.
| """ | ||
| # https://iceberg.apache.org/spec/#metrics | ||
| # total-files-size | ||
| project, catalog, namespace, table = table_id.split(".") |
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.
Unpacking table_id.split('.') directly into four variables is unsafe. If table_id doesn't contain exactly three dots, this will raise a ValueError. It's better to validate the number of parts before unpacking to provide a more informative error message and prevent unexpected crashes.
parts = table_id.split(".")
if len(parts) != 4:
raise ValueError(
"Invalid BigLake table ID. Expected format: "
"project.catalog.namespace.table"
)
project, catalog, namespace, table = parts| """ | ||
| Docstring for get_table_metadata |
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.
| # BigLake tables can't be read directly by the BQ Storage Read API, so make | ||
| # sure we run a query first. | ||
| parts = table_id.split(".") | ||
| if len(parts) == 4: |
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.
Relying on len(table_id.split('.')) == 4 to identify a BigLake table is fragile. BigQuery identifiers can contain dots if they are quoted (e.g., my-project.dataset.with.dot.table). This could lead to misidentifying a standard BigQuery table as a BigLake table. Consider a more robust detection mechanism. For example, you could attempt to parse the ID as a BigLake ID and handle failure, or introduce an explicit parameter to specify the table type.
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:
Fixes #<issue_number_goes_here> 🦕