You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "davlee1972 (via GitHub)" <gi...@apache.org> on 2024/10/31 15:53:03 UTC

Re: [I] [Python] Keeping cursors alive when using cursor.fetch_record_batch() [arrow-adbc]

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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org