@@ -552,6 +552,43 @@ def fetchall_json(self):
552
552
553
553
return results
554
554
555
+ def _convert_complex_types_to_string (
556
+ self , rows : "pyarrow.Table"
557
+ ) -> "pyarrow.Table" :
558
+ """
559
+ Convert complex types (array, struct, map) to string representation.
560
+
561
+ Args:
562
+ rows: Input PyArrow table
563
+
564
+ Returns:
565
+ PyArrow table with complex types converted to strings
566
+ """
567
+
568
+ if not pyarrow :
569
+ return rows
570
+
571
+ def convert_complex_column_to_string (col : "pyarrow.Array" ) -> "pyarrow.Array" :
572
+ python_values = col .to_pylist ()
573
+ json_strings = [
574
+ (None if val is None else json .dumps (val )) for val in python_values
575
+ ]
576
+ return pyarrow .array (json_strings , type = pyarrow .string ())
577
+
578
+ converted_columns = []
579
+ for col in rows .columns :
580
+ converted_col = col
581
+ if (
582
+ pyarrow .types .is_list (col .type )
583
+ or pyarrow .types .is_large_list (col .type )
584
+ or pyarrow .types .is_struct (col .type )
585
+ or pyarrow .types .is_map (col .type )
586
+ ):
587
+ converted_col = convert_complex_column_to_string (col )
588
+ converted_columns .append (converted_col )
589
+
590
+ return pyarrow .Table .from_arrays (converted_columns , names = rows .column_names )
591
+
555
592
def fetchmany_arrow (self , size : int ) -> "pyarrow.Table" :
556
593
"""
557
594
Fetch the next set of rows as an Arrow table.
@@ -572,6 +609,9 @@ def fetchmany_arrow(self, size: int) -> "pyarrow.Table":
572
609
results = self .results .next_n_rows (size )
573
610
self ._next_row_index += results .num_rows
574
611
612
+ if not self .backend ._use_arrow_native_complex_types :
613
+ results = self ._convert_complex_types_to_string (results )
614
+
575
615
return results
576
616
577
617
def fetchall_arrow (self ) -> "pyarrow.Table" :
@@ -581,6 +621,9 @@ def fetchall_arrow(self) -> "pyarrow.Table":
581
621
results = self .results .remaining_rows ()
582
622
self ._next_row_index += results .num_rows
583
623
624
+ if not self .backend ._use_arrow_native_complex_types :
625
+ results = self ._convert_complex_types_to_string (results )
626
+
584
627
return results
585
628
586
629
def fetchone (self ) -> Optional [Row ]:
0 commit comments