25
25
ParamEscaper ,
26
26
inject_parameters ,
27
27
transform_paramstyle ,
28
- ArrowQueue ,
28
+ ColumnTable ,
29
29
ColumnQueue
30
30
)
31
31
from databricks .sql .parameters .native import (
@@ -1152,10 +1152,10 @@ def _convert_columnar_table(self, table):
1152
1152
column_names = [c [0 ] for c in self .description ]
1153
1153
ResultRow = Row (* column_names )
1154
1154
result = []
1155
- for row_index in range (len ( table [ 0 ]) ):
1155
+ for row_index in range (table . num_rows ):
1156
1156
curr_row = []
1157
- for col_index in range (len ( table ) ):
1158
- curr_row .append (table [ col_index ][ row_index ] )
1157
+ for col_index in range (table . num_columns ):
1158
+ curr_row .append (table . get_item ( col_index , row_index ) )
1159
1159
result .append (ResultRow (* curr_row ))
1160
1160
1161
1161
return result
@@ -1235,11 +1235,11 @@ def merge_columnar(self, result1, result2):
1235
1235
:return:
1236
1236
"""
1237
1237
1238
- if len ( result1 ) != len ( result2 ) :
1239
- raise ValueError ("The number of columns in both results must be the same " )
1238
+ if result1 . column_names != result2 . column_names :
1239
+ raise ValueError ("The columns in the results don't match " )
1240
1240
1241
- merged_result = [result1 [i ] + result2 [i ] for i in range (len ( result1 ) )]
1242
- return merged_result
1241
+ merged_result = [result1 . column_table [i ] + result2 . column_table [i ] for i in range (result1 . num_columns )]
1242
+ return ColumnTable ( merged_result , result1 . column_names )
1243
1243
1244
1244
def fetchmany_columnar (self , size : int ):
1245
1245
"""
@@ -1250,8 +1250,8 @@ def fetchmany_columnar(self, size: int):
1250
1250
raise ValueError ("size argument for fetchmany is %s but must be >= 0" , size )
1251
1251
1252
1252
results = self .results .next_n_rows (size )
1253
- n_remaining_rows = size - len ( results [ 0 ])
1254
- self ._next_row_index += len ( results [ 0 ])
1253
+ n_remaining_rows = size - results . num_rows
1254
+ self ._next_row_index += results . num_rows
1255
1255
1256
1256
while (
1257
1257
n_remaining_rows > 0
@@ -1261,8 +1261,8 @@ def fetchmany_columnar(self, size: int):
1261
1261
self ._fill_results_buffer ()
1262
1262
partial_results = self .results .next_n_rows (n_remaining_rows )
1263
1263
results = self .merge_columnar (results , partial_results )
1264
- n_remaining_rows -= len ( partial_results [ 0 ])
1265
- self ._next_row_index += len ( partial_results [ 0 ])
1264
+ n_remaining_rows -= partial_results . num_rows
1265
+ self ._next_row_index += partial_results . num_rows
1266
1266
1267
1267
return results
1268
1268
@@ -1282,13 +1282,13 @@ def fetchall_arrow(self) -> "pyarrow.Table":
1282
1282
def fetchall_columnar (self ):
1283
1283
"""Fetch all (remaining) rows of a query result, returning them as a Columnar table."""
1284
1284
results = self .results .remaining_rows ()
1285
- self ._next_row_index += len ( results [ 0 ])
1285
+ self ._next_row_index += results . num_rows
1286
1286
1287
1287
while not self .has_been_closed_server_side and self .has_more_rows :
1288
1288
self ._fill_results_buffer ()
1289
1289
partial_results = self .results .remaining_rows ()
1290
1290
results = self .merge_columnar (results , partial_results )
1291
- self ._next_row_index += len ( partial_results [ 0 ])
1291
+ self ._next_row_index += partial_results . num_rows
1292
1292
1293
1293
return results
1294
1294
0 commit comments