This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new f2b2aa2943 [python] Close full-text readers when search raises 
synchronously (#9997)
f2b2aa2943 is described below

commit f2b2aa29435d868546e3bb7ec36dd215f82671ea
Author: chaoyang <[email protected]>
AuthorDate: Sun Sep 20 16:16:15 2026 +0800

    [python] Close full-text readers when search raises synchronously (#9997)
---
 .../pypaimon/table/source/full_text_read.py        |  6 +-
 .../tests/full_text_reader_cleanup_test.py         | 64 ++++++++++++++++++++++
 2 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/paimon-python/pypaimon/table/source/full_text_read.py 
b/paimon-python/pypaimon/table/source/full_text_read.py
index e6ddbbcd52..cccd1a90e1 100644
--- a/paimon-python/pypaimon/table/source/full_text_read.py
+++ b/paimon-python/pypaimon/table/source/full_text_read.py
@@ -162,7 +162,11 @@ class DataEvolutionFullTextRead(FullTextRead):
             full_text_search = 
full_text_search.with_include_row_ids(include_row_ids)
 
         offset_reader = OffsetGlobalIndexReader(reader, row_range_start, 
row_range_end)
-        future = offset_reader.visit_full_text_search(full_text_search)
+        try:
+            future = offset_reader.visit_full_text_search(full_text_search)
+        except BaseException:
+            reader.close()
+            raise
         future.add_done_callback(lambda _: reader.close())
         return future
 
diff --git a/paimon-python/pypaimon/tests/full_text_reader_cleanup_test.py 
b/paimon-python/pypaimon/tests/full_text_reader_cleanup_test.py
new file mode 100644
index 0000000000..94d38c1c7d
--- /dev/null
+++ b/paimon-python/pypaimon/tests/full_text_reader_cleanup_test.py
@@ -0,0 +1,64 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from concurrent.futures import Future
+from unittest.mock import Mock, patch
+
+import pytest
+
+from pypaimon.globalindex.vector_search_result import 
DictBasedScoredIndexResult
+from pypaimon.table.source.full_text_read import DataEvolutionFullTextRead
+from pypaimon.tests.vector_search_filter_test import _StubTable, _entry, _field
+
+
[email protected]("mode", ["sync_error", "sync_interrupt", "completed", 
"pending", "failed"])
+def test_full_text_reader_lifetime(mode):
+    field = _field(0, "text", "STRING")
+    table = _StubTable([field], [])
+    entry = _entry(None, 0, "full-text", "index", 10, 19)
+    native = Mock()
+    future = Future()
+    failure = KeyboardInterrupt() if mode == "sync_interrupt" else 
ValueError("search failed")
+    if mode.startswith("sync_"):
+        native.visit_full_text_search.side_effect = failure
+    else:
+        native.visit_full_text_search.return_value = future
+        if mode == "completed":
+            future.set_result(DictBasedScoredIndexResult({1: 0.5}))
+
+    with 
patch("pypaimon.table.source.full_text_read._create_full_text_reader", 
return_value=native):
+        read = DataEvolutionFullTextRead(table, 1, field, "query")
+        if mode.startswith("sync_"):
+            with pytest.raises(type(failure)) as exc:
+                read._eval(10, 19, [entry.index_file], None)
+            assert exc.value is failure
+        else:
+            result = read._eval(10, 19, [entry.index_file], None)
+            if mode != "completed":
+                native.close.assert_not_called()
+                assert not result.done()
+                if mode == "failed":
+                    future.set_exception(failure)
+                else:
+                    future.set_result(DictBasedScoredIndexResult({1: 0.5}))
+            if mode == "failed":
+                with pytest.raises(ValueError) as exc:
+                    result.result()
+                assert exc.value is failure
+            else:
+                assert list(result.result().results()) == [11]
+    native.close.assert_called_once_with()

Reply via email to