Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python][StreamQueryResult] Fix memory ownership issues in StreamQueryResult::FetchRaw #9968

Merged
merged 2 commits into from Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/stream_query_result.cpp
Expand Up @@ -55,7 +55,12 @@ unique_ptr<DataChunk> StreamQueryResult::FetchRaw() {
{
auto lock = LockContext();
CheckExecutableInternal(*lock);
chunk = context->Fetch(*lock, *this);
auto system_chunk = context->Fetch(*lock, *this);
if (system_chunk) {
chunk = make_uniq<DataChunk>();
chunk->Initialize(Allocator::DefaultAllocator(), system_chunk->GetTypes());
system_chunk->Copy(*chunk, 0);
}
}
if (!chunk || chunk->ColumnCount() == 0 || chunk->size() == 0) {
Close();
Expand Down
20 changes: 20 additions & 0 deletions tools/pythonpkg/tests/fast/api/test_streaming_result.py
Expand Up @@ -61,3 +61,23 @@ def test_record_batch_reader(self):
result = []
for batch in reader:
result += batch.to_pydict()['i']

def test_9801(self, duckdb_cursor):
duckdb_cursor.execute('CREATE TABLE test(id INTEGER , name VARCHAR NOT NULL);')

words = ['aaaaaaaaaaaaaaaaaaaaaaa', 'bbbb', 'ccccccccc', 'ííííííííí']
lines = [(i, words[i % 4]) for i in range(1000)]
duckdb_cursor.executemany("INSERT INTO TEST (id, name) VALUES (?, ?)", lines)

rel1 = duckdb_cursor.sql(
"""
SELECT id, name FROM test ORDER BY id ASC
"""
)
result = rel1.fetchmany(size=5)
counter = 0
while result != []:
for x in result:
assert x == (counter, words[counter % 4])
counter += 1
result = rel1.fetchmany(size=5)