@@ -105,7 +105,6 @@ def execute(
105105 * ,
106106 ordered : bool = True ,
107107 use_explicit_destination : Optional [bool ] = False ,
108- get_size_bytes : bool = False ,
109108 page_size : Optional [int ] = None ,
110109 max_results : Optional [int ] = None ,
111110 ):
@@ -152,6 +151,7 @@ def peek(
152151 self ,
153152 array_value : bigframes .core .ArrayValue ,
154153 n_rows : int ,
154+ use_explicit_destination : Optional [bool ] = False ,
155155 ) -> ExecuteResult :
156156 """
157157 A 'peek' efficiently accesses a small number of rows in the dataframe.
@@ -233,8 +233,7 @@ def execute(
233233 array_value : bigframes .core .ArrayValue ,
234234 * ,
235235 ordered : bool = True ,
236- use_explicit_destination : Optional [bool ] = False ,
237- get_size_bytes : bool = False ,
236+ use_explicit_destination : Optional [bool ] = None ,
238237 page_size : Optional [int ] = None ,
239238 max_results : Optional [int ] = None ,
240239 ):
@@ -259,13 +258,14 @@ def execute(
259258 job_config = job_config ,
260259 page_size = page_size ,
261260 max_results = max_results ,
261+ query_with_job = use_explicit_destination ,
262262 )
263263
264264 # Though we provide the read client, iterator may or may not use it based on what is efficient for the result
265265 def iterator_supplier ():
266266 return iterator .to_arrow_iterable (bqstorage_client = self .bqstoragereadclient )
267267
268- if get_size_bytes is True or use_explicit_destination :
268+ if query_job :
269269 size_bytes = self .bqclient .get_table (query_job .destination ).num_bytes
270270 else :
271271 size_bytes = None
@@ -329,8 +329,7 @@ def export_gbq(
329329 if if_exists != "append" and has_timedelta_col :
330330 # Only update schema if this is not modifying an existing table, and the
331331 # new table contains timedelta columns.
332- assert query_job .destination is not None
333- table = self .bqclient .get_table (query_job .destination )
332+ table = self .bqclient .get_table (destination )
334333 table .schema = array_value .schema .to_bigquery ()
335334 self .bqclient .update_table (table , ["schema" ])
336335
@@ -377,6 +376,7 @@ def peek(
377376 self ,
378377 array_value : bigframes .core .ArrayValue ,
379378 n_rows : int ,
379+ use_explicit_destination : Optional [bool ] = None ,
380380 ) -> ExecuteResult :
381381 """
382382 A 'peek' efficiently accesses a small number of rows in the dataframe.
@@ -385,12 +385,24 @@ def peek(
385385 if not tree_properties .can_fast_peek (plan ):
386386 msg = "Peeking this value cannot be done efficiently."
387387 warnings .warn (msg )
388+ if use_explicit_destination is None :
389+ use_explicit_destination = bigframes .options .bigquery .allow_large_results
390+
391+ job_config = bigquery .QueryJobConfig ()
392+ # Use explicit destination to avoid 10GB limit of temporary table
393+ if use_explicit_destination :
394+ destination_table = self .storage_manager .create_temp_table (
395+ array_value .schema .to_bigquery (), cluster_cols = []
396+ )
397+ job_config .destination = destination_table
388398
389399 sql = self .compiler .compile (plan , ordered = False , limit = n_rows )
390400
391401 # TODO(swast): plumb through the api_name of the user-facing api that
392402 # caused this query.
393- iterator , query_job = self ._run_execute_query (sql = sql )
403+ iterator , query_job = self ._run_execute_query (
404+ sql = sql , job_config = job_config , query_with_job = use_explicit_destination
405+ )
394406 return ExecuteResult (
395407 # Probably don't need read client for small peek results, but let client decide
396408 arrow_batches = lambda : iterator .to_arrow_iterable (
@@ -485,7 +497,8 @@ def _run_execute_query(
485497 api_name : Optional [str ] = None ,
486498 page_size : Optional [int ] = None ,
487499 max_results : Optional [int ] = None ,
488- ) -> Tuple [bq_table .RowIterator , bigquery .QueryJob ]:
500+ query_with_job : bool = True ,
501+ ) -> Tuple [bq_table .RowIterator , Optional [bigquery .QueryJob ]]:
489502 """
490503 Starts BigQuery query job and waits for results.
491504 """
@@ -503,15 +516,17 @@ def _run_execute_query(
503516 # as `add_and_trim_labels` ensures the label count does not exceed 64.
504517 bq_io .add_and_trim_labels (job_config , api_name = api_name )
505518 try :
506- return bq_io .start_query_with_client (
519+ iterator , query_job = bq_io .start_query_with_client (
507520 self .bqclient ,
508521 sql ,
509522 job_config = job_config ,
510523 api_name = api_name ,
511524 max_results = max_results ,
512525 page_size = page_size ,
513526 metrics = self .metrics ,
527+ query_with_job = query_with_job ,
514528 )
529+ return iterator , query_job
515530
516531 except google .api_core .exceptions .BadRequest as e :
517532 # Unfortunately, this error type does not have a separate error code or exception type
@@ -642,7 +657,7 @@ def _sql_as_cached_temp_table(
642657 job_config = job_config ,
643658 api_name = "cached" ,
644659 )
645- query_job . destination
660+ assert query_job is not None
646661 query_job .result ()
647662 return query_job .destination
648663
0 commit comments