Skip to content

Commit 6a8646d

Browse files
committed
Minor fixes
1 parent eeaee96 commit 6a8646d

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/databricks/sql/client.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -1227,13 +1227,17 @@ def fetchmany_arrow(self, size: int) -> "pyarrow.Table":
12271227

12281228
return results
12291229

1230-
def merge_columnar(self, result1, result2):
1231-
"""
1232-
Function to merge / combining the columnar results into a single result
1233-
:param result1:
1234-
:param result2:
1235-
:return:
1236-
"""
1230+
def merge_columnar(self, result1, result2):
1231+
"""
1232+
Function to merge / combining the columnar results into a single result
1233+
:param result1:
1234+
:param result2:
1235+
:return:
1236+
"""
1237+
1238+
if len(result1) != len(result2):
1239+
raise ValueError("The number of columns in both results must be the same")
1240+
12371241
merged_result = [result1[i] + result2[i] for i in range(len(result1))]
12381242
return merged_result
12391243

src/databricks/sql/utils.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,17 @@ def convert_decimals_in_arrow_table(table, description) -> "pyarrow.Table":
589589

590590

591591
def convert_to_assigned_datatypes_in_column_table(column_table, description):
592+
593+
converted_column_table = []
592594
for i, col in enumerate(column_table):
593595
if description[i][1] == "decimal":
594-
column_table[i] = tuple(v if v is None else Decimal(v) for v in col)
596+
converted_column_table.append(tuple(v if v is None else Decimal(v) for v in col))
595597
elif description[i][1] == "date":
596-
column_table[i] = tuple(
598+
converted_column_table[i].append(tuple(
597599
v if v is None else datetime.date.fromisoformat(v) for v in col
598-
)
600+
))
599601
elif description[i][1] == "timestamp":
600-
column_table[i] = tuple(
602+
converted_column_table[i].append(tuple(
601603
(
602604
v
603605
if v is None
@@ -606,9 +608,11 @@ def convert_to_assigned_datatypes_in_column_table(column_table, description):
606608
)
607609
)
608610
for v in col
609-
)
611+
))
612+
else:
613+
converted_column_table.append(col)
610614

611-
return column_table
615+
return converted_column_table
612616

613617

614618
def convert_column_based_set_to_arrow_table(columns, description):
@@ -624,7 +628,7 @@ def convert_column_based_set_to_arrow_table(columns, description):
624628

625629
def convert_column_based_set_to_column_table(columns, description):
626630
column_names = [c[0] for c in description]
627-
column_table = [_covert_column_to_list(c) for c in columns]
631+
column_table = [_convert_column_to_list(c) for c in columns]
628632

629633
return column_table, column_names
630634

@@ -653,8 +657,8 @@ def _convert_column_to_arrow_array(t_col):
653657
raise OperationalError("Empty TColumn instance {}".format(t_col))
654658

655659

656-
def _covert_column_to_list(t_col):
657-
supported_field_types = (
660+
def _convert_column_to_list(t_col):
661+
SUPPORTED_FIELD_TYPES = (
658662
"boolVal",
659663
"byteVal",
660664
"i16Val",
@@ -665,7 +669,7 @@ def _covert_column_to_list(t_col):
665669
"binaryVal",
666670
)
667671

668-
for field in supported_field_types:
672+
for field in SUPPORTED_FIELD_TYPES:
669673
wrapper = getattr(t_col, field)
670674
if wrapper:
671675
return _create_python_tuple(wrapper)

0 commit comments

Comments
 (0)