@@ -784,8 +784,8 @@ def execute(
784
784
parameters = prepared_params ,
785
785
)
786
786
787
- print ("Line 781" )
788
- print (execute_response )
787
+ # print("Line 781")
788
+ # print(execute_response)
789
789
self .active_result_set = ResultSet (
790
790
self .connection ,
791
791
execute_response ,
@@ -1141,7 +1141,7 @@ def _fill_results_buffer(self):
1141
1141
def _convert_columnar_table (self , table ):
1142
1142
column_names = [c [0 ] for c in self .description ]
1143
1143
ResultRow = Row (* column_names )
1144
- print ("Table\n " ,table )
1144
+ # print("Table\n",table)
1145
1145
result = []
1146
1146
for row_index in range (len (table [0 ])):
1147
1147
curr_row = []
@@ -1164,23 +1164,20 @@ def _convert_arrow_table(self, table):
1164
1164
# Need to use nullable types, as otherwise type can change when there are missing values.
1165
1165
# See https://arrow.apache.org/docs/python/pandas.html#nullable-types
1166
1166
# NOTE: This api is epxerimental https://pandas.pydata.org/pandas-docs/stable/user_guide/integer_na.html
1167
- try :
1168
- dtype_mapping = {
1169
- pyarrow .int8 (): pandas .Int8Dtype (),
1170
- pyarrow .int16 (): pandas .Int16Dtype (),
1171
- pyarrow .int32 (): pandas .Int32Dtype (),
1172
- pyarrow .int64 (): pandas .Int64Dtype (),
1173
- pyarrow .uint8 (): pandas .UInt8Dtype (),
1174
- pyarrow .uint16 (): pandas .UInt16Dtype (),
1175
- pyarrow .uint32 (): pandas .UInt32Dtype (),
1176
- pyarrow .uint64 (): pandas .UInt64Dtype (),
1177
- pyarrow .bool_ (): pandas .BooleanDtype (),
1178
- pyarrow .float32 (): pandas .Float32Dtype (),
1179
- pyarrow .float64 (): pandas .Float64Dtype (),
1180
- pyarrow .string (): pandas .StringDtype (),
1181
- }
1182
- except AttributeError :
1183
- print ("pyarrow is not present" )
1167
+ dtype_mapping = {
1168
+ pyarrow .int8 (): pandas .Int8Dtype (),
1169
+ pyarrow .int16 (): pandas .Int16Dtype (),
1170
+ pyarrow .int32 (): pandas .Int32Dtype (),
1171
+ pyarrow .int64 (): pandas .Int64Dtype (),
1172
+ pyarrow .uint8 (): pandas .UInt8Dtype (),
1173
+ pyarrow .uint16 (): pandas .UInt16Dtype (),
1174
+ pyarrow .uint32 (): pandas .UInt32Dtype (),
1175
+ pyarrow .uint64 (): pandas .UInt64Dtype (),
1176
+ pyarrow .bool_ (): pandas .BooleanDtype (),
1177
+ pyarrow .float32 (): pandas .Float32Dtype (),
1178
+ pyarrow .float64 (): pandas .Float64Dtype (),
1179
+ pyarrow .string (): pandas .StringDtype (),
1180
+ }
1184
1181
1185
1182
# Need to rename columns, as the to_pandas function cannot handle duplicate column names
1186
1183
table_renamed = table .rename_columns ([str (c ) for c in range (table .num_columns )])
@@ -1222,6 +1219,20 @@ def fetchmany_arrow(self, size: int) -> "pyarrow.Table":
1222
1219
1223
1220
return results
1224
1221
1222
+ def fetchmany_columnar (self , size : int ):
1223
+ """
1224
+ Fetch the next set of rows of a query result, returning a Columnar Table.
1225
+
1226
+ An empty sequence is returned when no more rows are available.
1227
+ """
1228
+ if size < 0 :
1229
+ raise ValueError ("size argument for fetchmany is %s but must be >= 0" , size )
1230
+
1231
+ results = self .results .next_n_rows (size )
1232
+ self ._next_row_index += results .num_rows
1233
+
1234
+ return results
1235
+
1225
1236
def fetchall_arrow (self ) -> "pyarrow.Table" :
1226
1237
"""Fetch all (remaining) rows of a query result, returning them as a PyArrow table."""
1227
1238
results = self .results .remaining_rows ()
@@ -1245,7 +1256,11 @@ def fetchone(self) -> Optional[Row]:
1245
1256
Fetch the next row of a query result set, returning a single sequence,
1246
1257
or None when no more data is available.
1247
1258
"""
1248
- res = self ._convert_arrow_table (self .fetchmany_arrow (1 ))
1259
+ if isinstance (self .results , ColumnQueue ):
1260
+ res = self ._convert_columnar_table (self .fetchmany_columnar (1 ))
1261
+ else :
1262
+ res = self ._convert_arrow_table (self .fetchmany_arrow (1 ))
1263
+
1249
1264
if len (res ) > 0 :
1250
1265
return res [0 ]
1251
1266
else :
@@ -1260,14 +1275,16 @@ def fetchall(self) -> List[Row]:
1260
1275
else :
1261
1276
return self ._convert_arrow_table (self .fetchall_arrow ())
1262
1277
1263
-
1264
1278
def fetchmany (self , size : int ) -> List [Row ]:
1265
1279
"""
1266
1280
Fetch the next set of rows of a query result, returning a list of rows.
1267
1281
1268
1282
An empty sequence is returned when no more rows are available.
1269
1283
"""
1270
- return self ._convert_arrow_table (self .fetchmany_arrow (size ))
1284
+ if isinstance (self .results , ColumnQueue ):
1285
+ return self ._convert_columnar_table (self .fetchmany_columnar (size ))
1286
+ else :
1287
+ return self ._convert_arrow_table (self .fetchmany_arrow (size ))
1271
1288
1272
1289
def close (self ) -> None :
1273
1290
"""
0 commit comments