6969import bigframes .exceptions as bfe
7070import bigframes .operations as ops
7171import bigframes .operations .aggregations as agg_ops
72- from bigframes .session import dry_runs
72+ from bigframes .session import dry_runs , execution_spec
7373from bigframes .session import executor as executors
7474
7575# Type constraint for wherever column labels are used
@@ -257,7 +257,10 @@ def shape(self) -> typing.Tuple[int, int]:
257257 except Exception :
258258 pass
259259
260- row_count = self .session ._executor .execute (self .expr .row_count ()).to_py_scalar ()
260+ row_count = self .session ._executor .execute (
261+ self .expr .row_count (),
262+ execution_spec .ExecutionSpec (promise_under_10gb = True , ordered = False ),
263+ ).to_py_scalar ()
261264 return (row_count , len (self .value_columns ))
262265
263266 @property
@@ -539,8 +542,17 @@ def to_arrow(
539542 allow_large_results : Optional [bool ] = None ,
540543 ) -> Tuple [pa .Table , Optional [bigquery .QueryJob ]]:
541544 """Run query and download results as a pyarrow Table."""
545+ under_10gb = (
546+ (not allow_large_results )
547+ if (allow_large_results is not None )
548+ else bigframes .options ._allow_large_results
549+ )
542550 execute_result = self .session ._executor .execute (
543- self .expr , ordered = ordered , use_explicit_destination = allow_large_results
551+ self .expr ,
552+ execution_spec .ExecutionSpec (
553+ promise_under_10gb = under_10gb ,
554+ ordered = ordered ,
555+ ),
544556 )
545557 pa_table = execute_result .to_arrow_table ()
546558
@@ -629,8 +641,15 @@ def try_peek(
629641 self , n : int = 20 , force : bool = False , allow_large_results = None
630642 ) -> typing .Optional [pd .DataFrame ]:
631643 if force or self .expr .supports_fast_peek :
632- result = self .session ._executor .peek (
633- self .expr , n , use_explicit_destination = allow_large_results
644+ # really, we should just block insane peek values and always assume <10gb
645+ under_10gb = (
646+ (not allow_large_results )
647+ if (allow_large_results is not None )
648+ else bigframes .options ._allow_large_results
649+ )
650+ result = self .session ._executor .execute (
651+ self .expr ,
652+ execution_spec .ExecutionSpec (promise_under_10gb = under_10gb , peek = n ),
634653 )
635654 df = result .to_pandas ()
636655 return self ._copy_index_to_pandas (df )
@@ -647,10 +666,18 @@ def to_pandas_batches(
647666
648667 page_size and max_results determine the size and number of batches,
649668 see https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.job.QueryJob#google_cloud_bigquery_job_QueryJob_result"""
669+
670+ under_10gb = (
671+ (not allow_large_results )
672+ if (allow_large_results is not None )
673+ else bigframes .options ._allow_large_results
674+ )
650675 execute_result = self .session ._executor .execute (
651676 self .expr ,
652- ordered = True ,
653- use_explicit_destination = allow_large_results ,
677+ execution_spec .ExecutionSpec (
678+ promise_under_10gb = under_10gb ,
679+ ordered = True ,
680+ ),
654681 )
655682
656683 # To reduce the number of edge cases to consider when working with the
@@ -696,10 +723,17 @@ def _materialize_local(
696723 ) -> Tuple [pd .DataFrame , Optional [bigquery .QueryJob ]]:
697724 """Run query and download results as a pandas DataFrame. Return the total number of results as well."""
698725 # TODO(swast): Allow for dry run and timeout.
726+ under_10gb = (
727+ (not materialize_options .allow_large_results )
728+ if (materialize_options .allow_large_results is not None )
729+ else bigframes .options ._allow_large_results
730+ )
699731 execute_result = self .session ._executor .execute (
700732 self .expr ,
701- ordered = materialize_options .ordered ,
702- use_explicit_destination = materialize_options .allow_large_results ,
733+ execution_spec .ExecutionSpec (
734+ promise_under_10gb = under_10gb ,
735+ ordered = True ,
736+ ),
703737 )
704738 sample_config = materialize_options .downsampling
705739 if execute_result .total_bytes is not None :
@@ -1616,9 +1650,19 @@ def retrieve_repr_request_results(
16161650 config = executors .CacheConfig (optimize_for = "head" , if_cached = "reuse-strict" ),
16171651 )
16181652 head_result = self .session ._executor .execute (
1619- self .expr .slice (start = None , stop = max_results , step = None )
1653+ self .expr .slice (start = None , stop = max_results , step = None ),
1654+ execution_spec .ExecutionSpec (
1655+ promise_under_10gb = True ,
1656+ ordered = True ,
1657+ ),
16201658 )
1621- row_count = self .session ._executor .execute (self .expr .row_count ()).to_py_scalar ()
1659+ row_count = self .session ._executor .execute (
1660+ self .expr .row_count (),
1661+ execution_spec .ExecutionSpec (
1662+ promise_under_10gb = True ,
1663+ ordered = False ,
1664+ ),
1665+ ).to_py_scalar ()
16221666
16231667 head_df = head_result .to_pandas ()
16241668 return self ._copy_index_to_pandas (head_df ), row_count , head_result .query_job
0 commit comments