@@ -20,6 +20,7 @@ package databricks
2020import (
2121 "bytes"
2222 "context"
23+ "database/sql/driver"
2324 "fmt"
2425 "io"
2526 "sync/atomic"
@@ -38,12 +39,13 @@ type rowsWithIPCStream interface {
3839
3940// ipcReaderAdapter uses the new IPC stream interface for Arrow access
4041type ipcReaderAdapter struct {
41- ipcIterator dbsqlrows.ArrowIPCStreamIterator
42- currentReader * ipc.Reader
43- currentRecord arrow.RecordBatch
44- schema * arrow.Schema
45- closed bool
46- refCount int64
42+ dbsqlRowsHandle dbsqlrows.Rows // Row from which we obtain the iterator - their lifetimes are tied together
43+ ipcIterator dbsqlrows.ArrowIPCStreamIterator
44+ currentReader * ipc.Reader
45+ currentRecord arrow.RecordBatch
46+ schema * arrow.Schema
47+ closed bool
48+ refCount int64
4749}
4850
4951// newIPCReaderAdapter creates a RecordReader using direct IPC stream access
@@ -86,9 +88,10 @@ func newIPCReaderAdapter(ctx context.Context, rows dbsqlrows.Rows) (array.Record
8688 }
8789
8890 adapter := & ipcReaderAdapter {
89- refCount : 1 ,
90- ipcIterator : ipcIterator ,
91- schema : schema ,
91+ refCount : 1 ,
92+ dbsqlRowsHandle : rows ,
93+ ipcIterator : ipcIterator ,
94+ schema : schema ,
9295 }
9396
9497 // Initialize the first reader
@@ -202,6 +205,11 @@ func (r *ipcReaderAdapter) Release() {
202205 }
203206
204207 r .ipcIterator .Close ()
208+
209+ if r .dbsqlRowsHandle != nil {
210+ r .dbsqlRowsHandle .(driver.Rows ).Close ()
211+ r .dbsqlRowsHandle = nil
212+ }
205213 }
206214}
207215
0 commit comments