-
Notifications
You must be signed in to change notification settings - Fork 321
Feat: microgen - adds _client_helpers.py.j2 template
#2299
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
Changes from 23 commits
b9d4a04
5b4d538
132c571
90b224e
e071eab
dc72a98
7318f0b
07910c5
dc54c99
28de5f8
c457754
595e59f
44a0777
3e9ade6
485b9d4
a4276fe
1d0d036
eff7223
0734bf8
510a87b
a3117d8
ae7d3e1
0122907
913f521
3bf9f16
898eab9
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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| {# | ||
| This is a partial template file intended to be included in other templates. | ||
| It contains helper methods for the BigQueryClient class. | ||
| #} | ||
|
|
||
| # --- HELPER METHODS --- | ||
| def _parse_dataset_path(self, dataset_path: str) -> Tuple[Optional[str], str]: | ||
|
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. Are these helper functions going to be included in every generated client or is the inclusion of each individual function done on a selective basis? 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. Thanks for checking. There is only one generated client and these three helper functions will be included one time via jinja templating imports in the file that the client class is placed in. For context: The purpose of this microgenerator is to create code that will support customer transition from using a strictly handwritten To help facilitate this, a proxy of certain attributes associated with each Our helpers are present so that customer can provide the As an example, without the centralized To use For the past ten years, customers have not needed to do that extra step. With the new Our helpers take strings similar to It may seem like a little thing, but it will hopefully ease the transition to using the new GAPIC generated library. 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. @gkevinzheng see above. |
||
| """ | ||
| Helper to parse project_id and/or dataset_id from a string identifier. | ||
|
|
||
| Args: | ||
| dataset_path: A string in the format 'project_id.dataset_id' or | ||
| 'dataset_id'. | ||
|
|
||
| Returns: | ||
| A tuple of (project_id, dataset_id). | ||
| """ | ||
| if "." in dataset_path: | ||
| # Use rsplit to handle legacy paths like `google.com:my-project.my_dataset`. | ||
| project_id, dataset_id = dataset_path.rsplit(".", 1) | ||
| return project_id, dataset_id | ||
| return self.project, dataset_path | ||
|
|
||
| def _parse_dataset_id_to_dict(self, dataset_id: "DatasetIdentifier") -> dict: | ||
| """ | ||
| Helper to create a dictionary from a project_id and dataset_id to pass | ||
| internally between helper functions. | ||
|
|
||
| Args: | ||
| dataset_id: A string or DatasetReference. | ||
|
|
||
| Returns: | ||
| A dict of {"project_id": project_id, "dataset_id": dataset_id_str }. | ||
| """ | ||
| if isinstance(dataset_id, str): | ||
| project_id, dataset_id_str = self._parse_dataset_path(dataset_id) | ||
| return {"project_id": project_id, "dataset_id": dataset_id_str} | ||
| elif isinstance(dataset_id, dataset_reference.DatasetReference): | ||
| return { | ||
| "project_id": dataset_id.project_id, | ||
| "dataset_id": dataset_id.dataset_id, | ||
| } | ||
| else: | ||
| raise TypeError(f"Invalid type for dataset_id: {type(dataset_id)}") | ||
|
|
||
| def _parse_project_id_to_dict(self, project_id: Optional[str] = None) -> dict: | ||
| """Helper to create a request dictionary from a project_id.""" | ||
| final_project_id = project_id or self.project | ||
| return {"project_id": final_project_id} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1 | ||
chalmerlowe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.