@@ -1591,14 +1591,17 @@ def job_from_resource(self, resource):
1591
1591
return job .QueryJob .from_api_repr (resource , self )
1592
1592
return job .UnknownJob .from_api_repr (resource , self )
1593
1593
1594
- def create_job (self , job_config , retry = DEFAULT_RETRY ):
1594
+ def create_job (self , job_config , retry = DEFAULT_RETRY , timeout = None ):
1595
1595
"""Create a new job.
1596
1596
Args:
1597
1597
job_config (dict): configuration job representation returned from the API.
1598
1598
1599
1599
Keyword Arguments:
1600
1600
retry (Optional[google.api_core.retry.Retry]):
1601
1601
How to retry the RPC.
1602
+ timeout (Optional[float]):
1603
+ The number of seconds to wait for the underlying HTTP transport
1604
+ before using ``retry``.
1602
1605
1603
1606
Returns:
1604
1607
Union[ \
@@ -1617,7 +1620,11 @@ def create_job(self, job_config, retry=DEFAULT_RETRY):
1617
1620
destination = _get_sub_prop (job_config , ["load" , "destinationTable" ])
1618
1621
source_uris = _get_sub_prop (job_config , ["load" , "sourceUris" ])
1619
1622
return self .load_table_from_uri (
1620
- source_uris , destination , job_config = load_job_config , retry = retry
1623
+ source_uris ,
1624
+ destination ,
1625
+ job_config = load_job_config ,
1626
+ retry = retry ,
1627
+ timeout = timeout ,
1621
1628
)
1622
1629
elif "copy" in job_config :
1623
1630
copy_job_config = google .cloud .bigquery .job .CopyJobConfig .from_api_repr (
@@ -1633,7 +1640,11 @@ def create_job(self, job_config, retry=DEFAULT_RETRY):
1633
1640
table_ref = TableReference .from_api_repr (source_config )
1634
1641
sources .append (table_ref )
1635
1642
return self .copy_table (
1636
- sources , destination , job_config = copy_job_config , retry = retry
1643
+ sources ,
1644
+ destination ,
1645
+ job_config = copy_job_config ,
1646
+ retry = retry ,
1647
+ timeout = timeout ,
1637
1648
)
1638
1649
elif "extract" in job_config :
1639
1650
extract_job_config = google .cloud .bigquery .job .ExtractJobConfig .from_api_repr (
@@ -1650,6 +1661,7 @@ def create_job(self, job_config, retry=DEFAULT_RETRY):
1650
1661
destination_uris ,
1651
1662
job_config = extract_job_config ,
1652
1663
retry = retry ,
1664
+ timeout = timeout ,
1653
1665
source_type = source_type ,
1654
1666
)
1655
1667
elif "query" in job_config :
@@ -1659,7 +1671,9 @@ def create_job(self, job_config, retry=DEFAULT_RETRY):
1659
1671
copy_config
1660
1672
)
1661
1673
query = _get_sub_prop (copy_config , ["query" , "query" ])
1662
- return self .query (query , job_config = query_job_config , retry = retry )
1674
+ return self .query (
1675
+ query , job_config = query_job_config , retry = retry , timeout = timeout
1676
+ )
1663
1677
else :
1664
1678
raise TypeError ("Invalid job configuration received." )
1665
1679
@@ -1981,6 +1995,7 @@ def load_table_from_file(
1981
1995
location = None ,
1982
1996
project = None ,
1983
1997
job_config = None ,
1998
+ timeout = None ,
1984
1999
):
1985
2000
"""Upload the contents of this table from a file-like object.
1986
2001
@@ -2020,6 +2035,9 @@ def load_table_from_file(
2020
2035
to the client's project.
2021
2036
job_config (Optional[google.cloud.bigquery.job.LoadJobConfig]):
2022
2037
Extra configuration options for the job.
2038
+ timeout (Optional[float]):
2039
+ The number of seconds to wait for the underlying HTTP transport
2040
+ before using ``retry``.
2023
2041
2024
2042
Returns:
2025
2043
google.cloud.bigquery.job.LoadJob: A new load job.
@@ -2058,11 +2076,11 @@ def load_table_from_file(
2058
2076
try :
2059
2077
if size is None or size >= _MAX_MULTIPART_SIZE :
2060
2078
response = self ._do_resumable_upload (
2061
- file_obj , job_resource , num_retries
2079
+ file_obj , job_resource , num_retries , timeout
2062
2080
)
2063
2081
else :
2064
2082
response = self ._do_multipart_upload (
2065
- file_obj , job_resource , size , num_retries
2083
+ file_obj , job_resource , size , num_retries , timeout
2066
2084
)
2067
2085
except resumable_media .InvalidResponse as exc :
2068
2086
raise exceptions .from_http_response (exc .response )
@@ -2080,6 +2098,7 @@ def load_table_from_dataframe(
2080
2098
project = None ,
2081
2099
job_config = None ,
2082
2100
parquet_compression = "snappy" ,
2101
+ timeout = None ,
2083
2102
):
2084
2103
"""Upload the contents of a table from a pandas DataFrame.
2085
2104
@@ -2143,6 +2162,9 @@ def load_table_from_dataframe(
2143
2162
passed as the ``compression`` argument to the underlying
2144
2163
``DataFrame.to_parquet()`` method.
2145
2164
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_parquet.html#pandas.DataFrame.to_parquet
2165
+ timeout (Optional[float]):
2166
+ The number of seconds to wait for the underlying HTTP transport
2167
+ before using ``retry``.
2146
2168
2147
2169
Returns:
2148
2170
google.cloud.bigquery.job.LoadJob: A new load job.
@@ -2249,6 +2271,7 @@ def load_table_from_dataframe(
2249
2271
location = location ,
2250
2272
project = project ,
2251
2273
job_config = job_config ,
2274
+ timeout = timeout ,
2252
2275
)
2253
2276
2254
2277
finally :
@@ -2264,6 +2287,7 @@ def load_table_from_json(
2264
2287
location = None ,
2265
2288
project = None ,
2266
2289
job_config = None ,
2290
+ timeout = None ,
2267
2291
):
2268
2292
"""Upload the contents of a table from a JSON string or dict.
2269
2293
@@ -2313,6 +2337,9 @@ def load_table_from_json(
2313
2337
Extra configuration options for the job. The ``source_format``
2314
2338
setting is always set to
2315
2339
:attr:`~google.cloud.bigquery.job.SourceFormat.NEWLINE_DELIMITED_JSON`.
2340
+ timeout (Optional[float]):
2341
+ The number of seconds to wait for the underlying HTTP transport
2342
+ before using ``retry``.
2316
2343
2317
2344
Returns:
2318
2345
google.cloud.bigquery.job.LoadJob: A new load job.
@@ -2357,9 +2384,10 @@ def load_table_from_json(
2357
2384
location = location ,
2358
2385
project = project ,
2359
2386
job_config = job_config ,
2387
+ timeout = timeout ,
2360
2388
)
2361
2389
2362
- def _do_resumable_upload (self , stream , metadata , num_retries ):
2390
+ def _do_resumable_upload (self , stream , metadata , num_retries , timeout ):
2363
2391
"""Perform a resumable upload.
2364
2392
2365
2393
Args:
@@ -2371,21 +2399,25 @@ def _do_resumable_upload(self, stream, metadata, num_retries):
2371
2399
Number of upload retries. (Deprecated: This
2372
2400
argument will be removed in a future release.)
2373
2401
2402
+ timeout (float):
2403
+ The number of seconds to wait for the underlying HTTP transport
2404
+ before using ``retry``.
2405
+
2374
2406
Returns:
2375
2407
requests.Response:
2376
2408
The "200 OK" response object returned after the final chunk
2377
2409
is uploaded.
2378
2410
"""
2379
2411
upload , transport = self ._initiate_resumable_upload (
2380
- stream , metadata , num_retries
2412
+ stream , metadata , num_retries , timeout
2381
2413
)
2382
2414
2383
2415
while not upload .finished :
2384
2416
response = upload .transmit_next_chunk (transport )
2385
2417
2386
2418
return response
2387
2419
2388
- def _initiate_resumable_upload (self , stream , metadata , num_retries ):
2420
+ def _initiate_resumable_upload (self , stream , metadata , num_retries , timeout ):
2389
2421
"""Initiate a resumable upload.
2390
2422
2391
2423
Args:
@@ -2397,6 +2429,10 @@ def _initiate_resumable_upload(self, stream, metadata, num_retries):
2397
2429
Number of upload retries. (Deprecated: This
2398
2430
argument will be removed in a future release.)
2399
2431
2432
+ timeout (float):
2433
+ The number of seconds to wait for the underlying HTTP transport
2434
+ before using ``retry``.
2435
+
2400
2436
Returns:
2401
2437
Tuple:
2402
2438
Pair of
@@ -2419,12 +2455,17 @@ def _initiate_resumable_upload(self, stream, metadata, num_retries):
2419
2455
)
2420
2456
2421
2457
upload .initiate (
2422
- transport , stream , metadata , _GENERIC_CONTENT_TYPE , stream_final = False
2458
+ transport ,
2459
+ stream ,
2460
+ metadata ,
2461
+ _GENERIC_CONTENT_TYPE ,
2462
+ stream_final = False ,
2463
+ timeout = timeout ,
2423
2464
)
2424
2465
2425
2466
return upload , transport
2426
2467
2427
- def _do_multipart_upload (self , stream , metadata , size , num_retries ):
2468
+ def _do_multipart_upload (self , stream , metadata , size , num_retries , timeout ):
2428
2469
"""Perform a multipart upload.
2429
2470
2430
2471
Args:
@@ -2441,6 +2482,10 @@ def _do_multipart_upload(self, stream, metadata, size, num_retries):
2441
2482
Number of upload retries. (Deprecated: This
2442
2483
argument will be removed in a future release.)
2443
2484
2485
+ timeout (float):
2486
+ The number of seconds to wait for the underlying HTTP transport
2487
+ before using ``retry``.
2488
+
2444
2489
Returns:
2445
2490
requests.Response:
2446
2491
The "200 OK" response object returned after the multipart
@@ -2466,7 +2511,9 @@ def _do_multipart_upload(self, stream, metadata, size, num_retries):
2466
2511
max_retries = num_retries
2467
2512
)
2468
2513
2469
- response = upload .transmit (self ._http , data , metadata , _GENERIC_CONTENT_TYPE )
2514
+ response = upload .transmit (
2515
+ self ._http , data , metadata , _GENERIC_CONTENT_TYPE , timeout = timeout
2516
+ )
2470
2517
2471
2518
return response
2472
2519
0 commit comments