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 eec95be15c [core][python] Include unindexed rows by default in Data
Evolution scalar scans (#11319)
eec95be15c is described below
commit eec95be15cafdb7111a3cd8f0dafab91ba752f56
Author: Jingsong Lee <[email protected]>
AuthorDate: Sat Nov 21 22:49:51 2026 +0800
[core][python] Include unindexed rows by default in Data Evolution scalar
scans (#11319)
---
docs/docs/multimodal-table/global-index.mdx | 8 +-
.../multimodal-table/global-index/full-text.mdx | 4 +-
.../global-index/hybrid-search.mdx | 2 +-
.../global-index/manage-indexes.mdx | 27 +++++--
docs/docs/multimodal-table/global-index/rtree.mdx | 4 +-
docs/docs/multimodal-table/global-index/vector.mdx | 5 +-
docs/docs/multimodal-table/index.mdx | 5 +-
docs/docs/multimodal-table/quick-start.mdx | 16 ++--
docs/generated/core_configuration.html | 10 ++-
.../main/java/org/apache/paimon/CoreOptions.java | 39 ++++++++--
.../paimon/globalindex/DataEvolutionBatchScan.java | 24 +++---
.../DataEvolutionGlobalIndexScanner.java | 89 ++++++++++------------
.../source/AbstractDataEvolutionVectorRead.java | 18 ++++-
.../table/source/DataEvolutionFullTextRead.java | 29 +++----
.../table/source/DataEvolutionVectorScan.java | 4 +-
.../java/org/apache/paimon/CoreOptionsTest.java | 23 ++++++
.../paimon/table/BtreeGlobalIndexTableTest.java | 41 ++++++----
.../apache/paimon/table/IndexQuerySplitTest.java | 4 +-
.../table/MultiValueGlobalIndexTableTest.java | 9 +--
.../table/source/FullTextSearchBuilderTest.java | 15 ++++
.../table/source/VectorSearchBuilderTest.java | 7 ++
.../pypaimon/common/options/core_options.py | 29 ++++++-
.../native/read/native_full_text_search.py | 6 +-
.../execution/native/read/native_hybrid_search.py | 9 ++-
.../execution/native/read/native_search_plan.py | 13 +++-
.../execution/native/read/native_vector_search.py | 6 +-
.../pypaimon/execution/native/read/plan.py | 12 ++-
.../execution/python/read/scanner/file_scanner.py | 2 +-
.../execution/python/read/search/full_text_read.py | 2 +-
.../python/read/search/vector_search_read.py | 2 +-
.../python/read/search/vector_search_scan.py | 2 +-
.../pypaimon/multimodal/lerobot/reader.py | 2 +-
.../pypaimon/table/source/vector_search_builder.py | 7 +-
.../pypaimon/tests/global_index_build_test.py | 18 +++++
.../tests/global_index_scalar_search_mode_test.py | 20 +++++
paimon-python/pypaimon/tests/global_index_test.py | 2 +-
.../pypaimon/tests/lerobot_native_reader_test.py | 13 +++-
.../pypaimon/tests/native_full_text_search_test.py | 12 +++
.../pypaimon/tests/native_hybrid_search_test.py | 15 ++++
.../pypaimon/tests/native_index_options_test.py | 7 +-
.../pypaimon/tests/native_vector_search_test.py | 19 +++++
.../paimon/spark/sql/GeospatialTypeSQLTest.scala | 5 +-
42 files changed, 421 insertions(+), 165 deletions(-)
diff --git a/docs/docs/multimodal-table/global-index.mdx
b/docs/docs/multimodal-table/global-index.mdx
index 8ce236a276..3c0424375b 100644
--- a/docs/docs/multimodal-table/global-index.mdx
+++ b/docs/docs/multimodal-table/global-index.mdx
@@ -51,10 +51,10 @@ This guide covers Data Evolution append tables. Primary-key
tables have a separa
:::caution Index coverage affects results
-The default search mode is `fast`. If an index covers only part of the table,
-matching rows outside that coverage can be omitted. Creating a table or
appending
-data does not build a global index. Read [Coverage and
Freshness](./global-index/manage-indexes#coverage-and-freshness)
-before using indexed queries on changing data.
+Ordinary Data Evolution batch scans use `full` by default and read uncovered
rows.
+Vector and full-text searches default to `fast` and can omit matches outside
index coverage.
+Creating a table or appending data does not build a global index. See
+[Coverage and Freshness](./global-index/manage-indexes#coverage-and-freshness).
:::
diff --git a/docs/docs/multimodal-table/global-index/full-text.mdx
b/docs/docs/multimodal-table/global-index/full-text.mdx
index 52d3b1ba7c..9c5732212b 100644
--- a/docs/docs/multimodal-table/global-index/full-text.mdx
+++ b/docs/docs/multimodal-table/global-index/full-text.mdx
@@ -308,9 +308,9 @@ BM25 statistics are always those of the full corpus:
why it is opt-in; prefer an index that answers the predicate exactly, such as
Bitmap or FM for `contains`.
- Rows whose filter columns are not covered by a scalar index follow
- `scalar-index.search-mode`:
+
[`scalar-index.prefilter.search-mode`](./manage-indexes#coverage-and-freshness):
-| `scalar-index.search-mode` | Rows without an index on the filter columns |
+| `scalar-index.prefilter.search-mode` | Rows without an index on the filter
columns |
|---|---|
| `fast` (default) | Excluded from the search; a warning is logged |
| `full` / `detail` | Decided by reading their filter columns |
diff --git a/docs/docs/multimodal-table/global-index/hybrid-search.mdx
b/docs/docs/multimodal-table/global-index/hybrid-search.mdx
index 94625ab917..cb25f9db86 100644
--- a/docs/docs/multimodal-table/global-index/hybrid-search.mdx
+++ b/docs/docs/multimodal-table/global-index/hybrid-search.mdx
@@ -430,6 +430,6 @@ its own top-k, so vector and full-text candidates are drawn
from the same
filtered row set before the ranker merges them. Full-text routes follow the
same
rules as a standalone full-text search; see
[Full-Text Row Filters](./full-text#row-filters). In particular, under
-`scalar-index.search-mode=fast` a full-text route whose filter columns have no
+`scalar-index.prefilter.search-mode=fast` a full-text route whose filter
columns have no
scalar index contributes no candidates, so the fused result comes from the
other routes only.
diff --git a/docs/docs/multimodal-table/global-index/manage-indexes.mdx
b/docs/docs/multimodal-table/global-index/manage-indexes.mdx
index f7acd7d4e1..20a8cd790a 100644
--- a/docs/docs/multimodal-table/global-index/manage-indexes.mdx
+++ b/docs/docs/multimodal-table/global-index/manage-indexes.mdx
@@ -226,9 +226,10 @@ batch as ready for indexed queries.
Global index files cover row-id ranges. If more rows are appended after an
index is built, those
new rows are not automatically covered by the existing index files. Build the
global index again
-to create index files for newly uncovered data. The scalar, vector, and
full-text families
-default to `fast`, which searches indexed row ranges.
-Choose a search mode deliberately when recently appended data must be included.
+to create index files for newly uncovered data. Ordinary Data Evolution batch
scans default to
+`full`, which includes uncovered rows. Vector and full-text searches default
to `fast`, including
+the scalar coverage mode used for their row filters. An explicit `fast` can
omit matches in
+uncovered ranges.
Updates to already indexed rows also require the [update
policy](#update-indexed-columns).
| Mode | How coverage is checked | Use when |
@@ -279,10 +280,19 @@ the latest column values. An update that preserves row
IDs can therefore leave
stale index entries even when coverage is complete. Handle those updates
through
the [index update policy](#update-indexed-columns) and an index build.
-Use `scalar-index.search-mode`, `vector-index.search-mode`, or
-`full-text-index.search-mode` for one index family. The legacy
-`global-index.search-mode` has no default and is used as a fallback when the
corresponding
-family-specific option is not explicitly configured.
+Each query uses the first explicitly configured option in its list, followed
by its default.
+
+| Query | Search mode precedence |
+| --- | --- |
+| Ordinary Data Evolution scalar batch scan | `scalar-index.search-mode` →
`global-index.search-mode` → `full` |
+| Scalar prefilter in vector and full-text search |
`scalar-index.prefilter.search-mode` → `scalar-index.search-mode` →
`global-index.search-mode` → `fast` |
+| Vector search | `vector-index.search-mode` → `global-index.search-mode` →
`fast` |
+| Full-text search | `full-text-index.search-mode` →
`global-index.search-mode` → `fast` |
+
+Set `scalar-index.prefilter.search-mode` to tune filter coverage independently
of ordinary
+scalar scans. For example, `scalar-index.search-mode=full` and
+`scalar-index.prefilter.search-mode=fast` retain uncovered rows in ordinary
scans and limit
+search prefilters to indexed scalar coverage.
To temporarily disable global-index scan acceleration while keeping the index
files, set:
@@ -472,7 +482,8 @@ These table options affect global index build and read
behavior:
| `global-index.enabled` | `true` | Whether scans can use global indexes. |
| `global-index.query-in-reader.enabled` | `false` | Query supported scalar
global indexes per data split in readers instead of materializing index results
during scan planning. |
| `global-index.search-mode` | Not set | Legacy fallback search mode for
global-index queries. Family-specific options take precedence. |
-| `scalar-index.search-mode` | `fast` | Search mode for BTree, Bitmap,
Multivalue, FM, and R-tree bbox queries. |
+| `scalar-index.search-mode` | `full` | Search mode for ordinary Data
Evolution scalar batch scans. An explicit setting also serves as a fallback for
scalar prefilters. |
+| `scalar-index.prefilter.search-mode` | `fast` | Search mode for scalar
prefilters in vector and full-text search. Falls back to explicit
`scalar-index.search-mode` and `global-index.search-mode` in that order. |
| `vector-index.search-mode` | `fast` | Search mode for vector queries. |
| `full-text-index.search-mode` | `fast` | Search mode for full-text queries. |
| `global-index.external-path` | Not set | Root directory for global index
files. If not set, files are stored under the table index directory. |
diff --git a/docs/docs/multimodal-table/global-index/rtree.mdx
b/docs/docs/multimodal-table/global-index/rtree.mdx
index 09273cc1a1..e17be14110 100644
--- a/docs/docs/multimodal-table/global-index/rtree.mdx
+++ b/docs/docs/multimodal-table/global-index/rtree.mdx
@@ -118,8 +118,8 @@ when `global-index.filter.refine-from-data` is false.
## Coverage and Updates
The normal [coverage and freshness
rules](./manage-indexes#coverage-and-freshness)
-apply. The default scalar search mode is `fast`, which can omit unindexed rows.
-Choose `scalar-index.search-mode=full` or `detail` when uncovered ranges must
be
+apply. Ordinary Data Evolution batch scans default to `full`. An explicit
`fast` can
+omit unindexed rows. Choose `full` or `detail` when uncovered ranges must be
scanned, and refresh indexes as new data arrives.
Changing the geometry column makes existing envelopes stale even when row IDs
diff --git a/docs/docs/multimodal-table/global-index/vector.mdx
b/docs/docs/multimodal-table/global-index/vector.mdx
index bce1756458..62920e0694 100644
--- a/docs/docs/multimodal-table/global-index/vector.mdx
+++ b/docs/docs/multimodal-table/global-index/vector.mdx
@@ -323,8 +323,9 @@ columns, each query runs ANN once per shard. Post-filtering
may return fewer tha
when matches exist outside the candidates. Increasing the factor trades more
ANN/scalar
work for more candidates. Post-filtering does not retry or scan raw data to
fill Top-K.
Raw work outside vector coverage still follows the configured index search
modes. When a
-scalar index can evaluate the predicate but covers only some rows, scalar
`full`/`detail`
-modes also plan raw scans for its uncovered rows.
+scalar index can evaluate the predicate but covers only some rows, setting
+[`scalar-index.prefilter.search-mode`](./manage-indexes#coverage-and-freshness)
+to `full` or `detail` also plans raw scans for its uncovered rows.
Build a BTree index for frequently used metadata filters, such as `category`,
`tenant_id`,
or `event_time`, to restrict candidate row IDs before ANN.
diff --git a/docs/docs/multimodal-table/index.mdx
b/docs/docs/multimodal-table/index.mdx
index ad7b4c8fcb..b2c0b849fc 100644
--- a/docs/docs/multimodal-table/index.mdx
+++ b/docs/docs/multimodal-table/index.mdx
@@ -83,8 +83,9 @@ For JVM primary-key workloads, use the separate guides for
- A normal-column update writes the selected columns over complete affected
file
ranges. It saves I/O on untouched columns; it can still process more rows
than
the update predicate matches.
-- Appending data does not refresh existing indexes. The default `fast` search
mode
- can omit uncovered rows; choose a [coverage
policy](./global-index/manage-indexes#coverage-and-freshness).
+- Appending data does not refresh existing indexes. Ordinary batch scans
include uncovered
+ rows by default. The `fast` mode used by default in vector and full-text
searches can omit
+ uncovered rows. See [Coverage and
Freshness](./global-index/manage-indexes#coverage-and-freshness).
- Ordinary updates and compaction preserve row IDs. Some maintenance operations
reassign them; coordinate [row-ID
lifetime](./data-evolution-maintenance#row-id-lifetime)
with BLOB views or applications that persist row references.
diff --git a/docs/docs/multimodal-table/quick-start.mdx
b/docs/docs/multimodal-table/quick-start.mdx
index c52b7a23c7..28e3466b8b 100644
--- a/docs/docs/multimodal-table/quick-start.mdx
+++ b/docs/docs/multimodal-table/quick-start.mdx
@@ -113,9 +113,9 @@ FROM `media_samples$table_indexes`
WHERE index_field_name = 'category';
```
-The default search mode is `fast`, which searches indexed coverage. If you
append
-more records, build again before expecting indexed queries to include them, or
-select an appropriate [search
mode](./global-index/manage-indexes#coverage-and-freshness).
+Ordinary scalar queries default to `full`, which also scans rows outside the
index coverage.
+Use the [search modes](./global-index/manage-indexes#coverage-and-freshness)
to configure that
+behavior explicitly.
Updates to an indexed column also have a separate
[update policy](./global-index/manage-indexes#update-indexed-columns); this
example enriches
the data before building the index.
@@ -123,14 +123,13 @@ the data before building the index.
## 5. Refresh After an Append
Append another matching record after the first index build. With the default
-`scalar-index.search-mode=fast`, the indexed query still searches the original
-coverage:
+scalar scan mode, the query finds both rows:
```sql
INSERT INTO media_samples VALUES (3, 'animals', X'070809', NULL, NULL);
SELECT id FROM media_samples WHERE category = 'animals' ORDER BY id;
--- 1 (the new row is outside the current index coverage)
+-- 1, 3
```
Build again to cover the new row, then repeat the query:
@@ -146,9 +145,8 @@ SELECT id FROM media_samples WHERE category = 'animals'
ORDER BY id;
-- 1, 3
```
-The second build adds missing coverage. It does not make later appends refresh
-automatically. For reads that must include uncovered rows before the next
build,
-see the `full` and `detail` [search
modes](./global-index/manage-indexes#coverage-and-freshness).
+The second build adds missing coverage for this append. Rebuild after later
appends to
+accelerate queries on those rows.
## Next Steps
diff --git a/docs/generated/core_configuration.html
b/docs/generated/core_configuration.html
index 4bbc4e082c..963f094d9a 100644
--- a/docs/generated/core_configuration.html
+++ b/docs/generated/core_configuration.html
@@ -1573,10 +1573,16 @@ For an internal format table in a REST catalog, it also
makes the catalog own th
<td>The field that generates the row kind for primary key table,
the row kind determines which data is '+I', '-U', '+U' or '-D'.</td>
</tr>
<tr>
- <td><h5>scalar-index.search-mode</h5></td>
+ <td><h5>scalar-index.prefilter.search-mode</h5></td>
<td style="word-wrap: break-word;">fast</td>
<td><p>Enum</p></td>
- <td>Search mode for scalar index queries.<br /><br />Possible
values:<ul><li>"fast": Only search indexed data.</li><li>"full": Use snapshot
next row id and global index coverage to detect missing row ids, and scan raw
data only when a gap exists.</li><li>"detail": Scan data files to find exact
unindexed rows. This can handle index invalidation caused by updates or
rewrites.</li></ul></td>
+ <td>Search mode for scalar prefilters in vector and full-text
search. If unset, use an explicit scalar-index.search-mode, then an explicit
global-index.search-mode, then fast.<br /><br />Possible values:<ul><li>"fast":
Only search indexed data.</li><li>"full": Use snapshot next row id and global
index coverage to detect missing row ids, and scan raw data only when a gap
exists.</li><li>"detail": Scan data files to find exact unindexed rows. This
can handle index invalidation [...]
+ </tr>
+ <tr>
+ <td><h5>scalar-index.search-mode</h5></td>
+ <td style="word-wrap: break-word;">full</td>
+ <td><p>Enum</p></td>
+ <td>Search mode for ordinary Data Evolution scalar batch scans. An
explicit setting also serves as a fallback for scalar prefilters.<br /><br
/>Possible values:<ul><li>"fast": Only search indexed data.</li><li>"full": Use
snapshot next row id and global index coverage to detect missing row ids, and
scan raw data only when a gap exists.</li><li>"detail": Scan data files to find
exact unindexed rows. This can handle index invalidation caused by updates or
rewrites.</li></ul></td>
</tr>
<tr>
<td><h5>scan.bounded.watermark</h5></td>
diff --git a/paimon-api/src/main/java/org/apache/paimon/CoreOptions.java
b/paimon-api/src/main/java/org/apache/paimon/CoreOptions.java
index 06d94253fc..10a463f4c4 100644
--- a/paimon-api/src/main/java/org/apache/paimon/CoreOptions.java
+++ b/paimon-api/src/main/java/org/apache/paimon/CoreOptions.java
@@ -3188,9 +3188,20 @@ public class CoreOptions implements Serializable {
public static final ConfigOption<GlobalIndexSearchMode>
SCALAR_INDEX_SEARCH_MODE =
key("scalar-index.search-mode")
+ .enumType(GlobalIndexSearchMode.class)
+ .defaultValue(GlobalIndexSearchMode.FULL)
+ .withDescription(
+ "Search mode for ordinary Data Evolution scalar
batch scans. An explicit "
+ + "setting also serves as a fallback for
scalar prefilters.");
+
+ public static final ConfigOption<GlobalIndexSearchMode>
SCALAR_INDEX_PREFILTER_SEARCH_MODE =
+ key("scalar-index.prefilter.search-mode")
.enumType(GlobalIndexSearchMode.class)
.defaultValue(GlobalIndexSearchMode.FAST)
- .withDescription("Search mode for scalar index queries.");
+ .withDescription(
+ "Search mode for scalar prefilters in vector and
full-text search. If "
+ + "unset, use an explicit
scalar-index.search-mode, then an "
+ + "explicit global-index.search-mode, then
fast.");
public static final ConfigOption<GlobalIndexSearchMode>
VECTOR_INDEX_SEARCH_MODE =
key("vector-index.search-mode")
@@ -5083,9 +5094,22 @@ public class CoreOptions implements Serializable {
}
public GlobalIndexSearchMode scalarIndexSearchMode() {
+ return indexSearchMode(SCALAR_INDEX_SEARCH_MODE,
GlobalIndexSearchMode.FAST);
+ }
+
+ public GlobalIndexSearchMode scalarScanSearchMode() {
return indexSearchMode(SCALAR_INDEX_SEARCH_MODE);
}
+ public GlobalIndexSearchMode scalarPrefilterSearchMode() {
+ return options.getOptional(SCALAR_INDEX_PREFILTER_SEARCH_MODE)
+ .orElseGet(
+ () ->
+ indexSearchMode(
+ SCALAR_INDEX_SEARCH_MODE,
+
SCALAR_INDEX_PREFILTER_SEARCH_MODE.defaultValue()));
+ }
+
public boolean globalIndexFilterRefineFromData() {
return options.get(GLOBAL_INDEX_FILTER_REFINE_FROM_DATA);
}
@@ -5100,11 +5124,14 @@ public class CoreOptions implements Serializable {
private GlobalIndexSearchMode indexSearchMode(
ConfigOption<GlobalIndexSearchMode> familySearchMode) {
- if (options.contains(familySearchMode)) {
- return options.get(familySearchMode);
- }
- return options.getOptional(GLOBAL_INDEX_SEARCH_MODE)
- .orElseGet(() -> options.get(familySearchMode));
+ return indexSearchMode(familySearchMode,
familySearchMode.defaultValue());
+ }
+
+ private GlobalIndexSearchMode indexSearchMode(
+ ConfigOption<GlobalIndexSearchMode> familySearchMode,
+ GlobalIndexSearchMode defaultMode) {
+ return options.getOptional(familySearchMode)
+ .orElseGet(() ->
options.getOptional(GLOBAL_INDEX_SEARCH_MODE).orElse(defaultMode));
}
public Integer globalIndexThreadNum() {
diff --git
a/paimon-core/src/main/java/org/apache/paimon/globalindex/DataEvolutionBatchScan.java
b/paimon-core/src/main/java/org/apache/paimon/globalindex/DataEvolutionBatchScan.java
index da3c379866..470eb3a879 100644
---
a/paimon-core/src/main/java/org/apache/paimon/globalindex/DataEvolutionBatchScan.java
+++
b/paimon-core/src/main/java/org/apache/paimon/globalindex/DataEvolutionBatchScan.java
@@ -20,6 +20,7 @@ package org.apache.paimon.globalindex;
import org.apache.paimon.CoreOptions;
import org.apache.paimon.CoreOptions.ChangelogProducer;
+import org.apache.paimon.CoreOptions.GlobalIndexSearchMode;
import org.apache.paimon.Snapshot;
import org.apache.paimon.annotation.VisibleForTesting;
import org.apache.paimon.data.BinaryRow;
@@ -60,6 +61,7 @@ import javax.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -374,10 +376,12 @@ public class DataEvolutionBatchScan implements
DataTableScan {
return planEager();
}
Predicate indexFilter = rowIdSafeResidualFilter(filter);
- if (indexFilter == null
- || (table.coreOptions().scalarIndexSearchMode()
- == CoreOptions.GlobalIndexSearchMode.FAST
- && hasMixedSpatialDisjunction(indexFilter, false))) {
+ if (indexFilter == null) {
+ return planEager();
+ }
+ GlobalIndexSearchMode searchMode =
table.coreOptions().scalarScanSearchMode();
+ if (searchMode == GlobalIndexSearchMode.FAST
+ && hasMixedSpatialDisjunction(indexFilter, false)) {
return planEager();
}
@@ -425,6 +429,9 @@ public class DataEvolutionBatchScan implements
DataTableScan {
if (indexQuery == null) {
return dataPlan;
}
+ // Store the effective mode so restored splits keep the original scan
semantics.
+ Map<String, String> indexOptions = new HashMap<>(table.options());
+ indexOptions.put(CoreOptions.SCALAR_INDEX_SEARCH_MODE.key(),
searchMode.toString());
List<Split> indexQuerySplits = new ArrayList<>();
for (Split split : splits) {
DataSplit dataSplit = dataSplit(split);
@@ -432,8 +439,7 @@ public class DataEvolutionBatchScan implements
DataTableScan {
GlobalIndexBuilderUtils.calcRowRanges(Collections.singletonList(dataSplit));
GlobalIndexQuery splitQuery = indexQuery.forRanges(ranges);
List<Range> queryRanges =
- table.coreOptions().scalarIndexSearchMode()
- == CoreOptions.GlobalIndexSearchMode.FAST
+ searchMode == GlobalIndexSearchMode.FAST
? Range.and(ranges, splitQuery.indexedRanges())
: ranges;
if (queryRanges.isEmpty() || splitQuery.isEmpty(queryRanges)) {
@@ -441,7 +447,7 @@ public class DataEvolutionBatchScan implements
DataTableScan {
}
Split indexQuerySplit =
new IndexQuerySplit(
- dataSplit, splitQuery, table.options(),
Collections.emptyList());
+ dataSplit, splitQuery, indexOptions,
Collections.emptyList());
indexQuerySplits.add(withAuth(split, indexQuerySplit));
}
return () -> indexQuerySplits;
@@ -542,7 +548,7 @@ public class DataEvolutionBatchScan implements
DataTableScan {
LOG.info(
"Scan table '{}' with global index. searchMode='{}',
total={} ms, metadata={} ms, lookup={} ms, coverage={} ms.",
table.name(),
- options.scalarIndexSearchMode(),
+ options.scalarScanSearchMode(),
totalDuration / 1_000_000,
metadataDuration / 1_000_000,
lookupDuration / 1_000_000,
@@ -583,7 +589,7 @@ public class DataEvolutionBatchScan implements
DataTableScan {
LOG.info(
"Scan table '{}' with BTree global index TopN.
searchMode='{}', topN='{}', total={} ms, metadata={} ms, lookup={} ms,
coverage={} ms.",
table.name(),
- options.scalarIndexSearchMode(),
+ options.scalarScanSearchMode(),
topN,
totalDuration / 1_000_000,
metadataDuration / 1_000_000,
diff --git
a/paimon-core/src/main/java/org/apache/paimon/globalindex/DataEvolutionGlobalIndexScanner.java
b/paimon-core/src/main/java/org/apache/paimon/globalindex/DataEvolutionGlobalIndexScanner.java
index 4316e4f0cb..0de1ac08d5 100644
---
a/paimon-core/src/main/java/org/apache/paimon/globalindex/DataEvolutionGlobalIndexScanner.java
+++
b/paimon-core/src/main/java/org/apache/paimon/globalindex/DataEvolutionGlobalIndexScanner.java
@@ -18,6 +18,7 @@
package org.apache.paimon.globalindex;
+import org.apache.paimon.CoreOptions.GlobalIndexSearchMode;
import org.apache.paimon.Snapshot;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.globalindex.btree.BTreeGlobalIndexerFactory;
@@ -86,48 +87,20 @@ public class DataEvolutionGlobalIndexScanner implements
Closeable {
FileStoreTable table,
@Nullable Snapshot snapshot,
@Nullable PartitionPredicate partitionFilter,
- Options options,
- RowType rowType,
- FileIO fileIO,
- IndexPathFactory indexPathFactory,
- Collection<IndexFileMeta> indexFiles) {
- this(
- table,
- snapshot,
- partitionFilter,
- options,
- rowType,
- fileIO,
- indexPathFactory,
- indexFiles,
- indexFiles);
- }
-
- private DataEvolutionGlobalIndexScanner(
- FileStoreTable table,
- @Nullable Snapshot snapshot,
- @Nullable PartitionPredicate partitionFilter,
- Options options,
- RowType rowType,
- FileIO fileIO,
- IndexPathFactory indexPathFactory,
+ GlobalIndexSearchMode searchMode,
Collection<IndexFileMeta> coverageIndexFiles,
Collection<IndexFileMeta> indexFiles) {
this.table = table;
this.indexFiles = new ArrayList<>(indexFiles);
- this.fileIO = fileIO;
- this.options = options;
- this.rowType = rowType;
+ this.fileIO = table.fileIO();
+ this.options = table.coreOptions().toConfiguration();
+ this.rowType = table.rowType();
this.executor =
GlobalIndexReadThreadPool.getExecutorService(options.get(GLOBAL_INDEX_THREAD_NUM));
- this.indexPathFactory = indexPathFactory;
+ this.indexPathFactory =
table.store().pathFactory().globalIndexFileFactory();
this.coverage =
new DataEvolutionGlobalIndexCoverage(
- table,
- snapshot,
- partitionFilter,
- coverageIndexFiles,
- table.coreOptions().scalarIndexSearchMode());
+ table, snapshot, partitionFilter, coverageIndexFiles,
searchMode);
GlobalIndexFileReader indexFileReader = meta ->
fileIO.newInputStream(meta.filePath());
Map<Integer, List<IndexMetaFileGroup>> groupsByField =
groupIndexFiles(indexFiles);
IntFunction<Collection<GlobalIndexReader>> readersFunction =
@@ -216,13 +189,28 @@ public class DataEvolutionGlobalIndexScanner implements
Closeable {
@Nullable Snapshot pinnedSnapshot,
@Nullable PartitionPredicate partitionFilter,
Collection<IndexFileMeta> indexFiles) {
+ return createForScalarFilters(
+ table,
+ pinnedSnapshot,
+ partitionFilter,
+ indexFiles,
+ table.coreOptions().scalarPrefilterSearchMode());
+ }
+
+ public static Optional<DataEvolutionGlobalIndexScanner>
createForScalarFilters(
+ FileStoreTable table,
+ @Nullable Snapshot pinnedSnapshot,
+ @Nullable PartitionPredicate partitionFilter,
+ Collection<IndexFileMeta> indexFiles,
+ GlobalIndexSearchMode searchMode) {
return create(
table,
pinnedSnapshot,
partitionFilter,
indexFiles.stream()
.filter(file -> !isMultiFieldIndex(file))
- .collect(Collectors.toList()));
+ .collect(Collectors.toList()),
+ searchMode);
}
public static Optional<DataEvolutionGlobalIndexScanner> create(
@@ -230,6 +218,20 @@ public class DataEvolutionGlobalIndexScanner implements
Closeable {
@Nullable Snapshot pinnedSnapshot,
@Nullable PartitionPredicate partitionFilter,
Collection<IndexFileMeta> indexFiles) {
+ return create(
+ table,
+ pinnedSnapshot,
+ partitionFilter,
+ indexFiles,
+ table.coreOptions().scalarIndexSearchMode());
+ }
+
+ private static Optional<DataEvolutionGlobalIndexScanner> create(
+ FileStoreTable table,
+ @Nullable Snapshot pinnedSnapshot,
+ @Nullable PartitionPredicate partitionFilter,
+ Collection<IndexFileMeta> indexFiles,
+ GlobalIndexSearchMode searchMode) {
List<IndexFileMeta> globalIndexFiles =
globalIndexFiles(indexFiles).stream()
.filter(file -> isIndexInSchema(table.rowType(), file))
@@ -242,10 +244,8 @@ public class DataEvolutionGlobalIndexScanner implements
Closeable {
table,
pinnedSnapshot != null ? pinnedSnapshot :
tryTravelOrLatest(table),
partitionFilter,
- table.coreOptions().toConfiguration(),
- table.rowType(),
- table.fileIO(),
- table.store().pathFactory().globalIndexFileFactory(),
+ searchMode,
+ globalIndexFiles,
globalIndexFiles));
}
@@ -277,10 +277,8 @@ public class DataEvolutionGlobalIndexScanner implements
Closeable {
table,
snapshot,
partitionFilter,
- table.coreOptions().toConfiguration(),
- table.rowType(),
- table.fileIO(),
- table.store().pathFactory().globalIndexFileFactory(),
+ table.coreOptions().scalarScanSearchMode(),
+ indexFiles,
indexFiles));
}
@@ -324,10 +322,7 @@ public class DataEvolutionGlobalIndexScanner implements
Closeable {
table,
snapshot,
partitionFilter,
- table.coreOptions().toConfiguration(),
- table.rowType(),
- table.fileIO(),
- table.store().pathFactory().globalIndexFileFactory(),
+ table.coreOptions().scalarScanSearchMode(),
indexFiles,
selectedIndexFiles));
}
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/source/AbstractDataEvolutionVectorRead.java
b/paimon-core/src/main/java/org/apache/paimon/table/source/AbstractDataEvolutionVectorRead.java
index caf369cef2..c0f60988ad 100644
---
a/paimon-core/src/main/java/org/apache/paimon/table/source/AbstractDataEvolutionVectorRead.java
+++
b/paimon-core/src/main/java/org/apache/paimon/table/source/AbstractDataEvolutionVectorRead.java
@@ -19,6 +19,7 @@
package org.apache.paimon.table.source;
import org.apache.paimon.CoreOptions;
+import org.apache.paimon.CoreOptions.GlobalIndexSearchMode;
import org.apache.paimon.Snapshot;
import org.apache.paimon.data.InternalArray;
import org.apache.paimon.data.InternalRow;
@@ -102,6 +103,7 @@ public abstract class AbstractDataEvolutionVectorRead
implements Serializable {
protected final Map<String, String> options;
@Nullable protected final float[][] queryMatrix;
private final int candidatesFactor;
+ private final GlobalIndexSearchMode scalarPrefilterMode;
// Serialized with Spark/Flink worker closures; reset for each new read.
private boolean postFiltering;
@@ -157,6 +159,10 @@ public abstract class AbstractDataEvolutionVectorRead
implements Serializable {
Options effectiveOptions = Options.fromMap(mergedOptions);
this.candidatesFactor =
effectiveOptions.get(CoreOptions.VECTOR_INDEX_POST_FILTER_CANDIDATES_FACTOR);
+ this.scalarPrefilterMode =
+ filter == null
+ ? null
+ : new
CoreOptions(effectiveOptions).scalarPrefilterSearchMode();
if (candidatesFactor <= 0) {
throw new IllegalArgumentException(
CoreOptions.VECTOR_INDEX_POST_FILTER_CANDIDATES_FACTOR.key()
@@ -329,7 +335,11 @@ public abstract class AbstractDataEvolutionVectorRead
implements Serializable {
Optional<DataEvolutionGlobalIndexScanner> optionalScanner =
DataEvolutionGlobalIndexScanner.createForScalarFilters(
- table, planSnapshot, partitionFilter,
scalarIndexFiles);
+ table,
+ planSnapshot,
+ partitionFilter,
+ scalarIndexFiles,
+ scalarPrefilterMode);
if (!optionalScanner.isPresent()) {
return null;
}
@@ -374,7 +384,11 @@ public abstract class AbstractDataEvolutionVectorRead
implements Serializable {
}
Optional<DataEvolutionGlobalIndexScanner> optionalScanner =
DataEvolutionGlobalIndexScanner.createForScalarFilters(
- table, planSnapshot, partitionFilter,
scalarIndexFiles);
+ table,
+ planSnapshot,
+ partitionFilter,
+ scalarIndexFiles,
+ scalarPrefilterMode);
if (!optionalScanner.isPresent()) {
return null;
}
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/source/DataEvolutionFullTextRead.java
b/paimon-core/src/main/java/org/apache/paimon/table/source/DataEvolutionFullTextRead.java
index 3851358a68..919807a938 100644
---
a/paimon-core/src/main/java/org/apache/paimon/table/source/DataEvolutionFullTextRead.java
+++
b/paimon-core/src/main/java/org/apache/paimon/table/source/DataEvolutionFullTextRead.java
@@ -180,8 +180,9 @@ public class DataEvolutionFullTextRead implements
FullTextRead {
* otherwise. When every index covering the filter columns declines
the predicate, the
* rows are excluded in {@code fast} and otherwise decided by
reading their filter
* columns.
- * <li>Rows whose filter columns are not covered follow {@code
scalar-index.search-mode}:
- * excluded in {@code fast}, otherwise decided by reading their
filter columns.
+ * <li>Rows whose filter columns are not covered follow {@code
+ * scalar-index.prefilter.search-mode}: excluded in {@code fast},
otherwise decided by
+ * reading their filter columns.
* </ul>
*
* <p>Either way the rows stay in the existing full-text index and are
handed to it as an
@@ -210,13 +211,14 @@ public class DataEvolutionFullTextRead implements
FullTextRead {
}
RoaringNavigableMap64 unindexed = new RoaringNavigableMap64();
+ GlobalIndexSearchMode prefilterMode =
table.coreOptions().scalarPrefilterSearchMode();
for (Range range :
new DataEvolutionGlobalIndexCoverage(
table,
planSnapshot,
partitionFilter,
scalarIndexFiles,
- table.coreOptions().scalarIndexSearchMode())
+ prefilterMode)
.unindexedRanges(table.rowType(), filter)) {
unindexed.addRange(range);
}
@@ -248,8 +250,9 @@ public class DataEvolutionFullTextRead implements
FullTextRead {
}
matched.or(fromIndex);
} else {
- warnUnindexedFilter();
- if (table.coreOptions().scalarIndexSearchMode() !=
GlobalIndexSearchMode.FAST) {
+ if (prefilterMode == GlobalIndexSearchMode.FAST) {
+ warnUnindexedFilter();
+ } else {
// No scalar index could evaluate the filter: decide these
rows from the data,
// like rows whose filter columns have no index.
unindexed.or(decidedByIndex);
@@ -280,15 +283,13 @@ public class DataEvolutionFullTextRead implements
FullTextRead {
}
private void warnUnindexedFilter() {
- if (table.coreOptions().scalarIndexSearchMode() ==
GlobalIndexSearchMode.FAST) {
- LOG.warn(
- "Full-text search on table {} has a row filter {} that no
scalar global index "
- + "can evaluate; indexed rows are excluded from
the result because "
- + "scalar-index.search-mode is fast. Build a
scalar index on the "
- + "filtered columns or use search mode full.",
- table.name(),
- filter);
- }
+ LOG.warn(
+ "Full-text search on table {} has a row filter {} that no
scalar global index "
+ + "can evaluate. The fast scalar prefilter excludes
these rows. Build a "
+ + "scalar index on the filtered columns or set "
+ + "scalar-index.prefilter.search-mode to full.",
+ table.name(),
+ filter);
}
ScoredGlobalIndexResult evalQuery(
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/source/DataEvolutionVectorScan.java
b/paimon-core/src/main/java/org/apache/paimon/table/source/DataEvolutionVectorScan.java
index a1ac203824..8755eacc20 100644
---
a/paimon-core/src/main/java/org/apache/paimon/table/source/DataEvolutionVectorScan.java
+++
b/paimon-core/src/main/java/org/apache/paimon/table/source/DataEvolutionVectorScan.java
@@ -202,7 +202,7 @@ public class DataEvolutionVectorScan implements VectorScan {
scalarUnindexedRanges(
snapshot,
scalarFiles,
- effectiveOptions.scalarIndexSearchMode(),
+ effectiveOptions.scalarPrefilterSearchMode(),
filterFieldIds);
if (!bitmapCoverage.isEmpty()) {
List<Range> covered =
Range.sortAndMergeOverlap(bitmapCoverage, true);
@@ -286,7 +286,7 @@ public class DataEvolutionVectorScan implements VectorScan {
// use the actual contributing fields so a declined OR arm does not
generate raw work.
Optional<DataEvolutionGlobalIndexScanner> optionalScanner =
DataEvolutionGlobalIndexScanner.createForScalarFilters(
- table, snapshot, partitionFilter, scalarFiles);
+ table, snapshot, partitionFilter, scalarFiles,
searchMode);
if (!optionalScanner.isPresent()) {
return Collections.emptyList();
}
diff --git a/paimon-core/src/test/java/org/apache/paimon/CoreOptionsTest.java
b/paimon-core/src/test/java/org/apache/paimon/CoreOptionsTest.java
index f6931d44a3..393356504e 100644
--- a/paimon-core/src/test/java/org/apache/paimon/CoreOptionsTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/CoreOptionsTest.java
@@ -204,6 +204,12 @@ public class CoreOptionsTest {
Options conf = new Options();
CoreOptions options = new CoreOptions(conf);
assertThat(options.globalIndexSearchMode()).isNull();
+ assertThat(CoreOptions.SCALAR_INDEX_SEARCH_MODE.defaultValue())
+ .isEqualTo(CoreOptions.GlobalIndexSearchMode.FULL);
+ assertThat(options.scalarScanSearchMode())
+ .isEqualTo(CoreOptions.GlobalIndexSearchMode.FULL);
+ assertThat(options.scalarPrefilterSearchMode())
+ .isEqualTo(CoreOptions.GlobalIndexSearchMode.FAST);
assertThat(options.scalarIndexSearchMode())
.isEqualTo(CoreOptions.GlobalIndexSearchMode.FAST);
assertThat(options.vectorIndexSearchMode())
@@ -213,6 +219,10 @@ public class CoreOptionsTest {
conf.set(CoreOptions.GLOBAL_INDEX_SEARCH_MODE,
CoreOptions.GlobalIndexSearchMode.DETAIL);
options = new CoreOptions(conf);
+ assertThat(options.scalarScanSearchMode())
+ .isEqualTo(CoreOptions.GlobalIndexSearchMode.DETAIL);
+ assertThat(options.scalarPrefilterSearchMode())
+ .isEqualTo(CoreOptions.GlobalIndexSearchMode.DETAIL);
assertThat(options.scalarIndexSearchMode())
.isEqualTo(CoreOptions.GlobalIndexSearchMode.DETAIL);
assertThat(options.vectorIndexSearchMode())
@@ -224,12 +234,25 @@ public class CoreOptionsTest {
conf.set(CoreOptions.VECTOR_INDEX_SEARCH_MODE,
CoreOptions.GlobalIndexSearchMode.FULL);
conf.set(CoreOptions.FULL_TEXT_INDEX_SEARCH_MODE,
CoreOptions.GlobalIndexSearchMode.FULL);
options = new CoreOptions(conf);
+ assertThat(options.scalarScanSearchMode())
+ .isEqualTo(CoreOptions.GlobalIndexSearchMode.FAST);
+ assertThat(options.scalarPrefilterSearchMode())
+ .isEqualTo(CoreOptions.GlobalIndexSearchMode.FAST);
assertThat(options.scalarIndexSearchMode())
.isEqualTo(CoreOptions.GlobalIndexSearchMode.FAST);
assertThat(options.vectorIndexSearchMode())
.isEqualTo(CoreOptions.GlobalIndexSearchMode.FULL);
assertThat(options.fullTextIndexSearchMode())
.isEqualTo(CoreOptions.GlobalIndexSearchMode.FULL);
+
+ conf.set(
+ CoreOptions.SCALAR_INDEX_PREFILTER_SEARCH_MODE,
+ CoreOptions.GlobalIndexSearchMode.FULL);
+ options = new CoreOptions(conf);
+ assertThat(options.scalarPrefilterSearchMode())
+ .isEqualTo(CoreOptions.GlobalIndexSearchMode.FULL);
+ assertThat(options.scalarScanSearchMode())
+ .isEqualTo(CoreOptions.GlobalIndexSearchMode.FAST);
}
@Test
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/BtreeGlobalIndexTableTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/BtreeGlobalIndexTableTest.java
index 76bc390724..4a2082cefc 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/BtreeGlobalIndexTableTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/BtreeGlobalIndexTableTest.java
@@ -59,6 +59,8 @@ import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.OutputStreamAppender;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
@@ -369,8 +371,7 @@ public class BtreeGlobalIndexTableTest extends
DataEvolutionTestBase {
createIndex("f1");
appendRows(100, 110);
- FileStoreTable table =
- tableWithSearchMode((FileStoreTable)
catalog.getTable(identifier()), "full");
+ FileStoreTable table = (FileStoreTable) catalog.getTable(identifier());
TopN topN =
new TopN(
new FieldRef(1, "f1", table.rowType().getTypeAt(1)),
@@ -585,11 +586,11 @@ public class BtreeGlobalIndexTableTest extends
DataEvolutionTestBase {
assertThat(logs)
.containsPattern(
"INFO Scan table '[^']+' with global index\\. "
- + "searchMode='fast', total=\\d+ ms,
metadata=\\d+ ms, "
+ + "searchMode='full', total=\\d+ ms,
metadata=\\d+ ms, "
+ "lookup=\\d+ ms, coverage=\\d+ ms\\.")
.containsPattern(
"INFO Scan table '[^']+' with BTree global index
TopN\\. "
- + "searchMode='fast', topN='[^']+',
total=\\d+ ms, "
+ + "searchMode='full', topN='[^']+',
total=\\d+ ms, "
+ "metadata=\\d+ ms, lookup=\\d+ ms,
coverage=\\d+ ms\\.")
.containsPattern(
"INFO Global index lookup table='[^']+',
type='btree', "
@@ -604,13 +605,20 @@ public class BtreeGlobalIndexTableTest extends
DataEvolutionTestBase {
}
}
- @Test
- public void testBTreeGlobalIndexSearchModeControlsUnindexedData() throws
Exception {
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ public void testBTreeGlobalIndexSearchModeControlsUnindexedData(boolean
queryInReader)
+ throws Exception {
write(500L);
createIndex("f1");
appendRows(500, 1000);
- FileStoreTable table = (FileStoreTable) catalog.getTable(identifier());
+ FileStoreTable table =
+ ((FileStoreTable) catalog.getTable(identifier()))
+ .copy(
+ Collections.singletonMap(
+
CoreOptions.GLOBAL_INDEX_QUERY_IN_READER_ENABLED.key(),
+ Boolean.toString(queryInReader)));
Predicate predicate =
new PredicateBuilder(table.rowType())
.in(
@@ -619,11 +627,15 @@ public class BtreeGlobalIndexTableTest extends
DataEvolutionTestBase {
BinaryString.fromString("a100"),
BinaryString.fromString("a700")));
- // Default scalar-index.search-mode is 'fast': only indexed rows are
- // returned, so the unindexed a700 is dropped.
- assertThat(readF1(table, predicate)).containsExactly("a100");
+ assertThat(readF1(table, predicate)).containsExactlyInAnyOrder("a100",
"a700");
assertThat(readF1(tableWithSearchMode(table, "fast"),
predicate)).containsExactly("a100");
+ FileStoreTable familyOverride =
+ tableWithSearchMode(table, "fast")
+ .copy(
+ Collections.singletonMap(
+
CoreOptions.SCALAR_INDEX_SEARCH_MODE.key(), "full"));
+ assertThat(readF1(familyOverride, predicate)).containsExactly("a100",
"a700");
assertThat(readF1(tableWithSearchMode(table, "full"), predicate))
.containsExactly("a100", "a700");
assertThat(readF1(tableWithSearchMode(table, "detail"), predicate))
@@ -635,8 +647,7 @@ public class BtreeGlobalIndexTableTest extends
DataEvolutionTestBase {
builder.equal(1, BinaryString.fromString("a700")),
builder.equal(2, BinaryString.fromString("b700")));
- // Default 'fast': a700 lives in the unindexed range, so it is dropped.
- assertThat(readF1(table, andWithUnindexedField)).isEmpty();
+ assertThat(readF1(table,
andWithUnindexedField)).containsExactly("a700");
assertThat(readF1(tableWithSearchMode(table, "fast"),
andWithUnindexedField)).isEmpty();
assertThat(readF1(tableWithSearchMode(table, "full"),
andWithUnindexedField))
.containsExactly("a700");
@@ -749,8 +760,7 @@ public class BtreeGlobalIndexTableTest extends
DataEvolutionTestBase {
builder.equal(1, BinaryString.fromString("a700")),
builder.equal(2, BinaryString.fromString("b700")));
- // Default 'fast': a700 is in the unindexed range, so it is dropped.
- assertThat(readF1(table, andPredicate)).isEmpty();
+ assertThat(readF1(table, andPredicate)).containsExactly("a700");
assertThat(readF1(tableWithSearchMode(table, "fast"),
andPredicate)).isEmpty();
assertThat(readF1(tableWithSearchMode(table, "full"), andPredicate))
.containsExactly("a700");
@@ -762,8 +772,7 @@ public class BtreeGlobalIndexTableTest extends
DataEvolutionTestBase {
builder.equal(1, BinaryString.fromString("a700")),
builder.equal(2, BinaryString.fromString("b701")));
- // Default 'fast': a700 is unindexed and dropped; a701 (f2 indexed)
stays.
- assertThat(readF1(table, orPredicate)).containsExactly("a701");
+ assertThat(readF1(table, orPredicate)).containsExactly("a700", "a701");
assertThat(readF1(tableWithSearchMode(table, "fast"),
orPredicate)).containsExactly("a701");
assertThat(readF1(tableWithSearchMode(table, "full"), orPredicate))
.containsExactly("a700", "a701");
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/IndexQuerySplitTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/IndexQuerySplitTest.java
index 5e2c6ffd1d..fc26f161ed 100644
--- a/paimon-core/src/test/java/org/apache/paimon/table/IndexQuerySplitTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/table/IndexQuerySplitTest.java
@@ -323,10 +323,10 @@ public class IndexQuerySplitTest extends
DataEvolutionTestBase {
ReadBuilder read =
distributedTable(table).newReadBuilder().withFilter(b.startsWith(1, str("a")));
List<Split> splits = read.newScan().plan().splits();
- assertThat(splits).hasSize(2).allMatch(split -> split instanceof
IndexQuerySplit);
+ assertThat(splits).hasSize(3).allMatch(split -> split instanceof
IndexQuerySplit);
// The first range still has both files needed for column merging.
assertThat(((IndexQuerySplit)
splits.get(0)).dataSplit().dataFiles()).hasSize(2);
- assertThat(read(read, splits)).hasSize(200);
+ assertThat(read(read, splits)).hasSize(300);
}
@ParameterizedTest
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/MultiValueGlobalIndexTableTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/MultiValueGlobalIndexTableTest.java
index f9a894f02c..7746b17933 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/MultiValueGlobalIndexTableTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/MultiValueGlobalIndexTableTest.java
@@ -97,13 +97,12 @@ public class MultiValueGlobalIndexTableTest extends
TableTestBase {
write(table, GenericRow.of(6, array(RED)));
table = getTableDefault();
- // Fast search only returns covered rows. Full search retains the
uncovered append.
- assertThat(readIds(table, containsRed)).containsExactlyInAnyOrder(1,
5);
- FileStoreTable fullSearchTable =
+ assertThat(readIds(table, containsRed)).containsExactlyInAnyOrder(1,
5, 6);
+ FileStoreTable fastSearchTable =
table.copy(
Collections.singletonMap(
- CoreOptions.GLOBAL_INDEX_SEARCH_MODE.key(),
"full"));
- assertThat(readIds(fullSearchTable,
containsRed)).containsExactlyInAnyOrder(1, 5, 6);
+ CoreOptions.GLOBAL_INDEX_SEARCH_MODE.key(),
"fast"));
+ assertThat(readIds(fastSearchTable,
containsRed)).containsExactlyInAnyOrder(1, 5);
}
private void buildIndex(FileStoreTable table) throws Exception {
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/source/FullTextSearchBuilderTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/source/FullTextSearchBuilderTest.java
index f43b7c590a..ce5e2266d4 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/source/FullTextSearchBuilderTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/source/FullTextSearchBuilderTest.java
@@ -603,6 +603,21 @@ public class FullTextSearchBuilderTest extends
TableTestBase {
GlobalIndexResult result = builder.newFullTextRead().read(plan);
assertThat(result.results()).containsExactlyInAnyOrder(1L, 2L, 3L, 4L,
5L);
+
+ FileStoreTable prefilterFast =
+ table.copy(
+ Collections.singletonMap(
+
CoreOptions.SCALAR_INDEX_PREFILTER_SEARCH_MODE.key(), "fast"));
+ assertThat(searchWithFilter(prefilterFast, idFilter, 10).results())
+ .containsExactlyInAnyOrder(1L, 2L);
+
+ ReadBuilder readBuilder =
prefilterFast.newReadBuilder().withFilter(idFilter);
+ List<Integer> ids = new ArrayList<>();
+ try (RecordReader<InternalRow> reader =
+
readBuilder.newRead().createReader(readBuilder.newScan().plan())) {
+ reader.forEachRemaining(row -> ids.add(row.getInt(0)));
+ }
+ assertThat(ids).containsExactlyInAnyOrder(1, 2, 3, 4, 5);
}
@Test
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/source/VectorSearchBuilderTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/source/VectorSearchBuilderTest.java
index 8d1478d772..2cb2264841 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/source/VectorSearchBuilderTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/source/VectorSearchBuilderTest.java
@@ -1577,6 +1577,13 @@ public class VectorSearchBuilderTest extends
TableTestBase {
reader.forEachRemaining(row -> ids.add(row.getInt(0)));
}
assertThat(ids).isEmpty();
+
+ Map<String, String> options = new HashMap<>();
+ options.put(CoreOptions.SCALAR_INDEX_SEARCH_MODE.key(), "fast");
+ options.put(CoreOptions.SCALAR_INDEX_PREFILTER_SEARCH_MODE.key(),
"full");
+ searchBuilder.withOptions(options);
+ vectorPlan = searchBuilder.newVectorScan().scan();
+
assertThat(searchBuilder.newVectorRead().read(vectorPlan).results()).containsExactly(8L);
}
@Test
diff --git a/paimon-python/pypaimon/common/options/core_options.py
b/paimon-python/pypaimon/common/options/core_options.py
index d85920ea39..052ed6757e 100644
--- a/paimon-python/pypaimon/common/options/core_options.py
+++ b/paimon-python/pypaimon/common/options/core_options.py
@@ -976,8 +976,18 @@ class CoreOptions:
SCALAR_INDEX_SEARCH_MODE: ConfigOption[GlobalIndexSearchMode] = (
ConfigOptions.key("scalar-index.search-mode")
.enum_type(GlobalIndexSearchMode)
+ .default_value(GlobalIndexSearchMode.FULL)
+ .with_description("Search mode for ordinary Data Evolution scalar
batch scans. An explicit "
+ "setting also serves as a fallback for scalar
prefilters.")
+ )
+
+ SCALAR_INDEX_PREFILTER_SEARCH_MODE: ConfigOption[GlobalIndexSearchMode] = (
+ ConfigOptions.key("scalar-index.prefilter.search-mode")
+ .enum_type(GlobalIndexSearchMode)
.default_value(GlobalIndexSearchMode.FAST)
- .with_description("Search mode for scalar index queries.")
+ .with_description("Search mode for scalar prefilters in vector and
full-text search. If unset, "
+ "use an explicit scalar-index.search-mode, then an
explicit "
+ "global-index.search-mode, then fast.")
)
VECTOR_INDEX_SEARCH_MODE: ConfigOption[GlobalIndexSearchMode] = (
@@ -1813,19 +1823,30 @@ class CoreOptions:
return self.options.get(CoreOptions.GLOBAL_INDEX_SEARCH_MODE)
def scalar_index_search_mode(self):
+ return self._family_index_search_mode(
+ CoreOptions.SCALAR_INDEX_SEARCH_MODE, GlobalIndexSearchMode.FAST)
+
+ def scalar_scan_search_mode(self):
return
self._family_index_search_mode(CoreOptions.SCALAR_INDEX_SEARCH_MODE)
+ def scalar_prefilter_search_mode(self):
+ option = CoreOptions.SCALAR_INDEX_PREFILTER_SEARCH_MODE
+ if self.options.to_map().get(option.key()) is not None:
+ return self.options.get(option)
+ return self._family_index_search_mode(
+ CoreOptions.SCALAR_INDEX_SEARCH_MODE, option.default_value())
+
def vector_index_search_mode(self):
return
self._family_index_search_mode(CoreOptions.VECTOR_INDEX_SEARCH_MODE)
def full_text_index_search_mode(self):
return
self._family_index_search_mode(CoreOptions.FULL_TEXT_INDEX_SEARCH_MODE)
- def _family_index_search_mode(self, option):
+ def _family_index_search_mode(self, option, default=None):
if self.options.contains(option):
- return self.options.get(option)
+ return self.options.get(option, default)
global_mode = self.global_index_search_mode()
- return global_mode if global_mode is not None else
self.options.get(option)
+ return global_mode if global_mode is not None else
self.options.get(option, default)
def global_index_external_path(self, default=None):
value = self.options.get(CoreOptions.GLOBAL_INDEX_EXTERNAL_PATH,
default)
diff --git
a/paimon-python/pypaimon/execution/native/read/native_full_text_search.py
b/paimon-python/pypaimon/execution/native/read/native_full_text_search.py
index 2ad37539a1..a24ac04285 100644
--- a/paimon-python/pypaimon/execution/native/read/native_full_text_search.py
+++ b/paimon-python/pypaimon/execution/native/read/native_full_text_search.py
@@ -23,7 +23,7 @@ from pypaimon.execution.native.table import (_native_table)
from pypaimon.execution.native.read.builder import (_predicate_to_native)
from pypaimon.execution.native.runtime import (native_runtime_available)
from pypaimon.table.file_store_table import FileStoreTable
-from pypaimon.execution.native.read.native_search_plan import _result
+from pypaimon.execution.native.read.native_search_plan import
_native_prefilter_options, _result
from pypaimon.execution.native.write.native_commit import
_rest_catalog_supported
@@ -45,7 +45,9 @@ def _native_full_text_builder(builder, require_limit=True):
raise NotImplementedError('Primary-key full-text search only supports
the FAST full-text index search mode')
if require_limit and (builder._limit is None or builder._limit <= 0):
raise ValueError('Limit must be positive, set via with_limit()')
- native = _native_table(table).new_full_text_search_builder()
+ options = _native_prefilter_options(table, {}) if builder._filter is not
None else {}
+ search_table = table.copy_without_time_travel(options) if options else
table
+ native = _native_table(search_table).new_full_text_search_builder()
if builder._field_name is not None and builder._query is not None:
native.with_query(builder._field_name, builder._query)
if builder._limit is not None:
diff --git
a/paimon-python/pypaimon/execution/native/read/native_hybrid_search.py
b/paimon-python/pypaimon/execution/native/read/native_hybrid_search.py
index 998c9adc21..a65bc369e9 100644
--- a/paimon-python/pypaimon/execution/native/read/native_hybrid_search.py
+++ b/paimon-python/pypaimon/execution/native/read/native_hybrid_search.py
@@ -21,6 +21,7 @@ from pypaimon.catalog.table_query_auth import
reject_search_under_query_auth
from pypaimon.globalindex.vector_search_result import
DictBasedScoredIndexResult
from pypaimon.execution.native.table import (_native_table, _options_to_native)
from pypaimon.execution.native.read.builder import (_predicate_to_native)
+from pypaimon.execution.native.read.native_search_plan import
_native_prefilter_options
from pypaimon.execution.native.runtime import (native_runtime_available)
from pypaimon.table.file_store_table import FileStoreTable
from pypaimon.execution.native.write.native_commit import
_rest_catalog_supported
@@ -42,15 +43,17 @@ def _native_builder(builder, executor=None):
builder._validate_search()
if executor is not None and not table.options.data_evolution_enabled():
raise ValueError('Distributed search supports only data-evolution
tables')
- native = _native_table(table).new_hybrid_search_builder()
+ options = _native_prefilter_options(table, {}) if builder._filter is not
None else {}
+ search_table = table.copy_without_time_travel(options) if options else
table
+ native = _native_table(search_table).new_hybrid_search_builder()
native.with_limit(builder._limit).with_ranker(builder._ranker)
for route in builder._routes:
- options = _options_to_native(route.options)
if route.is_vector():
+ options = _native_prefilter_options(table, route.options)
native.add_vector_route(route.field_name, route.vector,
route.limit, route.weight, options)
else:
native.add_full_text_route(
- route.field_name, route.full_text_query, route.limit,
route.weight, options)
+ route.field_name, route.full_text_query, route.limit,
route.weight, _options_to_native(route.options))
try:
if builder._partition_filter is not None:
native.with_partition_filter(_predicate_to_native(builder._partition_filter))
diff --git a/paimon-python/pypaimon/execution/native/read/native_search_plan.py
b/paimon-python/pypaimon/execution/native/read/native_search_plan.py
index 56d29ce63c..dba7b7127b 100644
--- a/paimon-python/pypaimon/execution/native/read/native_search_plan.py
+++ b/paimon-python/pypaimon/execution/native/read/native_search_plan.py
@@ -20,9 +20,10 @@
from copy import copy, deepcopy
from pypaimon.common.json_util import JSON
+from pypaimon.common.options.core_options import CoreOptions
from pypaimon.globalindex.vector_search_result import
DictBasedScoredIndexResult
from pypaimon.read.split_serializer import deserialize_split_v1,
serialize_split_v1
-from pypaimon.execution.native.table import (_partition_fields)
+from pypaimon.execution.native.table import _options_to_native,
_partition_fields
from pypaimon.snapshot.snapshot import Snapshot
from pypaimon.table.source.search_types import (
FullTextScanPlan, VectorSearchScanPlan,
@@ -34,6 +35,16 @@ from pypaimon.utils.range import Range
from pypaimon.write.commit_message_serializer import _index_from_row,
_index_row
+def _native_prefilter_options(table, options):
+ """Mirror the explicit prefilter mode for native runtimes with only the
legacy key."""
+ native_options = _options_to_native(options)
+ key = CoreOptions.SCALAR_INDEX_PREFILTER_SEARCH_MODE.key()
+ mode = native_options.get(key, table.options.options.to_map().get(key))
+ if mode is not None:
+ native_options[CoreOptions.SCALAR_INDEX_SEARCH_MODE.key()] = mode
+ return native_options
+
+
def _range(value):
return Range(*value)
diff --git
a/paimon-python/pypaimon/execution/native/read/native_vector_search.py
b/paimon-python/pypaimon/execution/native/read/native_vector_search.py
index 634edf9cb5..871a975673 100644
--- a/paimon-python/pypaimon/execution/native/read/native_vector_search.py
+++ b/paimon-python/pypaimon/execution/native/read/native_vector_search.py
@@ -19,10 +19,10 @@
from pypaimon.catalog.table_query_auth import reject_search_under_query_auth
from pypaimon.globalindex.vector_search_result import
DictBasedScoredIndexResult
-from pypaimon.execution.native.table import (_catalog_metastore,
_native_table, _options_to_native)
+from pypaimon.execution.native.table import (_catalog_metastore, _native_table)
from pypaimon.execution.native.read.builder import (_predicate_to_native)
from pypaimon.execution.native.runtime import (native_runtime_available)
-from pypaimon.execution.native.read.native_search_plan import _result
+from pypaimon.execution.native.read.native_search_plan import
_native_prefilter_options, _result
def _native_vector_builder(builder, batch=False):
@@ -49,7 +49,7 @@ def _native_vector_builder(builder, batch=False):
native_table.new_vector_search_builder())
if builder._vector_column is not None:
native.with_vector_column(builder._vector_column.name)
-
native.with_limit(builder._limit).with_options(_options_to_native(builder._options))
+
native.with_limit(builder._limit).with_options(_native_prefilter_options(table,
builder._options))
try:
if builder._filter is not None:
native.with_filter(_predicate_to_native(builder._filter))
diff --git a/paimon-python/pypaimon/execution/native/read/plan.py
b/paimon-python/pypaimon/execution/native/read/plan.py
index 357de9d4f2..a0848fe01c 100644
--- a/paimon-python/pypaimon/execution/native/read/plan.py
+++ b/paimon-python/pypaimon/execution/native/read/plan.py
@@ -69,8 +69,18 @@ def native_plan(
if not runtime.native_runtime_available():
raise RuntimeError(
"scan.native-plan.enabled needs the pypaimon-rust extension")
+ planning_table = table
+ if (predicate is not None and incremental_range is None
+ and row_ranges is None and global_index_result is None
+ and table.options.data_evolution_enabled() and
table.options.global_index_enabled()
+ and not
table.options.options.contains(CoreOptions.SCALAR_INDEX_SEARCH_MODE)
+ and not
table.options.options.contains(CoreOptions.GLOBAL_INDEX_SEARCH_MODE)):
+ # Released native runtimes may still default scalar scans to fast.
+ planning_table = table.copy_without_time_travel({
+ CoreOptions.SCALAR_INDEX_SEARCH_MODE.key():
table.options.scalar_scan_search_mode().value,
+ })
builder = native_builder._configure_native_read_builder(
- native_builder._native_read_builder(table), predicate, limit,
projection)
+ native_builder._native_read_builder(planning_table), predicate, limit,
projection)
if partition_predicate is not None:
builder =
builder.with_partition_filter(native_builder._predicate_to_native(partition_predicate))
if row_ranges is not None:
diff --git
a/paimon-python/pypaimon/execution/python/read/scanner/file_scanner.py
b/paimon-python/pypaimon/execution/python/read/scanner/file_scanner.py
index b565f2147c..39c037e9f0 100755
--- a/paimon-python/pypaimon/execution/python/read/scanner/file_scanner.py
+++ b/paimon-python/pypaimon/execution/python/read/scanner/file_scanner.py
@@ -571,7 +571,7 @@ class FileScanner:
evaluation = scanner.scan_with_coverage(predicate)
if evaluation is None:
return None
- scalar_mode = self.table.options.scalar_index_search_mode()
+ scalar_mode = self.table.options.scalar_scan_search_mode()
coverage_args = {}
if evaluation.indexed_ranges is not None:
coverage_args["indexed_ranges"] = evaluation.indexed_ranges
diff --git
a/paimon-python/pypaimon/execution/python/read/search/full_text_read.py
b/paimon-python/pypaimon/execution/python/read/search/full_text_read.py
index 530642a16a..f0fcf2f6a3 100644
--- a/paimon-python/pypaimon/execution/python/read/search/full_text_read.py
+++ b/paimon-python/pypaimon/execution/python/read/search/full_text_read.py
@@ -131,7 +131,7 @@ class DataEvolutionFullTextRead(FullTextRead):
snapshot = getattr(self, '_snapshot', None)
if snapshot is None:
snapshot = TimeTravelUtil.resolve_snapshot(self._table)
- mode = self._table.options.scalar_index_search_mode()
+ mode = self._table.options.scalar_prefilter_search_mode()
scalar_files = list(files.values())
coverage = DataEvolutionGlobalIndexCoverage(self._table, snapshot,
self._partition_filter, scalar_files)
raw_ranges = coverage.unindexed_ranges(self._table.fields,
self._filter, mode)
diff --git
a/paimon-python/pypaimon/execution/python/read/search/vector_search_read.py
b/paimon-python/pypaimon/execution/python/read/search/vector_search_read.py
index 7b54aaa966..915dde68fe 100644
--- a/paimon-python/pypaimon/execution/python/read/search/vector_search_read.py
+++ b/paimon-python/pypaimon/execution/python/read/search/vector_search_read.py
@@ -296,7 +296,7 @@ class AbstractVectorSearchReadImpl:
include_ranges.extend(
scanner.unindexed_ranges(
self._filter,
- search_mode=effective_core.scalar_index_search_mode(),
+ search_mode=effective_core.scalar_prefilter_search_mode(),
contributing_field_ids=(
evaluation.contributing_field_ids),
))
diff --git
a/paimon-python/pypaimon/execution/python/read/search/vector_search_scan.py
b/paimon-python/pypaimon/execution/python/read/search/vector_search_scan.py
index ad3c842425..726980c06f 100644
--- a/paimon-python/pypaimon/execution/python/read/search/vector_search_scan.py
+++ b/paimon-python/pypaimon/execution/python/read/search/vector_search_scan.py
@@ -177,7 +177,7 @@ class DataEvolutionVectorScan(VectorSearchScan):
).unindexed_ranges(
self._table.fields,
self._filter,
- search_mode=effective_core.scalar_index_search_mode(),
+ search_mode=effective_core.scalar_prefilter_search_mode(),
)
if vector_search_mode == GlobalIndexSearchMode.FAST:
scalar_unindexed_ranges = Range.and_(
diff --git a/paimon-python/pypaimon/multimodal/lerobot/reader.py
b/paimon-python/pypaimon/multimodal/lerobot/reader.py
index 5cb7d86511..8dfdb0e7f3 100644
--- a/paimon-python/pypaimon/multimodal/lerobot/reader.py
+++ b/paimon-python/pypaimon/multimodal/lerobot/reader.py
@@ -132,7 +132,7 @@ class _FrameLocator:
"frame index predicate.")
unindexed = scanner.unindexed_ranges(
predicate,
- search_mode=self._table.options.scalar_index_search_mode(),
+ search_mode=self._table.options.scalar_scan_search_mode(),
contributing_field_ids=evaluation.contributing_field_ids,
)
ranges = evaluation.result.results().to_range_list() + unindexed
diff --git a/paimon-python/pypaimon/table/source/vector_search_builder.py
b/paimon-python/pypaimon/table/source/vector_search_builder.py
index 9e8c501655..c20d7428d6 100644
--- a/paimon-python/pypaimon/table/source/vector_search_builder.py
+++ b/paimon-python/pypaimon/table/source/vector_search_builder.py
@@ -20,6 +20,7 @@
from abc import ABC, abstractmethod
from copy import copy
+from pypaimon.common.options.core_options import CoreOptions
from pypaimon.common.options.vector_index_options import VectorIndexOptions
from pypaimon.catalog.table_query_auth import reject_search_under_query_auth
from pypaimon.common.predicate_builder import PredicateBuilder
@@ -121,13 +122,15 @@ class AbstractVectorSearchBuilderImpl:
def with_option(self, key, value):
# type: (str, str) -> VectorSearchBuilder
- self._options[key] = value
- return self
+ return self.with_options({key: value})
def with_options(self, options):
# type: (dict) -> VectorSearchBuilder
if options is not None:
self._options.update(options)
+ prefilter_key =
CoreOptions.SCALAR_INDEX_PREFILTER_SEARCH_MODE.key()
+ if self._options.get(prefilter_key) is None:
+ self._options.pop(prefilter_key, None)
return self
def with_filter(self, predicate):
diff --git a/paimon-python/pypaimon/tests/global_index_build_test.py
b/paimon-python/pypaimon/tests/global_index_build_test.py
index dfdac43dbf..9f0b7c5b01 100644
--- a/paimon-python/pypaimon/tests/global_index_build_test.py
+++ b/paimon-python/pypaimon/tests/global_index_build_test.py
@@ -461,6 +461,24 @@ class GlobalIndexBuildTest(
self.assertEqual([2], rows.column('id').to_pylist())
self.assertEqual(0, table.create_global_index('name',
index_type=kind))
+ def test_scalar_scan_includes_unindexed_rows_by_default(self):
+ schema = pa.schema([('id', pa.int32()), ('name', pa.string())])
+ table = self._create_table(pa_schema=schema)
+ self._write_arrow(table, pa.table({'id': [1], 'name': ['match']},
schema=schema))
+ self.assertEqual(1, table.create_global_index('name'))
+ self._write_arrow(table, pa.table({'id': [2], 'name': ['match']},
schema=schema))
+
+ for options, expected in [
+ ({}, [1, 2]),
+ ({'global-index.search-mode': 'fast'}, [1]),
+ ({'global-index.search-mode': 'fast', 'scalar-index.search-mode':
'full'}, [1, 2]),
+ ]:
+ with self.subTest(options=options):
+ builder = table.copy(options).new_read_builder()
+
builder.with_filter(builder.new_predicate_builder().equal('name', 'match'))
+ result =
builder.new_read().to_arrow(builder.new_scan().plan().splits())
+ self.assertEqual(expected,
sorted(result.column('id').to_pylist()))
+
def test_create_btree_global_index_from_python(self):
table = self._create_table()
self._write_arrow(table, pa.table(
diff --git
a/paimon-python/pypaimon/tests/global_index_scalar_search_mode_test.py
b/paimon-python/pypaimon/tests/global_index_scalar_search_mode_test.py
index ae2485822b..0a9f72b73a 100644
--- a/paimon-python/pypaimon/tests/global_index_scalar_search_mode_test.py
+++ b/paimon-python/pypaimon/tests/global_index_scalar_search_mode_test.py
@@ -61,8 +61,13 @@ class ScalarGlobalIndexSearchModeTest(unittest.TestCase):
def test_default_values(self):
options = CoreOptions(Options.from_none())
self.assertIsNone(options.global_index_search_mode())
+ self.assertEqual(GlobalIndexSearchMode.FULL,
CoreOptions.SCALAR_INDEX_SEARCH_MODE.default_value())
+ self.assertEqual(
+ GlobalIndexSearchMode.FULL, options.scalar_scan_search_mode())
self.assertEqual(
GlobalIndexSearchMode.FAST, options.scalar_index_search_mode())
+ self.assertEqual(
+ GlobalIndexSearchMode.FAST, options.scalar_prefilter_search_mode())
self.assertEqual(
GlobalIndexSearchMode.FAST, options.vector_index_search_mode())
self.assertEqual(
@@ -71,7 +76,9 @@ class ScalarGlobalIndexSearchModeTest(unittest.TestCase):
def test_legacy_global_mode_is_family_fallback(self):
options = CoreOptions(Options({"global-index.search-mode": "detail"}))
for getter in (
+ options.scalar_scan_search_mode,
options.scalar_index_search_mode,
+ options.scalar_prefilter_search_mode,
options.vector_index_search_mode,
options.full_text_index_search_mode):
self.assertEqual(GlobalIndexSearchMode.DETAIL, getter())
@@ -83,13 +90,26 @@ class ScalarGlobalIndexSearchModeTest(unittest.TestCase):
"vector-index.search-mode": "full",
"full-text-index.search-mode": "fast",
}))
+ self.assertEqual(
+ GlobalIndexSearchMode.FAST, options.scalar_scan_search_mode())
self.assertEqual(
GlobalIndexSearchMode.FAST, options.scalar_index_search_mode())
+ self.assertEqual(
+ GlobalIndexSearchMode.FAST, options.scalar_prefilter_search_mode())
self.assertEqual(
GlobalIndexSearchMode.FULL, options.vector_index_search_mode())
self.assertEqual(
GlobalIndexSearchMode.FAST, options.full_text_index_search_mode())
+ def test_prefilter_mode_overrides_legacy_modes_for_search_only(self):
+ options = CoreOptions(Options({
+ "global-index.search-mode": "fast",
+ "scalar-index.search-mode": "full",
+ "scalar-index.prefilter.search-mode": "detail",
+ }))
+ self.assertEqual(GlobalIndexSearchMode.DETAIL,
options.scalar_prefilter_search_mode())
+ self.assertEqual(GlobalIndexSearchMode.FULL,
options.scalar_scan_search_mode())
+
def test_coverage_honours_search_mode_override(self):
coverage = _coverage(CoreOptions(Options.from_none()))
self.assertEqual(
diff --git a/paimon-python/pypaimon/tests/global_index_test.py
b/paimon-python/pypaimon/tests/global_index_test.py
index 95dcf736bd..0a2956d48d 100644
--- a/paimon-python/pypaimon/tests/global_index_test.py
+++ b/paimon-python/pypaimon/tests/global_index_test.py
@@ -421,7 +421,7 @@ class GlobalIndexScalarFallbackTest(unittest.TestCase):
def global_index_enabled(self):
return True
- def scalar_index_search_mode(self):
+ def scalar_scan_search_mode(self):
return GlobalIndexSearchMode.FULL
class _Table:
diff --git a/paimon-python/pypaimon/tests/lerobot_native_reader_test.py
b/paimon-python/pypaimon/tests/lerobot_native_reader_test.py
index 40e3f7e2aa..4f49b22e1c 100644
--- a/paimon-python/pypaimon/tests/lerobot_native_reader_test.py
+++ b/paimon-python/pypaimon/tests/lerobot_native_reader_test.py
@@ -171,13 +171,18 @@ def
test_native_plan_failure_reuses_scanner_and_keeps_predicate(frames):
{"read.native.enabled": "false"},
{"scan.native-plan.enabled": "false"},
])
-def test_explicit_python_lookup_is_preserved(frames, options):
- current = reader(frames, **options)
[email protected]("scalar_options, expected", [
+ ({}, [2, 4]),
+ ({"scalar-index.search-mode": "fast"}, [2]),
+])
+def test_explicit_python_lookup_is_preserved(frames, options, scalar_options,
expected):
+ frames.add(pa.table({"index": [40, 50], "value": [4, 5]}))
+ current = reader(frames, **options, **scalar_options)
try:
assert not current._table.options.native_read_enabled()
with patch.object(current._locator, "locate",
wraps=current._locator.locate) as locate:
- assert current.read_indices([20], ["value"])["value"].to_pylist()
== [2]
- locate.assert_called_once_with([20])
+ assert sorted(current.read_indices([20, 40],
["value"])["value"].to_pylist()) == expected
+ locate.assert_called_once_with([20, 40])
finally:
current.close()
diff --git a/paimon-python/pypaimon/tests/native_full_text_search_test.py
b/paimon-python/pypaimon/tests/native_full_text_search_test.py
index 36cc51c186..2cd1b87d8a 100644
--- a/paimon-python/pypaimon/tests/native_full_text_search_test.py
+++ b/paimon-python/pypaimon/tests/native_full_text_search_test.py
@@ -116,6 +116,18 @@ def
test_scalar_filter_modes_before_full_text_top_k(rest_catalog, text_mode, sca
assert indexes._ids(table) == list(range(12))
[email protected]('prefilter_mode, scalar_mode, expected', [
+ ('fast', 'full', set()), ('full', 'fast', {1, 5, 7}), ('detail', 'fast',
{1, 5, 7}),
+])
+def test_prefilter_mode_overrides_legacy_scalar_mode(rest_catalog,
prefilter_mode, scalar_mode, expected):
+ catalog, _ = rest_catalog
+ table = _table(catalog, {'full-text-index.search-mode': 'fast',
+ 'scalar-index.search-mode': scalar_mode,
+ 'scalar-index.prefilter.search-mode':
prefilter_mode})
+ predicate =
table.new_read_builder().new_predicate_builder().equal('label', 'keep')
+ assert set(_compare(table, predicate=predicate)) == expected
+
+
@pytest.mark.parametrize('refine', [False, True])
@pytest.mark.parametrize('scalar_mode', ['fast', 'full', 'detail'])
@pytest.mark.parametrize('index_type', ['btree', 'bitmap'])
diff --git a/paimon-python/pypaimon/tests/native_hybrid_search_test.py
b/paimon-python/pypaimon/tests/native_hybrid_search_test.py
index ef7a980437..e30b3559fe 100644
--- a/paimon-python/pypaimon/tests/native_hybrid_search_test.py
+++ b/paimon-python/pypaimon/tests/native_hybrid_search_test.py
@@ -130,6 +130,21 @@ def
test_partial_coverage_and_scalar_modes_apply_to_each_route(rest_catalog, mod
assert indexes._ids(table) == list(range(12))
+def test_prefilter_mode_includes_uncovered_rows_in_hybrid_search(rest_catalog):
+ catalog, _ = rest_catalog
+ table = _table(catalog, {'vector-index.search-mode': 'fast',
'full-text-index.search-mode': 'fast',
+ 'scalar-index.search-mode': 'fast',
'scalar-index.prefilter.search-mode': 'full'},
+ indexed=False)
+ table.create_global_index('label', index_type='btree')
+ indexes._append(table, _rows(8, 4), schema=SCHEMA)
+ table.create_global_index('content', index_type='full-text')
+ table.create_global_index('embedding', index_type='ivf-flat', options={
+ 'ivf-flat.dimension': '2', 'ivf-flat.nlist': '1',
'ivf-flat.distance.metric': 'l2'})
+
+ predicate =
table.new_read_builder().new_predicate_builder().equal('label', 'keep')
+ assert set(_compare(table, predicate=predicate)) == {1, 5, 7, 9, 11}
+
+
@pytest.mark.parametrize('index_type', ['btree', 'bitmap'])
@pytest.mark.parametrize('refine', [False, True])
def test_candidate_refinement_uses_java_semantics_in_both_routes(rest_catalog,
index_type, refine):
diff --git a/paimon-python/pypaimon/tests/native_index_options_test.py
b/paimon-python/pypaimon/tests/native_index_options_test.py
index 93175a52b2..34937ebaf6 100644
--- a/paimon-python/pypaimon/tests/native_index_options_test.py
+++ b/paimon-python/pypaimon/tests/native_index_options_test.py
@@ -117,8 +117,11 @@ def
test_distinct_scalar_field_options_reach_native_scan(tmp_path, streaming):
assert native_stream_scan(table, predicate=predicate) is
bridge.return_value.new_stream_scan.return_value
else:
assert native_plan(table, predicate=predicate) is
convert.return_value
- bridge.assert_called_once_with(table)
- options = json.loads(_resolved_schema_json(table))['options']
+ bridge.assert_called_once()
+ planned, = bridge.call_args[0]
+ options = json.loads(_resolved_schema_json(planned))['options']
+ assert options.get('scalar-index.search-mode') == (None if streaming else
'full')
+ assert 'scalar-index.search-mode' not in table.table_schema.options
assert options['fields.amount.index-options'] !=
options['fields.other.index-options']
diff --git a/paimon-python/pypaimon/tests/native_vector_search_test.py
b/paimon-python/pypaimon/tests/native_vector_search_test.py
index f81d2eb632..9c85c6b5c2 100644
--- a/paimon-python/pypaimon/tests/native_vector_search_test.py
+++ b/paimon-python/pypaimon/tests/native_vector_search_test.py
@@ -571,6 +571,25 @@ def
test_unsupported_conjunct_on_same_indexed_field_is_not_exact(rest_catalog, m
assert len(_rows(native, _single(native,
limit=2).with_filter(is_null).execute_local())) == 1
[email protected]('table_mode, query_options', [
+ ('full', {}),
+ ('fast', {'scalar-index.prefilter.search-mode': 'full'}),
+ ('full', {'scalar-index.prefilter.search-mode': None}),
+])
+def test_prefilter_mode_includes_uncovered_scalar_rows(vector_table,
table_mode, query_options):
+ vector_table.create_global_index('id', index_type='btree')
+ _write(vector_table, [{'id': 7, 'embedding': [3, 3], 'pt': 1}])
+ vector_table.create_global_index('embedding', index_type='ivf-flat',
options={
+ 'ivf-flat.dimension': '2', 'ivf-flat.nlist': '1',
'ivf-flat.distance.metric': 'l2'})
+ table = vector_table.copy({'vector-index.search-mode': 'fast',
'scalar-index.search-mode': 'fast',
+ 'scalar-index.prefilter.search-mode':
table_mode})
+ predicate = table.new_read_builder().new_predicate_builder().equal('id', 7)
+ for native in ['false', 'true']:
+ read_table = table.copy({'read.native.enabled': native,
'scan.native-plan.enabled': native})
+ builder = _single(read_table, [3, 3],
10).with_filter(predicate).with_options(query_options)
+ assert _rows(read_table,
builder.execute_local()).column('id').to_pylist() == [7]
+
+
@pytest.mark.parametrize('scalar_mode', ['fast', 'full', 'detail'])
@pytest.mark.parametrize('vector_mode', ['fast', 'full', 'detail'])
@pytest.mark.parametrize('vector_covers_tail', [False, True])
diff --git
a/paimon-spark/paimon-spark-4.1/src/test/scala/org/apache/paimon/spark/sql/GeospatialTypeSQLTest.scala
b/paimon-spark/paimon-spark-4.1/src/test/scala/org/apache/paimon/spark/sql/GeospatialTypeSQLTest.scala
index 3a19a0a196..c022068304 100644
---
a/paimon-spark/paimon-spark-4.1/src/test/scala/org/apache/paimon/spark/sql/GeospatialTypeSQLTest.scala
+++
b/paimon-spark/paimon-spark-4.1/src/test/scala/org/apache/paimon/spark/sql/GeospatialTypeSQLTest.scala
@@ -200,10 +200,11 @@ class GeospatialTypeSQLTest extends PaimonSparkTestBase {
.takeWhile(_ != null)
.exists(e => Option(e.getMessage).exists(_.contains("same SRID"))))
- // A matching append outside the published index distinguishes an
indexed fast scan
- // from a full scan. Full mode must also find the newly appended
geometry.
+ // The default scan includes a matching append outside the published
index.
sql(s"INSERT INTO t VALUES (5, $point)")
val select = s"SELECT id FROM t WHERE ST_Intersects(geom, $point)"
+ checkAnswer(sql(select), Seq(Row(2), Row(5)))
+ sql("ALTER TABLE t SET TBLPROPERTIES ('scalar-index.search-mode' =
'fast')")
checkAnswer(sql(select), Seq(Row(2)))
sql("ALTER TABLE t SET TBLPROPERTIES ('scalar-index.search-mode' =
'full')")
checkAnswer(sql(select), Seq(Row(2), Row(5)))