davlee1972 commented on issue #1893:
URL: https://github.com/apache/arrow-adbc/issues/1893#issuecomment-2450229258

   I ended up monkey patching AdbcReaderBatchReader to keep the cursor alive..
   
   from adbc_driver_manager._lib import ArrowArrayStreamHandle
   from adbc_driver_manager._reader import AdbcRecordBatchReader
   
   def _set_conn(self, conn, cursor):
       self.adbc_conn = conn
       self.adbc_cursor = cursor
   
   AdbcRecordBatchReader.adbc_conn = None
   AdbcRecordBatchReader.adbc_cursor = None
   AdbcRecordBatchReader.set_conn = _set_conn
   
   --------------
   Code which executes the sql and returns back a pyarrow.RecordBatchReader 
without closing the cursor..
   
                   cursor.execute(sql)
                   arrow_batch_reader = cursor.fetch_record_batch()
   
                   exported = ArrowArrayStreamHandle()
                   arrow_batch_reader._export_to_c(exported.address)
                   new_arrow_batch_reader = 
AdbcRecordBatchReader._import_from_c(exported.address)
                   new_arrow_batch_reader.set_conn(conn, cursor)
                   
                   return new_arrow_batch_reader


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to