2020import polars
2121
2222import bigframes
23- import bigframes .clients
2423import bigframes .core .blocks
2524import bigframes .core .compile .polars
26- import bigframes .core .ordering
2725import bigframes .dataframe
28- import bigframes .session .clients
2926import bigframes .session .executor
3027import bigframes .session .metrics
3128
3532class TestExecutor (bigframes .session .executor .Executor ):
3633 compiler = bigframes .core .compile .polars .PolarsCompiler ()
3734
35+ def peek (
36+ self ,
37+ array_value : bigframes .core .ArrayValue ,
38+ n_rows : int ,
39+ use_explicit_destination : Optional [bool ] = False ,
40+ ):
41+ """
42+ A 'peek' efficiently accesses a small number of rows in the dataframe.
43+ """
44+ lazy_frame : polars .LazyFrame = self .compiler .compile (array_value )
45+ pa_table = lazy_frame .collect ().limit (n_rows ).to_arrow ()
46+ # Currently, pyarrow types might not quite be exactly the ones in the bigframes schema.
47+ # Nullability may be different, and might use large versions of list, string datatypes.
48+ return bigframes .session .executor .ExecuteResult (
49+ arrow_batches = pa_table .to_batches (),
50+ schema = array_value .schema ,
51+ total_bytes = pa_table .nbytes ,
52+ total_rows = pa_table .num_rows ,
53+ )
54+
3855 def execute (
3956 self ,
4057 array_value : bigframes .core .ArrayValue ,
@@ -58,6 +75,14 @@ def execute(
5875 total_rows = pa_table .num_rows ,
5976 )
6077
78+ def cached (
79+ self ,
80+ array_value : bigframes .core .ArrayValue ,
81+ * ,
82+ config ,
83+ ) -> None :
84+ return
85+
6186
6287class TestSession (bigframes .session .Session ):
6388 def __init__ (self ):
@@ -92,3 +117,8 @@ def read_pandas(self, pandas_dataframe, write_engine="default"):
92117 pandas_dataframe = pandas_dataframe .to_frame ()
93118 local_block = bigframes .core .blocks .Block .from_local (pandas_dataframe , self )
94119 return bigframes .dataframe .DataFrame (local_block )
120+
121+ @property
122+ def bqclient (self ):
123+ # prevents logger from trying to call bq upon any errors
124+ return None
0 commit comments