This is an automated email from the ASF dual-hosted git repository.
lxy-9602 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new dfa4bc86 fix(global-index): exclude deleted rows from vector search
ranking (#502)
dfa4bc86 is described below
commit dfa4bc862f25806b69934d39b8f6e3f80fb74a59
Author: Nicholas Jiang <[email protected]>
AuthorDate: Thu Nov 5 09:51:46 2026 +0700
fix(global-index): exclude deleted rows from vector search ranking (#502)
---
docs/source/user_guide/global_index.rst | 10 +
.../global_index/global_index_live_row_filter.cpp | 7 +-
.../global_index/global_index_live_row_filter.h | 8 +-
.../core/global_index/global_index_scan_impl.cpp | 44 +++--
.../core/global_index/global_index_scan_impl.h | 12 +-
.../global_index/live_row_global_index_reader.cpp | 30 ++-
.../global_index/live_row_global_index_reader.h | 30 +--
.../live_row_global_index_reader_test.cpp | 78 ++++++++
.../table/source/data_evolution_full_text_read.cpp | 3 +-
src/paimon/testing/mock/mock_global_index_reader.h | 10 +
test/inte/data_evolution_table_test.cpp | 26 ++-
test/inte/global_index_test.cpp | 213 +++++++++++++++++++++
12 files changed, 424 insertions(+), 47 deletions(-)
diff --git a/docs/source/user_guide/global_index.rst
b/docs/source/user_guide/global_index.rst
index 5901e5c7..cafaabd5 100644
--- a/docs/source/user_guide/global_index.rst
+++ b/docs/source/user_guide/global_index.rst
@@ -422,3 +422,13 @@ Vector Index (Lumina)
An approximate nearest neighbor (ANN) index powered by Lumina for vector
similarity search.
It supports high-dimensional vector search with configurable distance metrics
and encoding strategies.
For more configurations, refer to the ``docs/reference`` directory in the
Lumina release package.
+
+When ``deletion-vectors.enabled`` and ``row-tracking.enabled`` are set,
readers created by
+``GlobalIndexScan`` search only the rows that are live in the snapshot the
scan reads, as Java
+Paimon does, so rows deleted by deletion vectors do not take ``limit`` slots.
The live rows are
+combined with the ``pre_filter`` of the ``VectorSearch``. In Data Evolution
tables, only the
+deletion vectors of the data files the index covers are read. As for full-text
search, pass one
+snapshot id to both the index scan and the data scan.
+
+A search across multiple index shards returns up to ``limit`` rows from each
shard, and the merged
+result is not truncated to ``limit``.
diff --git a/src/paimon/core/global_index/global_index_live_row_filter.cpp
b/src/paimon/core/global_index/global_index_live_row_filter.cpp
index 2c72e1b5..3d554fb1 100644
--- a/src/paimon/core/global_index/global_index_live_row_filter.cpp
+++ b/src/paimon/core/global_index/global_index_live_row_filter.cpp
@@ -167,8 +167,8 @@ Status SubtractDeletedRows(const DataSplitImpl& split,
const std::string& root_p
Result<std::optional<RoaringBitmap64>> GlobalIndexLiveRowFilter::LiveRows(
const std::string& root_path, const std::shared_ptr<TableSchema>&
table_schema,
const Snapshot& snapshot, const std::shared_ptr<PredicateFilter>&
partition_filter,
- const CoreOptions& options, const std::shared_ptr<Executor>& executor,
- const std::shared_ptr<MemoryPool>& pool) {
+ const std::optional<RowRangeIndex>& row_range_index, const CoreOptions&
options,
+ const std::shared_ptr<Executor>& executor, const
std::shared_ptr<MemoryPool>& pool) {
// Without row tracking, as in primary-key tables, data files carry no row
ids to filter.
if (!options.DeletionVectorsEnabled() || !options.RowTrackingEnabled()) {
return std::optional<RoaringBitmap64>();
@@ -177,6 +177,9 @@ Result<std::optional<RoaringBitmap64>>
GlobalIndexLiveRowFilter::LiveRows(
std::unique_ptr<SnapshotReader> snapshot_reader,
CreateSnapshotReader(root_path, table_schema, partition_filter,
options, executor, pool));
snapshot_reader->WithMode(ScanMode::ALL)->WithSnapshot(snapshot);
+ if (row_range_index) {
+ snapshot_reader->WithRowRangeIndex(row_range_index.value());
+ }
PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<Plan> plan,
snapshot_reader->Read());
std::vector<std::shared_ptr<DataSplitImpl>> splits;
diff --git a/src/paimon/core/global_index/global_index_live_row_filter.h
b/src/paimon/core/global_index/global_index_live_row_filter.h
index 4f607e69..13cd1586 100644
--- a/src/paimon/core/global_index/global_index_live_row_filter.h
+++ b/src/paimon/core/global_index/global_index_live_row_filter.h
@@ -31,6 +31,7 @@
#include "paimon/memory/memory_pool.h"
#include "paimon/result.h"
#include "paimon/utils/roaring_bitmap64.h"
+#include "paimon/utils/row_range_index.h"
namespace paimon {
/// Live-row filtering shared by global index search readers, aligned with Java
@@ -50,14 +51,17 @@ class GlobalIndexLiveRowFilter {
/// @param snapshot The snapshot to read; pin it to the one the
global index is
/// read from, so row ids and live rows agree.
/// @param partition_filter Predicate over the partition fields, or null
for all partitions.
+ /// @param row_range_index Global row ids the caller needs, or nullopt
for all rows. Data files
+ /// whose row ids miss them may be skipped, every
one of them in Data
+ /// Evolution tables, so live rows outside them
may be left out.
/// @param options Options of the table.
/// @param executor Executor for reading manifests.
/// @param pool Memory pool for reading manifests and deletion
vectors.
static Result<std::optional<RoaringBitmap64>> LiveRows(
const std::string& root_path, const std::shared_ptr<TableSchema>&
table_schema,
const Snapshot& snapshot, const std::shared_ptr<PredicateFilter>&
partition_filter,
- const CoreOptions& options, const std::shared_ptr<Executor>& executor,
- const std::shared_ptr<MemoryPool>& pool);
+ const std::optional<RowRangeIndex>& row_range_index, const
CoreOptions& options,
+ const std::shared_ptr<Executor>& executor, const
std::shared_ptr<MemoryPool>& pool);
};
} // namespace paimon
diff --git a/src/paimon/core/global_index/global_index_scan_impl.cpp
b/src/paimon/core/global_index/global_index_scan_impl.cpp
index e7ae8cfe..38c5ce9b 100644
--- a/src/paimon/core/global_index/global_index_scan_impl.cpp
+++ b/src/paimon/core/global_index/global_index_scan_impl.cpp
@@ -39,18 +39,19 @@
#include "paimon/global_index/global_indexer_factory.h"
namespace paimon {
-GlobalIndexScanImpl::GlobalIndexScanImpl(
- const std::shared_ptr<TableSchema>& table_schema, const CoreOptions&
options,
- const std::shared_ptr<IndexPathFactory>& path_factory, IndexMetaMap&&
index_metas,
- LiveRowGlobalIndexReader::LiveRowsSupplier live_rows_supplier,
- const std::shared_ptr<Executor>& executor, const
std::shared_ptr<MemoryPool>& pool)
+GlobalIndexScanImpl::GlobalIndexScanImpl(const std::shared_ptr<TableSchema>&
table_schema,
+ const CoreOptions& options,
+ const
std::shared_ptr<IndexPathFactory>& path_factory,
+ IndexMetaMap&& index_metas,
LiveRowsLoader load_live_rows,
+ const std::shared_ptr<Executor>&
executor,
+ const std::shared_ptr<MemoryPool>&
pool)
: pool_(pool),
table_schema_(table_schema),
options_(options),
index_file_manager_(std::make_shared<GlobalIndexFileManager>(
options.GetFileSystem(), path_factory,
/*checkpoint_path_factory=*/nullptr)),
index_metas_(std::move(index_metas)),
- live_rows_supplier_(std::move(live_rows_supplier)),
+ load_live_rows_(std::move(load_live_rows)),
executor_(executor) {}
Result<std::shared_ptr<Executor>> GlobalIndexScanImpl::GetOrCreateExecutor(
@@ -132,18 +133,19 @@ Result<std::unique_ptr<GlobalIndexScanImpl>>
GlobalIndexScanImpl::Create(
index_metas[index_meta->index_field_id][index_file_meta->IndexType()][range].push_back(
index_file_meta);
}
- // Full-text searches rank only the rows live in the snapshot the index is
read from.
- LiveRowGlobalIndexReader::LiveRowsSupplier live_rows_supplier;
+ // Full-text and vector searches rank only the rows live in the snapshot
the index is read from.
+ LiveRowsLoader load_live_rows;
if (options.DeletionVectorsEnabled()) {
- live_rows_supplier = LiveRowGlobalIndexReader::CacheLiveRows(
- [root_path, table_schema, snapshot, partitions, options,
final_executor, pool]() {
- return GlobalIndexLiveRowFilter::LiveRows(
- root_path, table_schema, snapshot, partitions, options,
final_executor, pool);
- });
+ load_live_rows = [root_path, table_schema, snapshot, partitions,
options, final_executor,
+ pool](const RowRangeIndex& row_range_index) {
+ return GlobalIndexLiveRowFilter::LiveRows(root_path, table_schema,
snapshot, partitions,
+ row_range_index,
options, final_executor,
+ pool);
+ };
}
return std::unique_ptr<GlobalIndexScanImpl>(
new GlobalIndexScanImpl(table_schema, options, path_factory,
std::move(index_metas),
- std::move(live_rows_supplier), final_executor,
pool));
+ std::move(load_live_rows), final_executor,
pool));
}
Result<std::shared_ptr<GlobalIndexEvaluator>>
GlobalIndexScanImpl::GetOrCreateIndexEvaluator() {
@@ -255,10 +257,20 @@ Result<std::vector<std::shared_ptr<GlobalIndexReader>>>
GlobalIndexScanImpl::Cre
if (union_readers.empty()) {
continue;
}
- if (live_rows_supplier_) {
+ if (load_live_rows_) {
+ // As Java `AbstractDataEvolutionVectorRead#preFilters` does, load
only the live rows of
+ // the indexed row ranges, so Data Evolution tables skip the
deletion vectors of other
+ // data files.
+ PAIMON_ASSIGN_OR_RAISE(RowRangeIndex indexed_row_ranges,
+ RowRangeIndex::Create(row_ranges));
+ LiveRowGlobalIndexReader::LiveRowsSupplier live_rows_supplier =
+ LiveRowGlobalIndexReader::CacheLiveRows(
+ [load_live_rows = load_live_rows_, indexed_row_ranges]() {
+ return load_live_rows(indexed_row_ranges);
+ });
readers.push_back(LiveRowGlobalIndexReader::CreateUnion(
std::move(union_readers), std::move(row_ranges),
std::move(search_ranges),
- executor_, live_rows_supplier_));
+ executor_, live_rows_supplier));
} else {
readers.push_back(std::make_shared<UnionGlobalIndexReader>(
std::move(union_readers), std::move(row_ranges),
std::move(search_ranges),
diff --git a/src/paimon/core/global_index/global_index_scan_impl.h
b/src/paimon/core/global_index/global_index_scan_impl.h
index 364228b5..26af31df 100644
--- a/src/paimon/core/global_index/global_index_scan_impl.h
+++ b/src/paimon/core/global_index/global_index_scan_impl.h
@@ -19,6 +19,7 @@
#pragma once
+#include <functional>
#include <map>
#include <memory>
#include <optional>
@@ -69,12 +70,15 @@ class GlobalIndexScanImpl : public GlobalIndexScan {
using IndexMetaMap =
std::map<int32_t, std::map<std::string,
std::map<Range,
std::vector<std::shared_ptr<IndexFileMeta>>>>>;
+ /// Loads the rows live in the scanned snapshot among the data files whose
row ids intersect the
+ /// given row ranges.
+ using LiveRowsLoader =
+ std::function<Result<std::optional<RoaringBitmap64>>(const
RowRangeIndex&)>;
GlobalIndexScanImpl(const std::shared_ptr<TableSchema>& table_schema,
const CoreOptions& options,
const std::shared_ptr<IndexPathFactory>& path_factory,
- IndexMetaMap&& index_metas,
- LiveRowGlobalIndexReader::LiveRowsSupplier
live_rows_supplier,
+ IndexMetaMap&& index_metas, LiveRowsLoader
load_live_rows,
const std::shared_ptr<Executor>& executor,
const std::shared_ptr<MemoryPool>& pool);
@@ -96,8 +100,8 @@ class GlobalIndexScanImpl : public GlobalIndexScan {
CoreOptions options_;
std::shared_ptr<GlobalIndexFileManager> index_file_manager_;
IndexMetaMap index_metas_;
- /// Supplies the rows live in the scanned snapshot; empty when deletion
vectors are disabled.
- LiveRowGlobalIndexReader::LiveRowsSupplier live_rows_supplier_;
+ /// Loads the rows live in the scanned snapshot; empty when deletion
vectors are disabled.
+ LiveRowsLoader load_live_rows_;
std::shared_ptr<Executor> executor_;
std::shared_ptr<GlobalIndexEvaluator> evaluator_;
};
diff --git a/src/paimon/core/global_index/live_row_global_index_reader.cpp
b/src/paimon/core/global_index/live_row_global_index_reader.cpp
index 9bdf1449..38c7d951 100644
--- a/src/paimon/core/global_index/live_row_global_index_reader.cpp
+++ b/src/paimon/core/global_index/live_row_global_index_reader.cpp
@@ -24,6 +24,7 @@
#include <mutex>
#include <utility>
+#include "paimon/common/global_index/global_index_utils.h"
#include "paimon/common/global_index/union_global_index_reader.h"
namespace paimon {
@@ -40,7 +41,7 @@ bool MayRankRowsOf(const FullTextSearch& full_text_search,
const Range& range) {
}
/// A union of LiveRowGlobalIndexReaders that loads the live rows on the
visiting thread before a
-/// full-text search fans out to them.
+/// full-text or vector search fans out to them.
class LiveRowUnionGlobalIndexReader : public UnionGlobalIndexReader {
public:
/// @param ranked_ranges The global row ids the shards rank in a full-text
search, leaving out
@@ -69,6 +70,15 @@ class LiveRowUnionGlobalIndexReader : public
UnionGlobalIndexReader {
return UnionGlobalIndexReader::VisitFullTextSearch(full_text_search);
}
+ Result<std::shared_ptr<ScoredGlobalIndexResult>> VisitVectorSearch(
+ const std::shared_ptr<VectorSearch>& vector_search) override {
+ // The union passes a vector search to every shard.
+ if (vector_search) {
+ PAIMON_RETURN_NOT_OK(live_rows_supplier_());
+ }
+ return UnionGlobalIndexReader::VisitVectorSearch(vector_search);
+ }
+
private:
std::vector<Range> ranked_ranges_;
LiveRowGlobalIndexReader::LiveRowsSupplier live_rows_supplier_;
@@ -197,7 +207,23 @@ Result<std::shared_ptr<GlobalIndexResult>>
LiveRowGlobalIndexReader::VisitLike(
Result<std::shared_ptr<ScoredGlobalIndexResult>>
LiveRowGlobalIndexReader::VisitVectorSearch(
const std::shared_ptr<VectorSearch>& vector_search) {
- return wrapped_->VisitVectorSearch(vector_search);
+ if (!vector_search) {
+ return wrapped_->VisitVectorSearch(vector_search);
+ }
+ PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<const RoaringBitmap64> live_rows,
live_rows_supplier_());
+ if (!live_rows) {
+ return wrapped_->VisitVectorSearch(vector_search);
+ }
+ RoaringBitmap64 shard_live_rows = GlobalIndexUtils::RowIdsOf(shard_range_);
+ shard_live_rows &= *live_rows;
+ if (shard_live_rows.Cardinality() == shard_range_.Count()) {
+ return wrapped_->VisitVectorSearch(vector_search);
+ }
+ return wrapped_->VisitVectorSearch(vector_search->ReplacePreFilter(
+ [shard_live_rows = std::make_shared<const
RoaringBitmap64>(std::move(shard_live_rows)),
+ pre_filter = vector_search->pre_filter](int64_t row_id) {
+ return shard_live_rows->Contains(row_id) && (!pre_filter ||
pre_filter(row_id));
+ }));
}
Result<std::shared_ptr<ScoredGlobalIndexResult>>
LiveRowGlobalIndexReader::VisitFullTextSearch(
diff --git a/src/paimon/core/global_index/live_row_global_index_reader.h
b/src/paimon/core/global_index/live_row_global_index_reader.h
index 4e2589c7..72fb5dc4 100644
--- a/src/paimon/core/global_index/live_row_global_index_reader.h
+++ b/src/paimon/core/global_index/live_row_global_index_reader.h
@@ -32,12 +32,13 @@
namespace paimon {
-/// A GlobalIndexReader over one index shard that ranks only live rows in
full-text searches, so
-/// rows deleted by deletion vectors do not take top-k slots. As Java
-/// `DataEvolutionFullTextRead#includeRowIds` does, the shard is searched with
the live rows of its
-/// range, intersected with the include row ids if given, while BM25
statistics still come from the
-/// whole index. Predicate visits are delegated unchanged, as the read drops
deleted rows from their
-/// untruncated results, and so are vector searches.
+/// A GlobalIndexReader over one index shard that ranks only live rows in
full-text and vector
+/// searches, so rows deleted by deletion vectors do not take top-k slots. As
Java
+/// `DataEvolutionFullTextRead#includeRowIds` does, a full-text search ranks
the live rows of the
+/// shard range, intersected with the include row ids if given, while BM25
statistics still come
+/// from the whole index. As Java `AbstractDataEvolutionVectorRead#preFilters`
does, a vector search
+/// restricts its pre-filter to those live rows. Predicate visits are
delegated unchanged, as the
+/// read drops deleted rows from their untruncated results.
class LiveRowGlobalIndexReader : public GlobalIndexReader {
public:
/// Supplies the global row ids of live rows, or null when every row is
live.
@@ -48,18 +49,19 @@ class LiveRowGlobalIndexReader : public GlobalIndexReader {
static LiveRowsSupplier CacheLiveRows(
std::function<Result<std::optional<RoaringBitmap64>>()> load);
- /// Creates a union of the shard readers of one index whose full-text
searches rank only live
- /// rows. Each shard reader is wrapped in a LiveRowGlobalIndexReader. When
a search may rank
- /// rows of a shard, live rows are loaded on the visiting thread before it
fans out to the
- /// shards, so a load that reads manifests on `executor` never waits for
it from one of its own
- /// threads.
+ /// Creates a union of the shard readers of one index whose full-text and
vector searches rank
+ /// only live rows. Each shard reader is wrapped in a
LiveRowGlobalIndexReader. When a search
+ /// may rank rows of a shard, live rows are loaded on the visiting thread
before it fans out to
+ /// the shards, so a load that reads manifests on `executor` never waits
for it from one of its
+ /// own threads.
/// @param shard_readers Readers of the shards. They take and return
global row ids.
/// @param shard_ranges The global row id range (both ends
inclusive) of each shard.
/// @param search_ranges The global row ids each shard ranks in a
full-text search, as
/// passed to UnionGlobalIndexReader.
/// @param executor Executor to search the shards in parallel,
or null to search
/// them one after another.
- /// @param live_rows_supplier Supplies the live rows to full-text searches.
+ /// @param live_rows_supplier Supplies the live rows to full-text and
vector searches. Only
+ /// those within `shard_ranges` are used.
static std::shared_ptr<GlobalIndexReader> CreateUnion(
std::vector<std::shared_ptr<GlobalIndexReader>>&& shard_readers,
std::vector<Range>&& shard_ranges, std::vector<std::optional<Range>>&&
search_ranges,
@@ -68,7 +70,7 @@ class LiveRowGlobalIndexReader : public GlobalIndexReader {
/// Constructs a LiveRowGlobalIndexReader.
/// @param wrapped The reader of the shard. It takes and
returns global row ids.
/// @param shard_range The global row id range (both ends
inclusive) of the shard.
- /// @param live_rows_supplier Supplies the live rows to full-text searches.
+ /// @param live_rows_supplier Supplies the live rows to full-text and
vector searches.
LiveRowGlobalIndexReader(std::shared_ptr<GlobalIndexReader>&& wrapped,
const Range& shard_range,
LiveRowsSupplier live_rows_supplier);
@@ -89,6 +91,8 @@ class LiveRowGlobalIndexReader : public GlobalIndexReader {
Result<std::shared_ptr<GlobalIndexResult>> VisitContains(const Literal&
literal) override;
Result<std::shared_ptr<GlobalIndexResult>> VisitLike(const Literal&
literal) override;
+ /// Searches only the live rows of the shard that pass the pre-filter, if
given. The search is
+ /// delegated unchanged when the whole shard is live.
Result<std::shared_ptr<ScoredGlobalIndexResult>> VisitVectorSearch(
const std::shared_ptr<VectorSearch>& vector_search) override;
diff --git a/src/paimon/core/global_index/live_row_global_index_reader_test.cpp
b/src/paimon/core/global_index/live_row_global_index_reader_test.cpp
index bc727394..53ec5b23 100644
--- a/src/paimon/core/global_index/live_row_global_index_reader_test.cpp
+++ b/src/paimon/core/global_index/live_row_global_index_reader_test.cpp
@@ -20,16 +20,21 @@
#include "paimon/core/global_index/live_row_global_index_reader.h"
#include <cstdint>
+#include <map>
#include <memory>
#include <mutex>
#include <optional>
+#include <string>
#include <thread>
+#include <utility>
#include <vector>
#include "gtest/gtest.h"
#include "paimon/executor.h"
#include "paimon/predicate/full_text_search.h"
#include "paimon/predicate/literal.h"
+#include "paimon/predicate/predicate_builder.h"
+#include "paimon/predicate/vector_search.h"
#include "paimon/testing/mock/mock_global_index_reader.h"
#include "paimon/testing/utils/testharness.h"
#include "paimon/utils/range.h"
@@ -62,6 +67,27 @@ class LiveRowGlobalIndexReaderTest : public ::testing::Test {
return std::make_shared<FullTextSearch>("f0",
R"({"match":{"query":"apple"}})",
/*limit=*/3, include_row_ids);
}
+
+ static std::shared_ptr<VectorSearch> SearchVector(
+ VectorSearch::PreFilter pre_filter = nullptr) {
+ return std::make_shared<VectorSearch>(
+ "f1", /*limit=*/3, std::vector<float>({1.0f, 2.0f}),
std::move(pre_filter),
+ PredicateBuilder::Equal(/*field_index=*/0, /*field_name=*/"f0",
FieldType::INT,
+ Literal(1)),
+ VectorSearch::DistanceType::COSINE,
+ std::map<std::string, std::string>({{"search.parallel", "2"}}));
+ }
+
+ static std::vector<int64_t> RowsPassingPreFilter(const VectorSearch&
vector_search,
+ const
std::vector<int64_t>& row_ids) {
+ std::vector<int64_t> passed;
+ for (int64_t row_id : row_ids) {
+ if (vector_search.pre_filter(row_id)) {
+ passed.push_back(row_id);
+ }
+ }
+ return passed;
+ }
};
TEST_F(LiveRowGlobalIndexReaderTest, TestSearchUnchangedWhenEveryRowIsLive) {
@@ -75,6 +101,20 @@ TEST_F(LiveRowGlobalIndexReaderTest,
TestSearchUnchangedWhenEveryRowIsLive) {
ASSERT_EQ(mock_reader->CapturedFullTextSearch(), search);
ASSERT_EQ(result->ToString(), "row ids: {11,12}, scores: {0.50,0.90}");
ASSERT_EQ(call_count, 1);
+
+ std::shared_ptr<VectorSearch> vector_search = SearchVector();
+ ASSERT_OK_AND_ASSIGN(result, reader.VisitVectorSearch(vector_search));
+ ASSERT_EQ(mock_reader->CapturedVectorSearch(), vector_search);
+ ASSERT_EQ(result->ToString(), "row ids: {11,12}, scores: {0.50,0.90}");
+ ASSERT_EQ(call_count, 2);
+
+ LiveRowGlobalIndexReader live_shard_reader(mock_reader, Range(10, 14),
+ Supply(LiveRows(0, 20, {9,
15}), &call_count));
+ ASSERT_OK(live_shard_reader.VisitFullTextSearch(search));
+ ASSERT_EQ(mock_reader->CapturedFullTextSearch(), search);
+ ASSERT_OK(live_shard_reader.VisitVectorSearch(vector_search));
+ ASSERT_EQ(mock_reader->CapturedVectorSearch(), vector_search);
+ ASSERT_EQ(call_count, 4);
}
TEST_F(LiveRowGlobalIndexReaderTest, TestSearchOnlyLiveRowsOfShard) {
@@ -94,6 +134,26 @@ TEST_F(LiveRowGlobalIndexReaderTest,
TestSearchOnlyLiveRowsOfShard) {
ASSERT_TRUE(captured->include_row_ids);
ASSERT_EQ(captured->include_row_ids.value(), RoaringBitmap64::From({10,
11, 13, 14}));
+ std::shared_ptr<VectorSearch> vector_search = SearchVector();
+ ASSERT_OK_AND_ASSIGN(result, reader.VisitVectorSearch(vector_search));
+ ASSERT_EQ(result->ToString(), "row ids: {11,13}, scores: {0.90,0.50}");
+ std::shared_ptr<VectorSearch> captured_vector =
mock_reader->CapturedVectorSearch();
+ ASSERT_TRUE(captured_vector && captured_vector->pre_filter);
+ ASSERT_EQ(captured_vector->field_name, vector_search->field_name);
+ ASSERT_EQ(captured_vector->limit, vector_search->limit);
+ ASSERT_EQ(captured_vector->query, vector_search->query);
+ ASSERT_EQ(captured_vector->predicate, vector_search->predicate);
+ ASSERT_TRUE(captured_vector->distance_type ==
vector_search->distance_type);
+ ASSERT_EQ(captured_vector->options, vector_search->options);
+ std::vector<int64_t> row_ids = {1, 9, 10, 11, 12, 13, 14, 15};
+ ASSERT_EQ(RowsPassingPreFilter(*captured_vector, row_ids),
+ std::vector<int64_t>({10, 11, 13, 14}));
+
+ ASSERT_OK(reader.VisitVectorSearch(SearchVector([](int64_t row_id) {
return row_id != 13; })));
+ captured_vector = mock_reader->CapturedVectorSearch();
+ ASSERT_TRUE(captured_vector && captured_vector->pre_filter);
+ ASSERT_EQ(RowsPassingPreFilter(*captured_vector, row_ids),
std::vector<int64_t>({10, 11, 14}));
+
constexpr int64_t kMax = RoaringBitmap64::MAX_VALUE;
LiveRowGlobalIndexReader max_reader(mock_reader, Range(kMax - 1, kMax),
Supply(RoaringBitmap64::From({kMax}),
&call_count));
@@ -101,6 +161,11 @@ TEST_F(LiveRowGlobalIndexReaderTest,
TestSearchOnlyLiveRowsOfShard) {
captured = mock_reader->CapturedFullTextSearch();
ASSERT_TRUE(captured && captured->include_row_ids);
ASSERT_EQ(captured->include_row_ids.value(),
RoaringBitmap64::From({kMax}));
+ ASSERT_OK(max_reader.VisitVectorSearch(SearchVector()));
+ captured_vector = mock_reader->CapturedVectorSearch();
+ ASSERT_TRUE(captured_vector && captured_vector->pre_filter);
+ ASSERT_EQ(RowsPassingPreFilter(*captured_vector, {kMax - 1, kMax}),
+ std::vector<int64_t>({kMax}));
}
TEST_F(LiveRowGlobalIndexReaderTest, TestIncludeRowIdsClippedToShard) {
@@ -153,6 +218,16 @@ TEST_F(LiveRowGlobalIndexReaderTest,
TestCreateUnionLoadsLiveRowsBeforeSearching
ASSERT_TRUE(first_search->include_row_ids->IsEmpty());
ASSERT_EQ(second_shard->CapturedFullTextSearch(), search);
ASSERT_EQ(result->ToString(), "row ids: {4294967296}, scores: {0.50}");
+
+ loading_thread.reset();
+ std::shared_ptr<VectorSearch> vector_search = SearchVector();
+ ASSERT_OK_AND_ASSIGN(result, reader->VisitVectorSearch(vector_search));
+ ASSERT_TRUE(loading_thread == std::this_thread::get_id());
+ std::shared_ptr<VectorSearch> first_vector_search =
first_shard->CapturedVectorSearch();
+ ASSERT_TRUE(first_vector_search && first_vector_search->pre_filter);
+ ASSERT_TRUE(RowsPassingPreFilter(*first_vector_search, {0, 1}).empty());
+ ASSERT_EQ(second_shard->CapturedVectorSearch(), vector_search);
+ ASSERT_EQ(result->ToString(), "row ids: {4294967296}, scores: {0.50}");
}
TEST_F(LiveRowGlobalIndexReaderTest,
TestCreateUnionRanksLiveRowsOfSearchRanges) {
@@ -217,12 +292,15 @@ TEST_F(LiveRowGlobalIndexReaderTest,
TestLiveRowsErrorOnlyFailsSearchesThatRankR
};
LiveRowGlobalIndexReader reader(mock_reader, Range(0, 9),
failing_supplier);
ASSERT_NOK_WITH_MSG(reader.VisitFullTextSearch(Search()), "cannot read
deletion vector");
+ ASSERT_NOK_WITH_MSG(reader.VisitVectorSearch(SearchVector()), "cannot read
deletion vector");
ASSERT_EQ(mock_reader->InvocationCount(), 0);
std::shared_ptr<GlobalIndexReader> union_reader =
LiveRowGlobalIndexReader::CreateUnion(
std::vector<std::shared_ptr<GlobalIndexReader>>({mock_reader}),
{Range(0, 9)},
{Range(5, 9)}, /*executor=*/nullptr, failing_supplier);
ASSERT_NOK_WITH_MSG(union_reader->VisitFullTextSearch(Search()), "cannot
read deletion vector");
+ ASSERT_NOK_WITH_MSG(union_reader->VisitVectorSearch(SearchVector()),
+ "cannot read deletion vector");
ASSERT_NOK_WITH_MSG(union_reader->VisitFullTextSearch(std::make_shared<FullTextSearch>(
"f0", R"({"match":{"query":"apple"}})",
/*limit=*/0)),
"full-text search requires a positive limit");
diff --git a/src/paimon/core/table/source/data_evolution_full_text_read.cpp
b/src/paimon/core/table/source/data_evolution_full_text_read.cpp
index e73f4c42..9183441c 100644
--- a/src/paimon/core/table/source/data_evolution_full_text_read.cpp
+++ b/src/paimon/core/table/source/data_evolution_full_text_read.cpp
@@ -187,7 +187,8 @@ Result<std::optional<RoaringBitmap64>>
DataEvolutionFullTextRead::LiveRows(
PAIMON_ASSIGN_OR_RAISE(Snapshot snapshot,
LoadPlannedSnapshot(options_, root_path_,
snapshot_id));
return GlobalIndexLiveRowFilter::LiveRows(root_path_, table_schema_,
snapshot,
- partition_filter_, options_,
executor_, pool_);
+ partition_filter_,
/*row_range_index=*/std::nullopt,
+ options_, executor_, pool_);
}
Result<std::shared_ptr<ScoredGlobalIndexResult>>
DataEvolutionFullTextRead::SearchSplit(
diff --git a/src/paimon/testing/mock/mock_global_index_reader.h
b/src/paimon/testing/mock/mock_global_index_reader.h
index c5bd3bef..9dd9ffc3 100644
--- a/src/paimon/testing/mock/mock_global_index_reader.h
+++ b/src/paimon/testing/mock/mock_global_index_reader.h
@@ -144,6 +144,10 @@ class MockGlobalIndexReader : public GlobalIndexReader {
Result<std::shared_ptr<ScoredGlobalIndexResult>> VisitVectorSearch(
const std::shared_ptr<VectorSearch>& vector_search) override {
+ {
+ std::lock_guard<std::mutex> lock(captured_search_mutex_);
+ captured_vector_search_ = vector_search;
+ }
return MakeScoredResult();
}
@@ -163,6 +167,11 @@ class MockGlobalIndexReader : public GlobalIndexReader {
return captured_full_text_search_;
}
+ std::shared_ptr<VectorSearch> CapturedVectorSearch() const {
+ std::lock_guard<std::mutex> lock(captured_search_mutex_);
+ return captured_vector_search_;
+ }
+
bool IsThreadSafe() const override {
return thread_safe_;
}
@@ -209,6 +218,7 @@ class MockGlobalIndexReader : public GlobalIndexReader {
bool supports_search_;
mutable std::mutex captured_search_mutex_;
std::shared_ptr<FullTextSearch> captured_full_text_search_;
+ std::shared_ptr<VectorSearch> captured_vector_search_;
std::vector<int64_t> default_result_;
bool return_nullptr_ = false;
bool return_error_ = false;
diff --git a/test/inte/data_evolution_table_test.cpp
b/test/inte/data_evolution_table_test.cpp
index 475ae9a6..79e16a6f 100644
--- a/test/inte/data_evolution_table_test.cpp
+++ b/test/inte/data_evolution_table_test.cpp
@@ -57,6 +57,7 @@
#include "paimon/testing/utils/io_exception_helper.h"
#include "paimon/testing/utils/test_helper.h"
#include "paimon/testing/utils/testharness.h"
+#include "paimon/utils/row_range_index.h"
namespace paimon::test {
using DataEvolutionTableParam = std::tuple<std::string, bool, bool>;
@@ -3553,32 +3554,43 @@ TEST_P(DataEvolutionDvTableTest,
TestGlobalIndexLiveRows) {
std::shared_ptr<Executor> executor = CreateDefaultExecutor();
auto read_live_rows = [&](const Snapshot& read_snapshot,
- const std::shared_ptr<PredicateFilter>&
partition_filter) {
+ const std::shared_ptr<PredicateFilter>&
partition_filter,
+ const std::optional<RowRangeIndex>&
row_range_index) {
return GlobalIndexLiveRowFilter::LiveRows(table_path,
table_schema.value(), read_snapshot,
- partition_filter, options,
executor,
- GetDefaultPool());
+ partition_filter,
row_range_index, options,
+ executor, GetDefaultPool());
};
ASSERT_OK_AND_ASSIGN(std::optional<RoaringBitmap64> live_rows,
- read_live_rows(snapshot.value(),
/*partition_filter=*/nullptr));
+ read_live_rows(snapshot.value(),
/*partition_filter=*/nullptr,
+ /*row_range_index=*/std::nullopt));
ASSERT_TRUE(live_rows);
ASSERT_EQ(live_rows.value(), RoaringBitmap64::From({0, 2, 5, 6, 7}));
+ ASSERT_OK_AND_ASSIGN(RowRangeIndex p1_row_ranges,
RowRangeIndex::Create({Range(4, 5)}));
+ ASSERT_OK_AND_ASSIGN(
+ live_rows, read_live_rows(snapshot.value(),
/*partition_filter=*/nullptr, p1_row_ranges));
+ ASSERT_TRUE(live_rows);
+ ASSERT_EQ(live_rows.value(), RoaringBitmap64::From({5, 6, 7}));
+
auto arrow_schema =
DataField::ConvertDataFieldsToArrowSchema(table_schema.value()->Fields());
ASSERT_OK_AND_ASSIGN(std::shared_ptr<PredicateFilter> p0_filter,
FileStoreScan::CreatePartitionPredicate(
table_schema.value()->PartitionKeys(),
options.GetPartitionDefaultName(), arrow_schema,
{{{"f1", "p0"}}}));
- ASSERT_OK_AND_ASSIGN(live_rows, read_live_rows(snapshot.value(),
p0_filter));
+ ASSERT_OK_AND_ASSIGN(live_rows, read_live_rows(snapshot.value(), p0_filter,
+
/*row_range_index=*/std::nullopt));
ASSERT_TRUE(live_rows);
ASSERT_EQ(live_rows.value(), RoaringBitmap64::From({0, 2}));
ASSERT_OK_AND_ASSIGN(live_rows,
read_live_rows(snapshot_before_deletion.value(),
-
/*partition_filter=*/nullptr));
+
/*partition_filter=*/nullptr,
+
/*row_range_index=*/std::nullopt));
ASSERT_TRUE(live_rows);
ASSERT_EQ(live_rows.value(), RoaringBitmap64::From({0, 1, 2, 3, 4, 5, 6,
7}));
ASSERT_OK(fs->Delete(PathUtil::JoinPath(table_path, "index")));
- ASSERT_NOK_WITH_MSG(read_live_rows(snapshot.value(),
/*partition_filter=*/nullptr),
+ ASSERT_NOK_WITH_MSG(read_live_rows(snapshot.value(),
/*partition_filter=*/nullptr,
+ /*row_range_index=*/std::nullopt),
"failed to read deletion vector of data file");
}
diff --git a/test/inte/global_index_test.cpp b/test/inte/global_index_test.cpp
index b92b44bf..3c24f83f 100644
--- a/test/inte/global_index_test.cpp
+++ b/test/inte/global_index_test.cpp
@@ -3044,6 +3044,219 @@ TEST_P(GlobalIndexTest, TestScanIndexWithTwoIndexes) {
ASSERT_OK_AND_ASSIGN(index_readers, global_index_scan->CreateReaders("f2",
std::nullopt));
ASSERT_EQ(index_readers.size(), 0);
}
+
+TEST_P(GlobalIndexTest, TestLuminaSearchSkipsRowsDeletedByDeletionVectors) {
+ arrow::FieldVector fields = {arrow::field("f0", arrow::int32()),
+ arrow::field("f1",
arrow::list(arrow::float32()))};
+ std::map<std::string, std::string> lumina_options = {
+ {"lumina.index.dimension", "4"},
+ {"lumina.index.type", "bruteforce"},
+ {"lumina.distance.metric", "l2"},
+ {"lumina.encoding.type", "rawf32"},
+ {"lumina.search.parallel_number", "10"},
+ {"lumina.extension.build.tag.tag_schema",
+ R"([{"key_name":"f0","type":"enum","value_type":"int32"}])"}};
+ auto schema = arrow::schema(fields);
+ std::map<std::string, std::string> options = {{Options::FILE_FORMAT,
file_format_},
+ {Options::FILE_SYSTEM,
"local"},
+
{Options::ROW_TRACKING_ENABLED, "true"},
+
{Options::DATA_EVOLUTION_ENABLED, "true"},
+
{Options::DELETION_VECTORS_ENABLED, "true"}};
+ CreateTable(/*partition_keys=*/{}, schema, options);
+ std::string table_path = PathUtil::JoinPath(dir_->Str(), "foo.db/bar");
+
+ auto src_array1 =
arrow::ipc::internal::json::ArrayFromJSON(arrow::struct_(fields), R"([
+[0, [0.0, 0.0, 0.0, 0.0]],
+[1, [1.0, 1.0, 1.0, 1.0]],
+[2, [2.0, 2.0, 2.0, 2.0]],
+[3, [3.0, 3.0, 3.0, 3.0]],
+[4, [4.0, 4.0, 4.0, 4.0]],
+[5, [5.0, 5.0, 5.0, 5.0]]
+ ])")
+ .ValueOrDie();
+ auto src_array2 =
arrow::ipc::internal::json::ArrayFromJSON(arrow::struct_(fields), R"([
+[6, [6.0, 6.0, 6.0, 6.0]],
+[7, [7.0, 7.0, 7.0, 7.0]],
+[8, [8.0, 8.0, 8.0, 8.0]],
+[9, [9.0, 9.0, 9.0, 9.0]]
+ ])")
+ .ValueOrDie();
+ auto src_array3 =
arrow::ipc::internal::json::ArrayFromJSON(arrow::struct_(fields), R"([
+[10, [10.0, 10.0, 10.0, 10.0]],
+[11, [11.0, 11.0, 11.0, 11.0]]
+ ])")
+ .ValueOrDie();
+ ASSERT_OK_AND_ASSIGN(auto commit_msgs1,
+ WriteArray(table_path, schema->field_names(),
src_array1));
+ ASSERT_OK(Commit(table_path, commit_msgs1));
+ ASSERT_OK_AND_ASSIGN(auto commit_msgs2,
+ WriteArray(table_path, schema->field_names(),
src_array2));
+ ASSERT_OK(Commit(table_path, commit_msgs2));
+ ASSERT_OK_AND_ASSIGN(auto commit_msgs3,
+ WriteArray(table_path, schema->field_names(),
src_array3));
+ ASSERT_OK(Commit(table_path, commit_msgs3));
+ ASSERT_OK(WriteIndex(table_path, /*partition_filters=*/{}, "f1", "lumina",
lumina_options,
+ Range(0, 5)));
+ ASSERT_OK(WriteIndex(table_path, /*partition_filters=*/{}, "f1", "lumina",
lumina_options,
+ Range(6, 9)));
+ ASSERT_OK(WriteIndex(table_path, /*partition_filters=*/{}, "f1", "lumina",
lumina_options,
+ Range(10, 11)));
+
+ auto create_scan = [&]() {
+ return GlobalIndexScan::Create(table_path,
/*snapshot_id=*/std::nullopt,
+ /*partitions=*/std::nullopt,
lumina_options, fs_,
+ /*executor=*/nullptr, pool_);
+ };
+ ASSERT_OK_AND_ASSIGN(std::shared_ptr<GlobalIndexScan>
scan_before_deletion, create_scan());
+
+ ASSERT_OK_AND_ASSIGN(auto split, ScanData(table_path,
/*partition_filters=*/{}));
+ ASSERT_OK_AND_ASSIGN(std::vector<std::string> anchor_file_names,
+
DeletionVectorTestHelper::RetrieveAnchorFileNames(split->DataFiles()));
+ ASSERT_EQ(anchor_file_names.size(), 3u);
+ ASSERT_OK_AND_ASSIGN(std::shared_ptr<CommitMessage> dv_commit_msg,
+
DeletionVectorTestHelper::CreateDeletionVectorCommitMessage(
+ dir_->GetFileSystem(), table_path, file_format_,
commit_msgs1[0],
+ {{anchor_file_names[0], /*deleted_positions=*/{0,
1, 2}},
+ {anchor_file_names[1],
/*deleted_positions=*/{1}},
+ {anchor_file_names[2], /*deleted_positions=*/{0,
1}}},
+ pool_));
+ ASSERT_OK(Commit(table_path, {dv_commit_msg}));
+ ASSERT_OK_AND_ASSIGN(std::shared_ptr<GlobalIndexScan> scan, create_scan());
+
+ std::vector<float> query = {0.0f, 0.0f, 0.0f, 0.0f};
+ auto search = [&](const std::shared_ptr<GlobalIndexScan>& index_scan,
+ const std::optional<RowRangeIndex>& row_range_index,
+ VectorSearch::PreFilter pre_filter,
+ const std::shared_ptr<Predicate>& predicate)
+ -> Result<std::shared_ptr<ScoredGlobalIndexResult>> {
+ PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<GlobalIndexReader> reader,
+ index_scan->CreateReader("f1", "lumina",
row_range_index));
+ if (!reader) {
+ return Status::Invalid("no lumina index on f1");
+ }
+ return reader->VisitVectorSearch(std::make_shared<VectorSearch>(
+ "f1", /*limit=*/3, query, std::move(pre_filter), predicate,
+ /*distance_type=*/std::nullopt, lumina_options));
+ };
+ ASSERT_OK_AND_ASSIGN(std::shared_ptr<ScoredGlobalIndexResult> index_result,
+ search(scan_before_deletion,
/*row_range_index=*/std::nullopt,
+ /*pre_filter=*/nullptr,
/*predicate=*/nullptr));
+ ASSERT_EQ(index_result->ToString(),
+ "row ids: {0,1,2,6,7,8,10,11}, "
+ "scores: {0.00,4.00,16.00,144.00,196.00,256.00,400.00,484.00}");
+ ASSERT_OK_AND_ASSIGN(index_result, search(
+ scan,
/*row_range_index=*/std::nullopt,
+ [](int64_t row_id) -> bool { return
row_id != 8; },
+ /*predicate=*/nullptr));
+ ASSERT_EQ(index_result->ToString(),
+ "row ids: {3,4,5,6,9}, scores:
{36.00,64.00,100.00,144.00,324.00}");
+ std::shared_ptr<Predicate> predicate = PredicateBuilder::In(
+ /*field_index=*/0, /*field_name=*/"f0", FieldType::INT,
+ {Literal(1), Literal(4), Literal(7), Literal(8), Literal(9)});
+ ASSERT_OK_AND_ASSIGN(index_result,
+ search(
+ scan, /*row_range_index=*/std::nullopt,
+ [](int64_t row_id) -> bool { return row_id != 9;
}, predicate));
+ ASSERT_EQ(index_result->ToString(), "row ids: {4,8}, scores:
{64.00,256.00}");
+ ASSERT_OK_AND_ASSIGN(index_result, search(scan,
/*row_range_index=*/std::nullopt,
+ /*pre_filter=*/nullptr,
/*predicate=*/nullptr));
+ ASSERT_EQ(index_result->ToString(),
+ "row ids: {3,4,5,6,8,9}, scores:
{36.00,64.00,100.00,144.00,256.00,324.00}");
+
+ ASSERT_OK_AND_ASSIGN(RowRangeIndex deleted_shard_range,
RowRangeIndex::Create({Range(10, 11)}));
+ ASSERT_OK_AND_ASSIGN(index_result, search(scan, deleted_shard_range,
/*pre_filter=*/nullptr,
+ /*predicate=*/nullptr));
+ ASSERT_EQ(index_result->ToString(), "row ids: {}, scores: {}");
+
+ ASSERT_OK_AND_ASSIGN(RowRangeIndex first_shard_range,
RowRangeIndex::Create({Range(0, 5)}));
+ ASSERT_OK_AND_ASSIGN(index_result, search(scan, first_shard_range,
/*pre_filter=*/nullptr,
+ /*predicate=*/nullptr));
+ ASSERT_EQ(index_result->ToString(), "row ids: {3,4,5}, scores:
{36.00,64.00,100.00}");
+ ASSERT_OK_AND_ASSIGN(auto plan, ScanGlobalIndexAndData(table_path,
/*predicate=*/nullptr,
+ /*options=*/{},
index_result));
+ auto expected_array =
+ arrow::ipc::internal::json::ArrayFromJSON(
+ arrow::struct_({SpecialFields::ValueKind().ArrowField(),
fields[0]}), R"([
+[0, 3],
+[0, 4],
+[0, 5]
+ ])")
+ .ValueOrDie();
+ ASSERT_OK(ReadData(table_path, {"f0"}, expected_array,
/*predicate=*/nullptr, plan));
+}
+
+TEST_P(GlobalIndexTest, TestLuminaSearchSkipsUnindexedDeletionVectors) {
+ arrow::FieldVector fields = {arrow::field("f0", arrow::int32()),
+ arrow::field("f1",
arrow::list(arrow::float32()))};
+ std::map<std::string, std::string> lumina_options =
{{"lumina.index.dimension", "4"},
+ {"lumina.index.type",
"bruteforce"},
+
{"lumina.distance.metric", "l2"},
+
{"lumina.encoding.type", "rawf32"},
+
{"lumina.search.parallel_number", "10"}};
+ auto schema = arrow::schema(fields);
+ std::map<std::string, std::string> options = {{Options::FILE_FORMAT,
file_format_},
+ {Options::FILE_SYSTEM,
"local"},
+
{Options::ROW_TRACKING_ENABLED, "true"},
+
{Options::DATA_EVOLUTION_ENABLED, "true"},
+
{Options::DELETION_VECTORS_ENABLED, "true"}};
+ CreateTable(/*partition_keys=*/{}, schema, options);
+ std::string table_path = PathUtil::JoinPath(dir_->Str(), "foo.db/bar");
+
+ auto indexed_array =
arrow::ipc::internal::json::ArrayFromJSON(arrow::struct_(fields), R"([
+[0, [0.0, 0.0, 0.0, 0.0]],
+[1, [1.0, 1.0, 1.0, 1.0]]
+ ])")
+ .ValueOrDie();
+ auto unindexed_array =
arrow::ipc::internal::json::ArrayFromJSON(arrow::struct_(fields), R"([
+[2, [2.0, 2.0, 2.0, 2.0]],
+[3, [3.0, 3.0, 3.0, 3.0]]
+ ])")
+ .ValueOrDie();
+ ASSERT_OK_AND_ASSIGN(auto indexed_commit_msgs,
+ WriteArray(table_path, schema->field_names(),
indexed_array));
+ ASSERT_OK(Commit(table_path, indexed_commit_msgs));
+ ASSERT_OK_AND_ASSIGN(auto unindexed_commit_msgs,
+ WriteArray(table_path, schema->field_names(),
unindexed_array));
+ ASSERT_OK(Commit(table_path, unindexed_commit_msgs));
+ ASSERT_OK(WriteIndex(table_path, /*partition_filters=*/{}, "f1", "lumina",
lumina_options,
+ Range(0, 1)));
+
+ ASSERT_OK_AND_ASSIGN(auto split, ScanData(table_path,
/*partition_filters=*/{}));
+ ASSERT_OK_AND_ASSIGN(std::vector<std::string> anchor_file_names,
+
DeletionVectorTestHelper::RetrieveAnchorFileNames(split->DataFiles()));
+ ASSERT_EQ(anchor_file_names.size(), 2u);
+ ASSERT_OK_AND_ASSIGN(
+ std::shared_ptr<CommitMessage> dv_commit_msg,
+ DeletionVectorTestHelper::CreateDeletionVectorCommitMessage(
+ dir_->GetFileSystem(), table_path, file_format_,
unindexed_commit_msgs[0],
+ {{anchor_file_names[1], /*deleted_positions=*/{1}}}, pool_));
+ ASSERT_OK(Commit(table_path, {dv_commit_msg}));
+
+ ASSERT_OK_AND_ASSIGN(split, ScanData(table_path,
/*partition_filters=*/{}));
+ std::vector<std::string> deletion_file_paths;
+ for (const std::optional<DeletionFile>& deletion_file :
split->DeletionFiles()) {
+ if (deletion_file) {
+ deletion_file_paths.push_back(deletion_file->path);
+ }
+ }
+ ASSERT_EQ(deletion_file_paths.size(), 1u);
+ ASSERT_OK(dir_->GetFileSystem()->Delete(deletion_file_paths[0]));
+
+ ASSERT_OK_AND_ASSIGN(std::shared_ptr<GlobalIndexScan> scan,
+ GlobalIndexScan::Create(table_path,
/*snapshot_id=*/std::nullopt,
+ /*partitions=*/std::nullopt,
lumina_options, fs_,
+ /*executor=*/nullptr, pool_));
+ ASSERT_OK_AND_ASSIGN(std::shared_ptr<GlobalIndexReader> reader,
+ scan->CreateReader("f1", "lumina",
/*row_range_index=*/std::nullopt));
+ ASSERT_TRUE(reader);
+ std::vector<float> query = {0.0f, 0.0f, 0.0f, 0.0f};
+ ASSERT_OK_AND_ASSIGN(
+ std::shared_ptr<ScoredGlobalIndexResult> index_result,
+ reader->VisitVectorSearch(std::make_shared<VectorSearch>(
+ "f1", /*limit=*/2, query, /*pre_filter=*/nullptr,
+ /*predicate=*/nullptr, /*distance_type=*/std::nullopt,
lumina_options)));
+ ASSERT_EQ(index_result->ToString(), "row ids: {0,1}, scores: {0.00,4.00}");
+}
#endif
TEST_P(GlobalIndexTest, TestDataEvolutionBatchScanWithExternalPath) {