@@ -221,7 +221,14 @@ def shape(self) -> typing.Tuple[int, int]:
221221 except Exception :
222222 pass
223223
224- row_count = self .session ._executor .get_row_count (self .expr )
224+ row_count = next (
225+ iter (
226+ self .session ._executor .execute (self .expr .row_count ())
227+ .to_arrow_table ()
228+ .to_pydict ()
229+ .values ()
230+ )
231+ )[0 ]
225232 return (row_count , len (self .value_columns ))
226233
227234 @property
@@ -485,7 +492,7 @@ def to_arrow(
485492 * ,
486493 ordered : bool = True ,
487494 allow_large_results : Optional [bool ] = None ,
488- ) -> Tuple [pa .Table , bigquery .QueryJob ]:
495+ ) -> Tuple [pa .Table , Optional [ bigquery .QueryJob ] ]:
489496 """Run query and download results as a pyarrow Table."""
490497 execute_result = self .session ._executor .execute (
491498 self .expr , ordered = ordered , use_explicit_destination = allow_large_results
@@ -659,7 +666,7 @@ def _materialize_local(
659666
660667 # TODO: Maybe materialize before downsampling
661668 # Some downsampling methods
662- if fraction < 1 :
669+ if fraction < 1 and ( execute_result . total_rows is not None ) :
663670 if not sample_config .enable_downsampling :
664671 raise RuntimeError (
665672 f"The data size ({ table_mb :.2f} MB) exceeds the maximum download limit of "
@@ -690,7 +697,6 @@ def _materialize_local(
690697 MaterializationOptions (ordered = materialize_options .ordered )
691698 )
692699 else :
693- total_rows = execute_result .total_rows
694700 arrow = execute_result .to_arrow_table ()
695701 df = io_pandas .arrow_to_pandas (arrow , schema = self .expr .schema )
696702 self ._copy_index_to_pandas (df )
@@ -1570,12 +1576,19 @@ def retrieve_repr_request_results(
15701576
15711577 # head caches full underlying expression, so row_count will be free after
15721578 head_result = self .session ._executor .head (self .expr , max_results )
1573- count = self .session ._executor .get_row_count (self .expr )
1579+ row_count = next (
1580+ iter (
1581+ self .session ._executor .execute (self .expr .row_count ())
1582+ .to_arrow_table ()
1583+ .to_pydict ()
1584+ .values ()
1585+ )
1586+ )[0 ]
15741587
15751588 arrow = head_result .to_arrow_table ()
15761589 df = io_pandas .arrow_to_pandas (arrow , schema = self .expr .schema )
15771590 self ._copy_index_to_pandas (df )
1578- return df , count , head_result .query_job
1591+ return df , row_count , head_result .query_job
15791592
15801593 def promote_offsets (self , label : Label = None ) -> typing .Tuple [Block , str ]:
15811594 expr , result_id = self ._expr .promote_offsets ()
0 commit comments