Skip to content

Commit 71cc3d4

Browse files
Correct issue with fetching data frames that contain multiple packets
with asyncio.
1 parent a43a812 commit 71cc3d4

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Common Changes
7474
- Fixed bug when fetching dates that are in the year 2038 or later.
7575
- Fixed bug when fetching numeric data with precision that exceeds 38 as
7676
decimal data.
77+
- Fixed bug when fetching large amounts of data in one round-trip when
78+
using asyncio with Oracle Database versions before 23ai.
7779

7880
Note the data frame support in python-oracledb 3.3 is a pre-release, and
7981
may change in a future version.

src/oracledb/impl/thin/messages/base.pyx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,13 @@ cdef class Message:
734734
buf.write_ub8(state | TNS_SESSION_STATE_EXPLICIT_BOUNDARY)
735735
self.conn_impl._session_state_desired = 0
736736

737+
cdef int on_out_of_packets(self) except -1:
738+
"""
739+
Called when an OufOfPackets exception is raised indicating that further
740+
packets are required to continue processing of this message.
741+
"""
742+
pass
743+
737744
cdef int postprocess(self) except -1:
738745
pass
739746

@@ -1307,6 +1314,7 @@ cdef class MessageWithData(Message):
13071314
self.cursor_impl._last_row_index = self.row_index - 1
13081315
self.cursor_impl._buffer_rowcount = self.row_index
13091316
self.bit_vector = NULL
1317+
self.on_row_completed()
13101318

13111319
cdef int _process_row_header(self, ReadBuffer buf) except -1:
13121320
cdef uint32_t num_bytes
@@ -1511,6 +1519,39 @@ cdef class MessageWithData(Message):
15111519
continue
15121520
self._write_bind_params_column(buf, var_impl, pos + offset)
15131521

1522+
cdef int on_out_of_packets(self) except -1:
1523+
"""
1524+
Called when an OufOfPackets exception is raised indicating that further
1525+
packets are required to continue processing of this message.
1526+
"""
1527+
cdef ThinVarImpl var_impl
1528+
1529+
# when fetching Arrow data, if the column has already been processed
1530+
# and no saved array already exists, the array is saved so that
1531+
# subsequent processing will not append to the array further; once the
1532+
# complete row has been processed, the saved arrays are restored and
1533+
# processing continues
1534+
if self.cursor_impl.fetching_arrow:
1535+
for var_impl in self.cursor_impl.fetch_var_impls:
1536+
if var_impl._saved_arrow_array is not None:
1537+
continue
1538+
elif var_impl._arrow_array.arrow_array.length > self.row_index:
1539+
var_impl._saved_arrow_array = var_impl._arrow_array
1540+
var_impl._arrow_array = None
1541+
var_impl._create_arrow_array()
1542+
1543+
cdef int on_row_completed(self) except -1:
1544+
"""
1545+
Called when a row has been successfully completed. This allows for any
1546+
saved Arrow arrays to be restored.
1547+
"""
1548+
cdef ThinVarImpl var_impl
1549+
if self.cursor_impl.fetching_arrow:
1550+
for var_impl in self.cursor_impl.fetch_var_impls:
1551+
if var_impl._saved_arrow_array is not None:
1552+
var_impl._arrow_array = var_impl._saved_arrow_array
1553+
var_impl._saved_arrow_array = None
1554+
15141555
cdef int postprocess(self) except -1:
15151556
"""
15161557
Run any variable out converter functions on all non-null values that

src/oracledb/impl/thin/protocol.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ cdef class BaseAsyncProtocol(BaseProtocol):
844844
break
845845
except OutOfPackets:
846846
await self._receive_packet(message)
847+
message.on_out_of_packets()
847848
self._read_buf.restore_point()
848849

849850
async def _process_single_message(self, Message message):

src/oracledb/impl/thin/var.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ cdef class ThinVarImpl(BaseVarImpl):
3333
cdef:
3434
object _last_raw_value
3535
ArrowArrayImpl _last_arrow_array
36+
ArrowArrayImpl _saved_arrow_array
3637
list _coroutine_indexes
3738

3839
cdef int _bind(self, object conn, BaseCursorImpl cursor_impl,

0 commit comments

Comments
 (0)