40
40
StructQueryParameter ,
41
41
UDFResource ,
42
42
)
43
- from google .cloud .bigquery .retry import DEFAULT_RETRY , DEFAULT_JOB_RETRY
43
+ from google .cloud .bigquery .retry import (
44
+ DEFAULT_RETRY ,
45
+ DEFAULT_JOB_RETRY ,
46
+ POLLING_DEFAULT_VALUE ,
47
+ )
44
48
from google .cloud .bigquery .routine import RoutineReference
45
49
from google .cloud .bigquery .schema import SchemaField
46
50
from google .cloud .bigquery .table import _EmptyRowIterator
@@ -1437,7 +1441,7 @@ def result( # type: ignore # (incompatible with supertype)
1437
1441
page_size : Optional [int ] = None ,
1438
1442
max_results : Optional [int ] = None ,
1439
1443
retry : Optional [retries .Retry ] = DEFAULT_RETRY ,
1440
- timeout : Optional [float ] = None ,
1444
+ timeout : Optional [Union [ float , object ]] = POLLING_DEFAULT_VALUE ,
1441
1445
start_index : Optional [int ] = None ,
1442
1446
job_retry : Optional [retries .Retry ] = DEFAULT_JOB_RETRY ,
1443
1447
) -> Union ["RowIterator" , _EmptyRowIterator ]:
@@ -1457,11 +1461,14 @@ def result( # type: ignore # (incompatible with supertype)
1457
1461
is ``DONE``, retrying is aborted early even if the
1458
1462
results are not available, as this will not change
1459
1463
anymore.
1460
- timeout (Optional[float]):
1464
+ timeout (Optional[Union[float, \
1465
+ google.api_core.future.polling.PollingFuture._DEFAULT_VALUE, \
1466
+ ]]):
1461
1467
The number of seconds to wait for the underlying HTTP transport
1462
- before using ``retry``.
1463
- If multiple requests are made under the hood, ``timeout``
1464
- applies to each individual request.
1468
+ before using ``retry``. If ``None``, wait indefinitely
1469
+ unless an error is returned. If unset, only the
1470
+ underlying API calls have their default timeouts, but we still
1471
+ wait indefinitely for the job to finish.
1465
1472
start_index (Optional[int]):
1466
1473
The zero-based index of the starting row to read.
1467
1474
job_retry (Optional[google.api_core.retry.Retry]):
@@ -1507,6 +1514,13 @@ def result( # type: ignore # (incompatible with supertype)
1507
1514
# Intentionally omit job_id and query_id since this doesn't
1508
1515
# actually correspond to a finished query job.
1509
1516
)
1517
+
1518
+ # When timeout has default sentinel value ``object()``, do not pass
1519
+ # anything to invoke default timeouts in subsequent calls.
1520
+ kwargs : Dict [str , Union [_helpers .TimeoutType , object ]] = {}
1521
+ if type (timeout ) is not object :
1522
+ kwargs ["timeout" ] = timeout
1523
+
1510
1524
try :
1511
1525
retry_do_query = getattr (self , "_retry_do_query" , None )
1512
1526
if retry_do_query is not None :
@@ -1548,7 +1562,7 @@ def is_job_done():
1548
1562
# rateLimitExceeded errors are ambiguous. We want to know if
1549
1563
# the query job failed and not just the call to
1550
1564
# jobs.getQueryResults.
1551
- if self .done (retry = retry , timeout = timeout ):
1565
+ if self .done (retry = retry , ** kwargs ):
1552
1566
# If it's already failed, we might as well stop.
1553
1567
job_failed_exception = self .exception ()
1554
1568
if job_failed_exception is not None :
@@ -1585,14 +1599,14 @@ def is_job_done():
1585
1599
# response from the REST API. This ensures we aren't
1586
1600
# making any extra API calls if the previous loop
1587
1601
# iteration fetched the finished job.
1588
- self ._reload_query_results (retry = retry , timeout = timeout )
1602
+ self ._reload_query_results (retry = retry , ** kwargs )
1589
1603
return True
1590
1604
1591
1605
# Call jobs.getQueryResults with max results set to 0 just to
1592
1606
# wait for the query to finish. Unlike most methods,
1593
1607
# jobs.getQueryResults hangs as long as it can to ensure we
1594
1608
# know when the query has finished as soon as possible.
1595
- self ._reload_query_results (retry = retry , timeout = timeout )
1609
+ self ._reload_query_results (retry = retry , ** kwargs )
1596
1610
1597
1611
# Even if the query is finished now according to
1598
1612
# jobs.getQueryResults, we'll want to reload the job status if
@@ -1682,10 +1696,10 @@ def is_job_done():
1682
1696
max_results = max_results ,
1683
1697
start_index = start_index ,
1684
1698
retry = retry ,
1685
- timeout = timeout ,
1686
1699
query_id = self .query_id ,
1687
1700
first_page_response = first_page_response ,
1688
1701
num_dml_affected_rows = self ._query_results .num_dml_affected_rows ,
1702
+ ** kwargs ,
1689
1703
)
1690
1704
rows ._preserve_order = _contains_order_by (self .query )
1691
1705
return rows
0 commit comments