Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfe16adc

Browse files
authored
feat: accept TableListItem where TableReference is accepted (#1016)
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:- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea- [ ] Ensure the tests and linter pass- [ ] Code coverage does not decrease (if any source code was changed)- [ ] Appropriate docs were updated (if necessary)🦕
1 parent4ecd64b commitfe16adc

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

‎google/cloud/bigquery/client.py‎

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,12 @@ def get_dataset(
806806

807807
defget_iam_policy(
808808
self,
809-
table:Union[Table,TableReference],
809+
table:Union[Table,TableReference,TableListItem,str],
810810
requested_policy_version:int=1,
811811
retry:retries.Retry=DEFAULT_RETRY,
812812
timeout:float=DEFAULT_TIMEOUT,
813813
)->Policy:
814-
ifnotisinstance(table, (Table,TableReference)):
815-
raiseTypeError("table must be a Table or TableReference")
814+
table=_table_arg_to_table_ref(table,default_project=self.project)
816815

817816
ifrequested_policy_version!=1:
818817
raiseValueError("only IAM policy version 1 is supported")
@@ -835,14 +834,13 @@ def get_iam_policy(
835834

836835
defset_iam_policy(
837836
self,
838-
table:Union[Table,TableReference],
837+
table:Union[Table,TableReference,TableListItem,str],
839838
policy:Policy,
840839
updateMask:str=None,
841840
retry:retries.Retry=DEFAULT_RETRY,
842841
timeout:float=DEFAULT_TIMEOUT,
843842
)->Policy:
844-
ifnotisinstance(table, (Table,TableReference)):
845-
raiseTypeError("table must be a Table or TableReference")
843+
table=_table_arg_to_table_ref(table,default_project=self.project)
846844

847845
ifnotisinstance(policy, (Policy)):
848846
raiseTypeError("policy must be a Policy")
@@ -869,13 +867,12 @@ def set_iam_policy(
869867

870868
deftest_iam_permissions(
871869
self,
872-
table:Union[Table,TableReference],
870+
table:Union[Table,TableReference,TableListItem,str],
873871
permissions:Sequence[str],
874872
retry:retries.Retry=DEFAULT_RETRY,
875873
timeout:float=DEFAULT_TIMEOUT,
876874
)->Dict[str,Any]:
877-
ifnotisinstance(table, (Table,TableReference)):
878-
raiseTypeError("table must be a Table or TableReference")
875+
table=_table_arg_to_table_ref(table,default_project=self.project)
879876

880877
body= {"permissions":permissions}
881878

@@ -982,7 +979,7 @@ def get_routine(
982979

983980
defget_table(
984981
self,
985-
table:Union[Table,TableReference,str],
982+
table:Union[Table,TableReference,TableListItem,str],
986983
retry:retries.Retry=DEFAULT_RETRY,
987984
timeout:float=DEFAULT_TIMEOUT,
988985
)->Table:
@@ -992,6 +989,7 @@ def get_table(
992989
table (Union[\
993990
google.cloud.bigquery.table.Table,\
994991
google.cloud.bigquery.table.TableReference,\
992+
google.cloud.bigquery.table.TableListItem,\
995993
str,\
996994
]):
997995
A reference to the table to fetch from the BigQuery API.
@@ -1757,7 +1755,7 @@ def delete_routine(
17571755

17581756
defdelete_table(
17591757
self,
1760-
table:Union[Table,TableReference,str],
1758+
table:Union[Table,TableReference,TableListItem,str],
17611759
retry:retries.Retry=DEFAULT_RETRY,
17621760
timeout:float=DEFAULT_TIMEOUT,
17631761
not_found_ok:bool=False,
@@ -1771,6 +1769,7 @@ def delete_table(
17711769
table (Union[\
17721770
google.cloud.bigquery.table.Table,\
17731771
google.cloud.bigquery.table.TableReference,\
1772+
google.cloud.bigquery.table.TableListItem,\
17741773
str,\
17751774
]):
17761775
A reference to the table to delete. If a string is passed in,
@@ -2257,7 +2256,7 @@ def api_request(*args, **kwargs):
22572256
defload_table_from_uri(
22582257
self,
22592258
source_uris:Union[str,Sequence[str]],
2260-
destination:Union[Table,TableReference,str],
2259+
destination:Union[Table,TableReference,TableListItem,str],
22612260
job_id:str=None,
22622261
job_id_prefix:str=None,
22632262
location:str=None,
@@ -2278,6 +2277,7 @@ def load_table_from_uri(
22782277
destination (Union[\
22792278
google.cloud.bigquery.table.Table,\
22802279
google.cloud.bigquery.table.TableReference,\
2280+
google.cloud.bigquery.table.TableListItem,\
22812281
str,\
22822282
]):
22832283
Table into which data is to be loaded. If a string is passed
@@ -2339,7 +2339,7 @@ def load_table_from_uri(
23392339
defload_table_from_file(
23402340
self,
23412341
file_obj:BinaryIO,
2342-
destination:Union[Table,TableReference,str],
2342+
destination:Union[Table,TableReference,TableListItem,str],
23432343
rewind:bool=False,
23442344
size:int=None,
23452345
num_retries:int=_DEFAULT_NUM_RETRIES,
@@ -2360,6 +2360,7 @@ def load_table_from_file(
23602360
destination (Union[\
23612361
google.cloud.bigquery.table.Table,\
23622362
google.cloud.bigquery.table.TableReference,\
2363+
google.cloud.bigquery.table.TableListItem,\
23632364
str,\
23642365
]):
23652366
Table into which data is to be loaded. If a string is passed
@@ -2699,7 +2700,7 @@ def load_table_from_dataframe(
26992700
defload_table_from_json(
27002701
self,
27012702
json_rows:Iterable[Dict[str,Any]],
2702-
destination:Union[Table,TableReference,str],
2703+
destination:Union[Table,TableReference,TableListItem,str],
27032704
num_retries:int=_DEFAULT_NUM_RETRIES,
27042705
job_id:str=None,
27052706
job_id_prefix:str=None,
@@ -2733,6 +2734,7 @@ def load_table_from_json(
27332734
destination (Union[\
27342735
google.cloud.bigquery.table.Table,\
27352736
google.cloud.bigquery.table.TableReference,\
2737+
google.cloud.bigquery.table.TableListItem,\
27362738
str,\
27372739
]):
27382740
Table into which data is to be loaded. If a string is passed
@@ -2980,9 +2982,13 @@ def _do_multipart_upload(
29802982
defcopy_table(
29812983
self,
29822984
sources:Union[
2983-
Table,TableReference,str,Sequence[Union[Table,TableReference,str]]
2985+
Table,
2986+
TableReference,
2987+
TableListItem,
2988+
str,
2989+
Sequence[Union[Table,TableReference,TableListItem,str]],
29842990
],
2985-
destination:Union[Table,TableReference,str],
2991+
destination:Union[Table,TableReference,TableListItem,str],
29862992
job_id:str=None,
29872993
job_id_prefix:str=None,
29882994
location:str=None,
@@ -3000,11 +3006,13 @@ def copy_table(
30003006
sources (Union[\
30013007
google.cloud.bigquery.table.Table,\
30023008
google.cloud.bigquery.table.TableReference,\
3009+
google.cloud.bigquery.table.TableListItem,\
30033010
str,\
30043011
Sequence[\
30053012
Union[\
30063013
google.cloud.bigquery.table.Table,\
30073014
google.cloud.bigquery.table.TableReference,\
3015+
google.cloud.bigquery.table.TableListItem,\
30083016
str,\
30093017
]\
30103018
],\
@@ -3013,6 +3021,7 @@ def copy_table(
30133021
destination (Union[\
30143022
google.cloud.bigquery.table.Table,\
30153023
google.cloud.bigquery.table.TableReference,\
3024+
google.cloud.bigquery.table.TableListItem,\
30163025
str,\
30173026
]):
30183027
Table into which data is to be copied.
@@ -3084,7 +3093,7 @@ def copy_table(
30843093

30853094
defextract_table(
30863095
self,
3087-
source:Union[Table,TableReference,Model,ModelReference,str],
3096+
source:Union[Table,TableReference,TableListItem,Model,ModelReference,str],
30883097
destination_uris:Union[str,Sequence[str]],
30893098
job_id:str=None,
30903099
job_id_prefix:str=None,
@@ -3104,6 +3113,7 @@ def extract_table(
31043113
source (Union[\
31053114
google.cloud.bigquery.table.Table,\
31063115
google.cloud.bigquery.table.TableReference,\
3116+
google.cloud.bigquery.table.TableListItem,\
31073117
google.cloud.bigquery.model.Model,\
31083118
google.cloud.bigquery.model.ModelReference,\
31093119
src,\
@@ -3465,7 +3475,7 @@ def insert_rows_from_dataframe(
34653475

34663476
definsert_rows_json(
34673477
self,
3468-
table:Union[Table,TableReference,str],
3478+
table:Union[Table,TableReference,TableListItem,str],
34693479
json_rows:Sequence[Dict],
34703480
row_ids:Union[Iterable[str],AutoRowIDs,None]=AutoRowIDs.GENERATE_UUID,
34713481
skip_invalid_rows:bool=None,
@@ -3483,6 +3493,7 @@ def insert_rows_json(
34833493
table (Union[\
34843494
google.cloud.bigquery.table.Table\
34853495
google.cloud.bigquery.table.TableReference,\
3496+
google.cloud.bigquery.table.TableListItem,\
34863497
str\
34873498
]):
34883499
The destination table for the row data, or a reference to it.
@@ -3605,7 +3616,7 @@ def insert_rows_json(
36053616

36063617
deflist_partitions(
36073618
self,
3608-
table:Union[Table,TableReference,str],
3619+
table:Union[Table,TableReference,TableListItem,str],
36093620
retry:retries.Retry=DEFAULT_RETRY,
36103621
timeout:float=DEFAULT_TIMEOUT,
36113622
)->Sequence[str]:
@@ -3615,6 +3626,7 @@ def list_partitions(
36153626
table (Union[\
36163627
google.cloud.bigquery.table.Table,\
36173628
google.cloud.bigquery.table.TableReference,\
3629+
google.cloud.bigquery.table.TableListItem,\
36183630
str,\
36193631
]):
36203632
The table or reference from which to get partition info

‎tests/unit/test_client.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ def test_get_iam_policy_w_invalid_table(self):
15541554
self.PROJECT,self.DS_ID,self.TABLE_ID,
15551555
)
15561556

1557-
withself.assertRaises(TypeError):
1557+
withself.assertRaises(ValueError):
15581558
client.get_iam_policy(table_resource_string)
15591559

15601560
deftest_get_iam_policy_w_invalid_version(self):
@@ -1675,7 +1675,7 @@ def test_set_iam_policy_w_invalid_table(self):
16751675
self.TABLE_ID,
16761676
)
16771677

1678-
withself.assertRaises(TypeError):
1678+
withself.assertRaises(ValueError):
16791679
client.set_iam_policy(table_resource_string,policy)
16801680

16811681
deftest_test_iam_permissions(self):
@@ -1717,7 +1717,7 @@ def test_test_iam_permissions_w_invalid_table(self):
17171717

17181718
PERMISSIONS= ["bigquery.tables.get","bigquery.tables.update"]
17191719

1720-
withself.assertRaises(TypeError):
1720+
withself.assertRaises(ValueError):
17211721
client.test_iam_permissions(table_resource_string,PERMISSIONS)
17221722

17231723
deftest_update_dataset_w_invalid_field(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp