-
Notifications
You must be signed in to change notification settings - Fork 298
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: accept TableListItem where TableReference is accepted #1016
Changes from 4 commits
5bcaa92
f830a02
297f9a3
eca2789
0c1214b
9467abc
8775658
86f7c87
9b6c908
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 |
---|---|---|
|
@@ -806,13 +806,16 @@ def get_dataset( | |
|
||
def get_iam_policy( | ||
self, | ||
table: Union[Table, TableReference], | ||
table: Union[Table, TableReference, TableListItem, str], | ||
requested_policy_version: int = 1, | ||
retry: retries.Retry = DEFAULT_RETRY, | ||
timeout: float = DEFAULT_TIMEOUT, | ||
) -> Policy: | ||
if not isinstance(table, (Table, TableReference)): | ||
raise TypeError("table must be a Table or TableReference") | ||
table = _table_arg_to_table_ref(table, default_project=self.project) | ||
if not isinstance(table, (TableReference)): | ||
raise TypeError( | ||
"table must be a Table, TableReference, or TableListItem, or string" | ||
) | ||
|
||
if requested_policy_version != 1: | ||
raise ValueError("only IAM policy version 1 is supported") | ||
|
@@ -835,14 +838,17 @@ def get_iam_policy( | |
|
||
def set_iam_policy( | ||
self, | ||
table: Union[Table, TableReference], | ||
table: Union[Table, TableReference, TableListItem, str], | ||
policy: Policy, | ||
updateMask: str = None, | ||
retry: retries.Retry = DEFAULT_RETRY, | ||
timeout: float = DEFAULT_TIMEOUT, | ||
) -> Policy: | ||
if not isinstance(table, (Table, TableReference)): | ||
raise TypeError("table must be a Table or TableReference") | ||
table = _table_arg_to_table_ref(table, default_project=self.project) | ||
if not isinstance(table, (TableReference)): | ||
raise TypeError( | ||
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. Line not covered in unit tests 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. Ah, got it! Thanks! |
||
"table must be a Table, TableReference, or TableListItem, or string" | ||
) | ||
|
||
if not isinstance(policy, (Policy)): | ||
raise TypeError("policy must be a Policy") | ||
|
@@ -869,13 +875,16 @@ def set_iam_policy( | |
|
||
def test_iam_permissions( | ||
self, | ||
table: Union[Table, TableReference], | ||
table: Union[Table, TableReference, TableListItem, str], | ||
permissions: Sequence[str], | ||
retry: retries.Retry = DEFAULT_RETRY, | ||
timeout: float = DEFAULT_TIMEOUT, | ||
) -> Dict[str, Any]: | ||
if not isinstance(table, (Table, TableReference)): | ||
raise TypeError("table must be a Table or TableReference") | ||
table = _table_arg_to_table_ref(table, default_project=self.project) | ||
if not isinstance(table, (TableReference)): | ||
raise TypeError( | ||
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. Line not covered in unit tests |
||
"table must be a Table, TableReference, or TableListItem, or string" | ||
) | ||
|
||
body = {"permissions": permissions} | ||
|
||
|
@@ -982,7 +991,7 @@ def get_routine( | |
|
||
def get_table( | ||
self, | ||
table: Union[Table, TableReference, str], | ||
table: Union[Table, TableReference, TableListItem, str], | ||
retry: retries.Retry = DEFAULT_RETRY, | ||
timeout: float = DEFAULT_TIMEOUT, | ||
) -> Table: | ||
|
@@ -992,6 +1001,7 @@ def get_table( | |
table (Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
google.cloud.bigquery.table.TableListItem, \ | ||
str, \ | ||
]): | ||
A reference to the table to fetch from the BigQuery API. | ||
|
@@ -1757,7 +1767,7 @@ def delete_routine( | |
|
||
def delete_table( | ||
self, | ||
table: Union[Table, TableReference, str], | ||
table: Union[Table, TableReference, TableListItem, str], | ||
retry: retries.Retry = DEFAULT_RETRY, | ||
timeout: float = DEFAULT_TIMEOUT, | ||
not_found_ok: bool = False, | ||
|
@@ -1771,6 +1781,7 @@ def delete_table( | |
table (Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
google.cloud.bigquery.table.TableListItem, \ | ||
str, \ | ||
]): | ||
A reference to the table to delete. If a string is passed in, | ||
|
@@ -2257,7 +2268,7 @@ def api_request(*args, **kwargs): | |
def load_table_from_uri( | ||
self, | ||
source_uris: Union[str, Sequence[str]], | ||
destination: Union[Table, TableReference, str], | ||
destination: Union[Table, TableReference, TableListItem, str], | ||
job_id: str = None, | ||
job_id_prefix: str = None, | ||
location: str = None, | ||
|
@@ -2278,6 +2289,7 @@ def load_table_from_uri( | |
destination (Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
google.cloud.bigquery.table.TableListItem, \ | ||
str, \ | ||
]): | ||
Table into which data is to be loaded. If a string is passed | ||
|
@@ -2339,7 +2351,7 @@ def load_table_from_uri( | |
def load_table_from_file( | ||
self, | ||
file_obj: BinaryIO, | ||
destination: Union[Table, TableReference, str], | ||
destination: Union[Table, TableReference, TableListItem, str], | ||
rewind: bool = False, | ||
size: int = None, | ||
num_retries: int = _DEFAULT_NUM_RETRIES, | ||
|
@@ -2360,6 +2372,7 @@ def load_table_from_file( | |
destination (Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
google.cloud.bigquery.table.TableListItem, \ | ||
str, \ | ||
]): | ||
Table into which data is to be loaded. If a string is passed | ||
|
@@ -2699,7 +2712,7 @@ def load_table_from_dataframe( | |
def load_table_from_json( | ||
self, | ||
json_rows: Iterable[Dict[str, Any]], | ||
destination: Union[Table, TableReference, str], | ||
destination: Union[Table, TableReference, TableListItem, str], | ||
num_retries: int = _DEFAULT_NUM_RETRIES, | ||
job_id: str = None, | ||
job_id_prefix: str = None, | ||
|
@@ -2733,6 +2746,7 @@ def load_table_from_json( | |
destination (Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
google.cloud.bigquery.table.TableListItem, \ | ||
str, \ | ||
]): | ||
Table into which data is to be loaded. If a string is passed | ||
|
@@ -2980,9 +2994,13 @@ def _do_multipart_upload( | |
def copy_table( | ||
self, | ||
sources: Union[ | ||
Table, TableReference, str, Sequence[Union[Table, TableReference, str]] | ||
Table, | ||
TableReference, | ||
TableListItem, | ||
str, | ||
Sequence[Union[Table, TableReference, TableListItem, str]], | ||
], | ||
destination: Union[Table, TableReference, str], | ||
destination: Union[Table, TableReference, TableListItem, str], | ||
job_id: str = None, | ||
job_id_prefix: str = None, | ||
location: str = None, | ||
|
@@ -3000,11 +3018,13 @@ def copy_table( | |
sources (Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
google.cloud.bigquery.table.TableListItem, \ | ||
str, \ | ||
Sequence[ \ | ||
Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
google.cloud.bigquery.table.TableListItem, \ | ||
str, \ | ||
] \ | ||
], \ | ||
|
@@ -3013,6 +3033,7 @@ def copy_table( | |
destination (Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
google.cloud.bigquery.table.TableListItem, \ | ||
str, \ | ||
]): | ||
Table into which data is to be copied. | ||
|
@@ -3084,7 +3105,7 @@ def copy_table( | |
|
||
def extract_table( | ||
self, | ||
source: Union[Table, TableReference, Model, ModelReference, str], | ||
source: Union[Table, TableReference, TableListItem, Model, ModelReference, str], | ||
destination_uris: Union[str, Sequence[str]], | ||
job_id: str = None, | ||
job_id_prefix: str = None, | ||
|
@@ -3104,6 +3125,7 @@ def extract_table( | |
source (Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
google.cloud.bigquery.table.TableListItem, \ | ||
google.cloud.bigquery.model.Model, \ | ||
google.cloud.bigquery.model.ModelReference, \ | ||
src, \ | ||
|
@@ -3465,7 +3487,7 @@ def insert_rows_from_dataframe( | |
|
||
def insert_rows_json( | ||
self, | ||
table: Union[Table, TableReference, str], | ||
table: Union[Table, TableReference, TableListItem, str], | ||
json_rows: Sequence[Dict], | ||
row_ids: Union[Iterable[str], AutoRowIDs, None] = AutoRowIDs.GENERATE_UUID, | ||
skip_invalid_rows: bool = None, | ||
|
@@ -3483,6 +3505,7 @@ def insert_rows_json( | |
table (Union[ \ | ||
google.cloud.bigquery.table.Table \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
google.cloud.bigquery.table.TableListItem, \ | ||
str \ | ||
]): | ||
The destination table for the row data, or a reference to it. | ||
|
@@ -3605,7 +3628,7 @@ def insert_rows_json( | |
|
||
def list_partitions( | ||
self, | ||
table: Union[Table, TableReference, str], | ||
table: Union[Table, TableReference, TableListItem, str], | ||
retry: retries.Retry = DEFAULT_RETRY, | ||
timeout: float = DEFAULT_TIMEOUT, | ||
) -> Sequence[str]: | ||
|
@@ -3615,6 +3638,7 @@ def list_partitions( | |
table (Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
google.cloud.bigquery.table.TableListItem, \ | ||
str, \ | ||
]): | ||
The table or reference from which to get partition info | ||
|
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.
Need unit test that covers this. Possibly this if statement can be deleted if
_table_arg_to_table_ref
already throws?