28
28
29
29
import logging
30
30
31
+ try :
32
+ import pyarrow
33
+ except ImportError :
34
+ pyarrow = None
35
+
31
36
logger = logging .getLogger (__name__ )
32
37
33
38
34
39
class ResultSetQueue (ABC ):
35
40
@abstractmethod
36
- def next_n_rows (self , num_rows : int ) -> pyarrow . Table :
41
+ def next_n_rows (self , num_rows : int ):
37
42
pass
38
43
39
44
@abstractmethod
40
- def remaining_rows (self ) -> pyarrow . Table :
45
+ def remaining_rows (self ):
41
46
pass
42
47
43
48
@@ -100,7 +105,7 @@ def build_queue(
100
105
class ArrowQueue (ResultSetQueue ):
101
106
def __init__ (
102
107
self ,
103
- arrow_table : pyarrow .Table ,
108
+ arrow_table : " pyarrow.Table" ,
104
109
n_valid_rows : int ,
105
110
start_row_index : int = 0 ,
106
111
):
@@ -115,7 +120,7 @@ def __init__(
115
120
self .arrow_table = arrow_table
116
121
self .n_valid_rows = n_valid_rows
117
122
118
- def next_n_rows (self , num_rows : int ) -> pyarrow .Table :
123
+ def next_n_rows (self , num_rows : int ) -> " pyarrow.Table" :
119
124
"""Get upto the next n rows of the Arrow dataframe"""
120
125
length = min (num_rows , self .n_valid_rows - self .cur_row_index )
121
126
# Note that the table.slice API is not the same as Python's slice
@@ -124,7 +129,7 @@ def next_n_rows(self, num_rows: int) -> pyarrow.Table:
124
129
self .cur_row_index += slice .num_rows
125
130
return slice
126
131
127
- def remaining_rows (self ) -> pyarrow .Table :
132
+ def remaining_rows (self ) -> " pyarrow.Table" :
128
133
slice = self .arrow_table .slice (
129
134
self .cur_row_index , self .n_valid_rows - self .cur_row_index
130
135
)
@@ -184,7 +189,7 @@ def __init__(
184
189
self .table = self ._create_next_table ()
185
190
self .table_row_index = 0
186
191
187
- def next_n_rows (self , num_rows : int ) -> pyarrow .Table :
192
+ def next_n_rows (self , num_rows : int ) -> " pyarrow.Table" :
188
193
"""
189
194
Get up to the next n rows of the cloud fetch Arrow dataframes.
190
195
@@ -216,7 +221,7 @@ def next_n_rows(self, num_rows: int) -> pyarrow.Table:
216
221
logger .debug ("CloudFetchQueue: collected {} next rows" .format (results .num_rows ))
217
222
return results
218
223
219
- def remaining_rows (self ) -> pyarrow .Table :
224
+ def remaining_rows (self ) -> " pyarrow.Table" :
220
225
"""
221
226
Get all remaining rows of the cloud fetch Arrow dataframes.
222
227
@@ -237,7 +242,7 @@ def remaining_rows(self) -> pyarrow.Table:
237
242
self .table_row_index = 0
238
243
return results
239
244
240
- def _create_next_table (self ) -> Union [pyarrow .Table , None ]:
245
+ def _create_next_table (self ) -> Union [" pyarrow.Table" , None ]:
241
246
logger .debug (
242
247
"CloudFetchQueue: Trying to get downloaded file for row {}" .format (
243
248
self .start_row_index
@@ -276,7 +281,7 @@ def _create_next_table(self) -> Union[pyarrow.Table, None]:
276
281
277
282
return arrow_table
278
283
279
- def _create_empty_table (self ) -> pyarrow .Table :
284
+ def _create_empty_table (self ) -> " pyarrow.Table" :
280
285
# Create a 0-row table with just the schema bytes
281
286
return create_arrow_table_from_arrow_file (self .schema_bytes , self .description )
282
287
@@ -515,7 +520,7 @@ def transform_paramstyle(
515
520
return output
516
521
517
522
518
- def create_arrow_table_from_arrow_file (file_bytes : bytes , description ) -> pyarrow .Table :
523
+ def create_arrow_table_from_arrow_file (file_bytes : bytes , description ) -> " pyarrow.Table" :
519
524
arrow_table = convert_arrow_based_file_to_arrow_table (file_bytes )
520
525
return convert_decimals_in_arrow_table (arrow_table , description )
521
526
@@ -542,7 +547,7 @@ def convert_arrow_based_set_to_arrow_table(arrow_batches, lz4_compressed, schema
542
547
return arrow_table , n_rows
543
548
544
549
545
- def convert_decimals_in_arrow_table (table , description ) -> pyarrow .Table :
550
+ def convert_decimals_in_arrow_table (table , description ) -> " pyarrow.Table" :
546
551
for i , col in enumerate (table .itercolumns ()):
547
552
if description [i ][1 ] == "decimal" :
548
553
decimal_col = col .to_pandas ().apply (
0 commit comments