-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: prepare client-side delegation and telemetry for pandas-gbq #17704
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?
Changes from all commits
a2812c9
206ab7f
7646f22
0af9073
be85288
a74b5c0
65f78bc
d91d822
09f0490
e1f00d4
21c0c79
eb478b9
814400e
ac785fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,10 +16,8 @@ | |||||||||||||||||||||||||||||||||||||
| from typing import Any | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import packaging.version | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| from google.cloud.bigquery import exceptions | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| _MIN_PYARROW_VERSION = packaging.version.Version("3.0.0") | ||||||||||||||||||||||||||||||||||||||
| _MIN_BQ_STORAGE_VERSION = packaging.version.Version("2.0.0") | ||||||||||||||||||||||||||||||||||||||
| _BQ_STORAGE_OPTIONAL_READ_SESSION_VERSION = packaging.version.Version("2.6.0") | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -247,3 +245,49 @@ def try_import(self, raise_if_error: bool = False) -> Any: | |||||||||||||||||||||||||||||||||||||
| and PYARROW_VERSIONS.try_import() is not None | ||||||||||||||||||||||||||||||||||||||
| and PYARROW_VERSIONS.installed_version >= _MIN_PYARROW_VERSION_RANGE | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| class PandasGBQVersions: | ||||||||||||||||||||||||||||||||||||||
| """Version and delegation comparisons for pandas-gbq package.""" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def __init__(self): | ||||||||||||||||||||||||||||||||||||||
| self._installed_version = None | ||||||||||||||||||||||||||||||||||||||
| self._delegation_api_version = None | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||||||||||
| def installed_version(self) -> packaging.version.Version: | ||||||||||||||||||||||||||||||||||||||
| """Return the parsed version of pandas-gbq""" | ||||||||||||||||||||||||||||||||||||||
| if self._installed_version is None: | ||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||
| import pandas_gbq # type: ignore | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| self._installed_version = packaging.version.parse( | ||||||||||||||||||||||||||||||||||||||
| getattr(pandas_gbq, "__version__", "0.0.0") | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| except Exception: | ||||||||||||||||||||||||||||||||||||||
| self._installed_version = packaging.version.parse("0.0.0") | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return self._installed_version | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||||||||||
| def delegation_api_version(self) -> int: | ||||||||||||||||||||||||||||||||||||||
| """Return the delegation API version of pandas-gbq if installed, otherwise 0.""" | ||||||||||||||||||||||||||||||||||||||
| if self._delegation_api_version is None: | ||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||
| import pandas_gbq # type: ignore | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| self._delegation_api_version = getattr( | ||||||||||||||||||||||||||||||||||||||
| pandas_gbq, "_internal_delegation_api_version", 0 | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| except Exception: | ||||||||||||||||||||||||||||||||||||||
| self._delegation_api_version = 0 | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+275
to
+283
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not want to hide errors for users. |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return self._delegation_api_version | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||||||||||
| def is_delegation_supported(self) -> bool: | ||||||||||||||||||||||||||||||||||||||
| """True if the installed pandas-gbq version supports query delegation API (version >= 1).""" | ||||||||||||||||||||||||||||||||||||||
| return self.delegation_api_version >= 1 | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| PANDAS_GBQ_VERSIONS = PandasGBQVersions() | ||||||||||||||||||||||||||||||||||||||
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.
Catching only
ImportErrorwhen importingpandas_gbqcan lead to unhandled exceptions if the import fails due to other issues (e.g., compiled extension load failures,AttributeError, orTypeErrorfrom broken dependencies). Additionally,packaging.version.parsecan raiseInvalidVersionif the version string is malformed. CatchingExceptionensures a robust fallback to version0.0.0.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.
I do not want to hide errors for users.