@@ -501,22 +501,25 @@ def __init__(
501
501
# Initialize queue for result data if not provided
502
502
self .results = results_queue or JsonQueue ([])
503
503
504
- def _convert_json_table (self , rows ):
504
+ def _convert_json_to_arrow (self , rows ):
505
+ """
506
+ Convert raw data rows to Arrow table.
507
+ """
508
+ columns = []
509
+ num_cols = len (rows [0 ])
510
+ for i in range (num_cols ):
511
+ columns .append ([row [i ] for row in rows ])
512
+ names = [col [0 ] for col in self .description ]
513
+ return pyarrow .Table .from_arrays (columns , names = names )
514
+
515
+ def _convert_json_types (self , rows ):
505
516
"""
506
517
Convert raw data rows to Row objects with named columns based on description.
507
518
Also converts string values to appropriate Python types based on column metadata.
508
-
509
- Args:
510
- rows: List of raw data rows
511
- Returns:
512
- List of Row objects with named columns and converted values
513
519
"""
514
520
if not self .description or not rows :
515
521
return rows
516
522
517
- column_names = [col [0 ] for col in self .description ]
518
- ResultRow = Row (* column_names )
519
-
520
523
# JSON + INLINE gives us string values, so we convert them to appropriate
521
524
# types based on column metadata
522
525
converted_rows = []
@@ -539,10 +542,28 @@ def _convert_json_table(self, rows):
539
542
)
540
543
converted_row .append (value )
541
544
542
- converted_rows .append (ResultRow ( * converted_row ) )
545
+ converted_rows .append (converted_row )
543
546
544
547
return converted_rows
545
548
549
+ def _convert_json_table (self , rows ):
550
+ """
551
+ Convert raw data rows to Row objects with named columns based on description.
552
+ Also converts string values to appropriate Python types based on column metadata.
553
+
554
+ Args:
555
+ rows: List of raw data rows
556
+ Returns:
557
+ List of Row objects with named columns and converted values
558
+ """
559
+ if not self .description or not rows :
560
+ return rows
561
+
562
+ ResultRow = Row (* [col [0 ] for col in self .description ])
563
+ rows = self ._convert_json_types (rows )
564
+
565
+ return [ResultRow (* row ) for row in rows ]
566
+
546
567
def fetchmany_json (self , size : int ):
547
568
"""
548
569
Fetch the next set of rows as a columnar table.
@@ -593,7 +614,11 @@ def fetchmany_arrow(self, size: int) -> "pyarrow.Table":
593
614
if size < 0 :
594
615
raise ValueError (f"size argument for fetchmany is { size } but must be >= 0" )
595
616
596
- results = self .results .next_n_rows (size )
617
+ if not isinstance (self .results , JsonQueue ):
618
+ raise NotImplementedError ("fetchmany_arrow only supported for JSON data" )
619
+
620
+ rows = self ._convert_json_types (self .results .next_n_rows (size ))
621
+ results = self ._convert_json_to_arrow (rows )
597
622
self ._next_row_index += results .num_rows
598
623
599
624
return results
@@ -602,7 +627,11 @@ def fetchall_arrow(self) -> "pyarrow.Table":
602
627
"""
603
628
Fetch all remaining rows as an Arrow table.
604
629
"""
605
- results = self .results .remaining_rows ()
630
+ if not isinstance (self .results , JsonQueue ):
631
+ raise NotImplementedError ("fetchall_arrow only supported for JSON data" )
632
+
633
+ rows = self ._convert_json_types (self .results .remaining_rows ())
634
+ results = self ._convert_json_to_arrow (rows )
606
635
self ._next_row_index += results .num_rows
607
636
608
637
return results
0 commit comments