1515
1616from typing import Optional
1717
18- from bigframes .core import bigframe_node , nodes , rewrite
18+ from bigframes .core import bigframe_node , rewrite
1919from bigframes .session import executor , semi_executor
2020
2121
@@ -30,30 +30,15 @@ def execute(
3030 ordered : bool ,
3131 peek : Optional [int ] = None ,
3232 ) -> Optional [executor .ExecuteResult ]:
33- rewrite_node = plan
34-
35- # Implement top-level slice here so that we don't have to implement
36- # slice in all ReadLocalNode compilers.
37- slice_start : Optional [int ] = None
38- slice_stop : Optional [int ] = None
39-
40- if isinstance (plan , nodes .SliceNode ):
41- # These slice features are not supported by pyarrow.Table.slice. Must
42- # have a non-negative start and stop and no custom step size.
43- if (
44- (plan .step is not None and plan .step != 1 )
45- or (plan .start is not None and plan .start < 0 )
46- or (plan .stop is not None and plan .stop < 0 )
47- ):
48- return None
33+ reduced_result = rewrite .try_reduce_to_local_scan (plan )
34+ if not reduced_result :
35+ return None
4936
50- slice_start = plan .start
51- slice_stop = plan .stop
52- rewrite_node = plan .child
37+ node , limit = reduced_result
5338
54- node = rewrite . try_reduce_to_local_scan ( rewrite_node )
55- if not node :
56- return None
39+ if limit is not None :
40+ if peek is None or limit < peek :
41+ peek = limit
5742
5843 # TODO: Can support some sorting
5944 offsets_col = node .offsets_col .sql if (node .offsets_col is not None ) else None
@@ -67,23 +52,7 @@ def execute(
6752
6853 arrow_table = arrow_table .select (needed_cols )
6954 arrow_table = arrow_table .rename_columns ([id .sql for id in node .ids ])
70-
71- if slice_start is not None or slice_stop is not None :
72- slice_length : Optional [int ] = None
73-
74- if slice_stop is not None :
75- if slice_start is None :
76- slice_length = slice_stop
77- else :
78- slice_length = slice_stop - slice_start
79-
80- arrow_table = arrow_table .slice (
81- offset = slice_start if slice_start is not None else 0 ,
82- length = slice_length ,
83- )
84- total_rows = arrow_table .num_rows
85- else :
86- total_rows = node .row_count
55+ total_rows = node .row_count
8756
8857 if (peek is not None ) and (total_rows is not None ):
8958 total_rows = min (peek , total_rows )
0 commit comments