Skip to content

Commit d53d1ea

Browse files
reduce diff
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 387102d commit d53d1ea

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/databricks/sql/result_set.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class ResultSet(ABC):
3636

3737
def __init__(
3838
self,
39-
connection: "Connection",
40-
backend: "DatabricksClient",
39+
connection: Connection,
40+
backend: DatabricksClient,
4141
arraysize: int,
4242
buffer_size_bytes: int,
4343
command_id: CommandId,
@@ -54,8 +54,8 @@ def __init__(
5454
A ResultSet manages the results of a single command.
5555
5656
Parameters:
57-
:param connection: The parent connection
58-
:param backend: The backend client
57+
:param connection: The parent connection that was used to execute this command
58+
:param backend: The backend specialised backend client to be invoked in the fetch phase
5959
:param arraysize: The max number of rows to fetch at a time (PEP-249)
6060
:param buffer_size_bytes: The size (in bytes) of the internal buffer + max fetch
6161
:param command_id: The command ID
@@ -190,9 +190,9 @@ class ThriftResultSet(ResultSet):
190190

191191
def __init__(
192192
self,
193-
connection: "Connection",
194-
execute_response: "ExecuteResponse",
195-
thrift_client: "ThriftDatabricksClient",
193+
connection: Connection,
194+
execute_response: ExecuteResponse,
195+
thrift_client: ThriftDatabricksClient,
196196
session_id_hex: Optional[str],
197197
buffer_size_bytes: int = 104857600,
198198
arraysize: int = 10000,
@@ -319,6 +319,7 @@ def fetchmany_arrow(self, size: int) -> "pyarrow.Table":
319319
if size < 0:
320320
raise ValueError("size argument for fetchmany is %s but must be >= 0", size)
321321
results = self.results.next_n_rows(size)
322+
partial_result_chunks = [results]
322323
n_remaining_rows = size - results.num_rows
323324
self._next_row_index += results.num_rows
324325

@@ -329,11 +330,11 @@ def fetchmany_arrow(self, size: int) -> "pyarrow.Table":
329330
):
330331
self._fill_results_buffer()
331332
partial_results = self.results.next_n_rows(n_remaining_rows)
332-
results = pyarrow.concat_tables([results, partial_results])
333+
partial_result_chunks.append(partial_results)
333334
n_remaining_rows -= partial_results.num_rows
334335
self._next_row_index += partial_results.num_rows
335336

336-
return results
337+
return pyarrow.concat_tables(partial_result_chunks)
337338

338339
def fetchmany_columnar(self, size: int):
339340
"""
@@ -364,7 +365,7 @@ def fetchall_arrow(self) -> "pyarrow.Table":
364365
"""Fetch all (remaining) rows of a query result, returning them as a PyArrow table."""
365366
results = self.results.remaining_rows()
366367
self._next_row_index += results.num_rows
367-
368+
partial_result_chunks = [results]
368369
while not self.has_been_closed_server_side and self.is_direct_results:
369370
self._fill_results_buffer()
370371
partial_results = self.results.remaining_rows()
@@ -373,7 +374,7 @@ def fetchall_arrow(self) -> "pyarrow.Table":
373374
):
374375
results = self.merge_columnar(results, partial_results)
375376
else:
376-
results = pyarrow.concat_tables([results, partial_results])
377+
partial_result_chunks.append(partial_results)
377378
self._next_row_index += partial_results.num_rows
378379

379380
# If PyArrow is installed and we have a ColumnTable result, convert it to PyArrow Table
@@ -384,7 +385,7 @@ def fetchall_arrow(self) -> "pyarrow.Table":
384385
for name, col in zip(results.column_names, results.column_table)
385386
}
386387
return pyarrow.Table.from_pydict(data)
387-
return results
388+
return pyarrow.concat_tables(partial_result_chunks)
388389

389390
def fetchall_columnar(self):
390391
"""Fetch all (remaining) rows of a query result, returning them as a Columnar table."""

src/databricks/sql/session.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def session_id(self) -> SessionId:
150150
return self._session_id
151151

152152
@property
153-
def guid(self):
153+
def guid(self) -> Any:
154154
"""Get the raw session ID (backend-specific)"""
155155
return self._session_id.guid
156156

@@ -161,7 +161,7 @@ def guid_hex(self) -> str:
161161

162162
def close(self) -> None:
163163
"""Close the underlying session."""
164-
logger.info(f"Closing session {self.guid_hex}")
164+
logger.info("Closing session %s", self.guid_hex)
165165
if not self.is_open:
166166
logger.debug("Session appears to have been closed already")
167167
return
@@ -174,13 +174,13 @@ def close(self) -> None:
174174
except DatabaseError as e:
175175
if "Invalid SessionHandle" in str(e):
176176
logger.warning(
177-
f"Attempted to close session that was already closed: {e}"
177+
"Attempted to close session that was already closed: %s", e
178178
)
179179
else:
180180
logger.warning(
181-
f"Attempt to close session raised an exception at the server: {e}"
181+
"Attempt to close session raised an exception at the server: %s", e
182182
)
183183
except Exception as e:
184-
logger.error(f"Attempt to close session raised a local exception: {e}")
184+
logger.error("Attempt to close session raised a local exception: %s", e)
185185

186186
self.is_open = False

0 commit comments

Comments
 (0)