Skip to content

[feature](paimon) Add SQL and TVF ANN search with Paimon 2.1 - #69493

Open
pzhdfy wants to merge 28 commits into
apache:branch-4.2from
pzhdfy:branch-4.2-paimon-rust-ann
Open

pzhdfy wants to merge 28 commits into
apache:branch-4.2from
pzhdfy:branch-4.2-paimon-rust-ann

Conversation

@pzhdfy

@pzhdfy pzhdfy commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Related PRs: #66227, #69343, #70075

Upgrade branch-4.2 to Paimon Java 2.1.0 and paimon-rust 0.5.0-rc1, and add primary-key vector search through ordinary SQL and the shared vector_search TVF.

  • Align Java SDK compatibility with master: preserve nullable-key MERGE matched updates/deletes, reject unsupported latest-delta OPTIONS, and adapt removed APIs and SDK schema/timestamp behavior.
  • Push down ORDER BY l2_distance_approximate(...) ASC and inner_product_approximate(...) DESC LIMIT ... to eligible Paimon Rust scans. Preserve ordinary execution when the existing planner guards decline.
  • Dispatch the shared vector_search interface to Paimon while retaining Lance's provider. Support matching VECTOR<FLOAT> PK indexes with L2 and inner-product metrics.
  • Return squared L2 or negative inner product as TVF _distance, with one global TopN/offset after merging bucket candidates. Ordinary SQL distance functions retain their existing units.
  • Keep outer WHERE/default filter as postfilters; apply explicit prefilter=true before candidate selection. Normalize retained predicates and preserve their descriptor dependencies through column pruning.
  • Implement use_index=false with FULL mode in the serialized table schema and no ANN index sources in bucket payloads, preserving all planned data files and row ranges.
  • Reject catalog initialization when both legacy user.sys and privilege.sys markers exist. Run the checks and rejected-catalog cleanup in the authentication context; propagate metadata access errors instead of silently bypassing removed ACLs.
  • Preserve SQL distance validation by declining ANN pushdown for nullable vector fields, including historical schemas where the same field was nullable or absent. Use Paimon's actual schema constraints; Doris external-column nullability alone does not establish eligibility. The TVF retains its explicit search semantics.
  • Restore the shared regression comparator's original behavior. Normalize schema-declared binary leaves explicitly in the Paimon consistency suite, preserving hex-looking VARCHAR values and all byte values.
  • Use optional compatible Thrift fields; reserve the Paimon payload layout on master via merged [chore](paimon) Upgrade paimon-rust and reserve ANN Thrift fields #70075.

Example:

SELECT id, _distance
FROM vector_search(
    'table' = 'paimon_catalog.demo.items',
    'column' = 'embedding',
    'query_vector' = '[0.1, 0.2, 0.3]',
    'metric' = 'l2',
    'top_k' = '10'
)
ORDER BY _distance;

Validation

Current head: 211eab204f3.

Current functional fixes:

  • run-fe-ut.sh --coverage: FE main/test compilation and Checkstyle passed; 151 tests across PaimonCatalogCompatibilityTest, PaimonExternalMetaCacheTest, PushDownVectorTopNIntoPaimonScanTest and PaimonVectorSearchTableValuedFunctionTest passed with no failures/errors/skips.
  • Coverage includes ordinary and legacy ACL warehouses, wrappers, metadata/close failures, authentication context, SQL L2/IP nullable vectors, historical nullable/missing vector fields, and a non-nullable positive control independent of Doris external nullability.
  • Current regression framework rebuilt and packaged: 51 unit tests passed. New negative cases prevent plain or nested 0x41 and A from comparing equal, while actual byte arrays and explicitly encoded bytes remain comparable.
  • ANN and Spark/Doris consistency suites passed dry-run: 2 suites, 0 failures/fatal errors/skips. After completing the NULL fixture's deletion-vector options, its dry-run passed again (1 suite, 0 failures). External Doris/Spark end-to-end execution remains pending; dry-run does not execute those queries.
  • SDK 2.1 metadata probe successfully created nullable and NOT NULL VECTOR<FLOAT,16> primary-key tables with partial-update/deletion-vector options. The probe also enabled the PK-vector index options through ALTER. This checks schema/options acceptance, not Spark writes or index building.
  • Local Doris code-review skill review updated with individual conclusions for all 17 critical checkpoints. git diff --check passed for the current fixes.

Earlier complete validation at ada008c4ba5 (native/JNI sources are unchanged by the current fixes):

  • Full FE and all BE Java extensions built with JDK 17 and zero Checkstyle violations. Focused FE/JNI tests: 511 distinct cases in 23 classes passed across the initial run and targeted rerun.
  • Full Clang ASAN/UBSAN BE build, link, installation and CDC packaging passed using BUILD_TYPE=ASAN EXTRA_CXX_FLAGS='-Xclang -debug-info-kind=line-tables-only' DORIS_TOOLCHAIN=clang DISABLE_BE_JAVA_EXTENSIONS=ON ./build.sh --be -j 8. doris_be --version passed with the standard JNI/HDFS library paths.
  • build-support/check-format.sh passed for 4,899 C/C++ files with clang-format 16. BE reader and predicate-converter test sources passed syntax compilation with standard UT options; the full BE gtest binary has not been run.
  • Java 2.1 → Rust 0.5 wire probe decoded indexed and exact bucket payloads with indexed/unindexed files and row ranges, and rejected truncated payloads. This did not read physical files.
  • The ANN, SDK 2.1 compatibility and nullable-key MERGE suites passed dry-run (3 suites). SDK compatibility regression result files were imported from master [improvement](fe) Upgrade Paimon to 2.1.0 #69343.

Compatibility and remaining limitation

  • Mixed-version compatibility requires a query error instead of a process crash; query functionality during rolling upgrades is not guaranteed. The generic Rust-reader bit does not negotiate ANN separately: an older BE can reject the new ANN request with an empty-split error. Old-FE serialized privilege wrappers can fail in the upgraded JNI SDK with an explicit upgrade error. These error paths were inspected; a real mixed-version cluster has not been exercised locally.
  • Paimon 2.1 removes upstream legacy file-based privileges. Catalog initialization now rejects warehouses containing the old ACL metadata; authorization must be migrated before those warehouses can be used.
  • SQL ANN requires the vector field to be NOT NULL in the current and historical schemas. Otherwise ordinary execution preserves the distance function's NULL error behavior.
  • Rust vector eager materialization memory budgeting remains deferred from this functional work.

Release note

Upgrade Paimon Java to 2.1.0 and paimon-rust to 0.5.0-rc1. Add Paimon SQL ANN pushdown and vector_search TVF support, including exact searches with use_index=false. Fix matched MERGE updates/deletes for NULL primary keys and reject unsupported latest-delta OPTIONS.

Deployments using Paimon's removed legacy file-based privilege system must migrate authorization before upgrading; affected catalogs are explicitly rejected. SQL ANN pushdown preserves ordinary NULL validation by requiring NOT NULL vector schemas, including their history.

Check List (For Author)

  • Unit tests and regression coverage added or adapted
  • Local compilation and focused test verification complete (external end-to-end regression remains pending)
  • Local Doris code-review skill review complete (compatibility policy and deferred memory limitation described above)
  • Behavior changed: Yes; SDK upgrade and Paimon ANN/TVF search.
  • Documentation: interface and compatibility restrictions described above.

dengfangyuan and others added 8 commits October 22, 2026 16:29
…the FE off the removed privilege package

Paimon 2.1 removes the privilege package the Doris FE paimon path depended
on; this swaps the dependency to the 2.1-community-release line and ports
the FE references to the replacement API surface.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…stack

Order-by-distance pushdown over the PK-vector index (l2 / inner_product
metrics), executed exclusively by the BE paimon-rust reader:

- FE: PushDownVectorTopNIntoPaimonScan rewrite (bounded TopN -> index-only
  scan with the __paimon_search_score_to_dis synthetic output column) and
  the AnnTopNInfo / vector payload plumbing down to the split.
- Rust eligibility gates: the vector capability bit is negotiated separately
  from the batch rust bit (a vector payload rides an empty paimon_split,
  which an older rust-capable BE would reject), the table/storage/backend
  gates are unified between the batch and vector paths, raw-convertible
  compacted splits skip the merge-reader gates, and the rewrite pre-flights
  the gate because a vector split has no JNI fallback.
- BE: the paimon-rust vector reader mode (bucket vector search split
  deserialization, score-to-distance transform, synthetic column fill).
- Housekeeping caught by the port: clang-format of the ANN reader files,
  FileSystemSchemaManager in the rust reader schema tests, the privilege
  references the 2.1 port missed, and a docs note that read.batch-size is
  currently a no-op on the PK-vector path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Conflicts:
	fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/source/PaimonScanNode.java
	fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalFileScan.java
…s and adapt the test suites

Finalization of the 2.1 stack switch:

- Pin the Paimon dependency to the released community 2.1.0 (identical
  content to the snapshot it replaces).
- Mirror the s3.* credentials into the catalog options: the 2.1 SDK's
  S3FileIO reads credentials from CatalogContext.options() where the
  previous version picked up the endpoint-scoped properties.
- Regression suites: a new end-to-end suite for the PK-vector ANN path
  (rust vs brute-force differential legs), adaptation of the write suites
  and fixtures to the 2.1 SDK / Spark behaviors, and the before-epoch
  timestamp-to-date expectation for 2.1.0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…review)

Addresses the P1/P2 review findings on PushDownVectorTopNIntoPaimonScan:

P1 - Keep residual filtering before the bounded vector top-N. The BE
paimon-rust predicate converter skips conjuncts it cannot represent
(and the synthetic distance column is outside its field registry), and
the engine re-applies those residuals on the returned block -- after the
top-K rows were already selected. With candidate distances 0, 2 and 3,
a `WHERE dis > 1 ORDER BY dis LIMIT 1` fetched only the distance-0 row
and returned nothing. The rewrite now fires with a Filter only when
every conjunct provably rides into the vector search: a comparison / IN /
null-check on a table column whose Doris type is in the converter's
supported set (mirrors PaimonRustPredicateConverter._is_supported_slot_type).
Anything else declines the rewrite and the query computes the distance
in Doris, which is always correct. Verified end to end: the differential
leg caught the empty result on the unfixed build and passes on the
fixed one.

P1 - Do not strip value-changing casts from the indexed vector. A legal
cast chain can change vector values (an ARRAY<FLOAT> -> ARRAY<INT> ->
ARRAY<FLOAT> round trip loses precision), so searching the original
vectors while the query means the casted ones changes the ranking. The
rewrite now accepts a direct indexed column slot only.

P1 - Preserve the relation's file-creation-time restriction on the
vector path. The ordinary path drops manifest entries older than the
bound, but the PK-vector search plans its own splits and never consults
the bound, so old files' nearest neighbors could leak into the result. A
scan carrying scan.file-creation-time-millis now declines the rewrite
(snapshot / tag / version selectors are resolved into the table before
the vector search and stay eligible).

P2 - Check the projection capabilities before committing the rewrite. A
PK-vector split has no JNI fallback, so a query whose projected columns
would set the projectedVariant bound (nested Variant) or an ORC table
with TIMESTAMP_LTZ in its schema -- both scan-node bounds with no
vector-path fallback -- would turn a supported query into an error.
Both are now pre-flighted and decline instead, keeping the query on an
ordinary supported path.

Tests: PushDownVectorTopNIntoPaimonScanTest grows from 20 to 27 cases
(distance-predicate / unsupported-type / expression filters decline, a
simple column filter still rides, file-creation-time declines while a
snapshot selector does not, lossy cast declines, Variant projection
declines; the two distance-predicate positives flip to the new sound
semantics). The ANN regression suite adds the requested differential
legs: a distance lower bound, an unconvertible ARRAY<FLOAT> predicate
and a file-creation-time bound, each compared against the rust-disabled
brute force.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Replace the 3.1.4-SNAPSHOT dependency with its release build. The 4.1.0
artifact is byte-identical to the snapshot it replaces (same class list
and file sizes, same shaded paimon 2.1.0 / hive 3.1.3, identical pom
dependency declarations), so this only pins the FE build to a stable
release version.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…NN path

Static review of this PR surfaced twelve soundness and compatibility
gaps on the PK-vector (ANN) search path; every one was verified against
the pinned sources before the fix:

- Wire protocol: TPaimonFileDesc.vector_payload moves from field 20 to
  21 and TFileScanRangeParams.external_search_request from 41 to 42 --
  both IDs are already reserved on master (original_file_path,
  fluss_properties), and reusing them would make a mixed-version cluster
  drop the payload instead of decoding it. BE/FE must upgrade together.
- Vector capability negotiation: a new heartbeat bit
  supports_paimon_rust_vector_reader (TBackendInfo field 12, free on all
  branches) gates the one-way rewrite separately from the batch rust
  bit, so a rolling upgrade keeps ordinary rust reads working and only
  declines the vector rewrite against older BEs.
- Partitioned vector splits now carry the derived partition values
  (PaimonSplit.setPaimonPartitionValues), which setPaimonParams demands
  for any table with partition keys.
- The rewrite pre-flight now also declines: a query vector containing a
  NULL element (getDouble() would silently search a zero coordinate
  while the un-rewritten function raises); scan.creation-time-millis
  (resolves into the same internal file-creation bound the vector search
  never consults); a data predicate on a table without deletion vectors
  or with merge-on-read (paimon-rust rejects it AFTER the one-way
  rewrite); a table column named __paimon_search_score_to_dis (collides
  with the synthetic distance slot); and an expression over a complex
  column (nested pruning reduces the scan tuple while the vector reader
  projects only root names -- the struct SerDe then binds children by
  ordinal). The shape whitelist additionally rejects NullLiteral
  operands: the BE converter rejects a null literal and with it the
  whole predicate, leaving it in the post-fetch residual. The scan node
  keeps the nested-projection bound as a loud backstop for vector
  splits and logs the vector-capability reason.
- BE: _convert_score_to_distance maps zero and out-of-range scores to
  +inf instead of negative sentinels -- a zero score is reachable from a
  genuine huge distance (the search-mode=full exact fallback computes
  squared L2 in f32), and -2 sorted ahead of every finite distance,
  inverting the coordinator's TopN. _build_read_columns skips the
  synthetic distance name only in vector mode, so an ordinary scan of a
  real column with that name keeps reading it. The BE test include path
  is fixed (the file never compiled).
- Regression framework: the 0x-token decode pass only substitutes
  UTF-8-round-trippable bytes and keeps the lossless hex token otherwise
  -- replacement-character decoding made 0x80 and 0x81 compare equal.

Verified: FE UT 36/36 (rewrite) + 96/0 (scan node) + 22/22 (rust
compat) + 4/4 (capability); BE UT 30/30; the full ANN regression suite
including the four new differential legs (no-deletion-vector first-row
table, partitioned table, NULL query vector, IN with a NULL option).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Six new findings, all verified and fixed:

- Branch identity: the pre-flight resolved the cached main table while the
  scan reads the relation's bound branch table, so a branch with a different
  index metric scored and reordered with the wrong metric. All four
  pre-flight sites now resolve the bound table (relation snapshot, or the
  options-applied table for t@options); time-travel relations benefit too.
- Historical scalar evolution: the vector path skipped the batch reader's
  per-file schema gate, so a TIMESTAMP(3)->(9) widening would NULL
  out-of-range values through Arrow's safe cast. The rewrite now declines
  any rust-incompatible schema history, and the scan node re-checks per
  split (loud backstop mirroring the pre-flight exactly).
- Generic mapping exception: FileQueryScanNode skipped the synthetic
  distance name for every external catalog, breaking real same-named Hive
  columns; the skip now applies only when the schema has no such column.
- Nonmovable projection: a NoneMovableFunction (assert_true) in the ANN
  project must keep evaluating below the TopN; any nonmovable expression
  outside the order-key alias now declines the rewrite.
- Pruned bare slot: a bare complex slot whose type was already reduced by
  nested pruning now declines (slot type must still equal the original
  column's), instead of tripping the desc-side guard loudly.
- IN beyond the converter cap: the whitelist mirrors the BE converter's
  16-bit child count, so a raised expr_children_limit no longer drops the
  predicate into the post-fetch residual.

Carried P1 threads closed at their narrowed edges: the pinned-empty
generation is fenced in getVectorSearchSplits exactly like the ordinary
path (a first commit after binding is no longer readable by vector
planning), and the pruned-bare-slot / IN-cap cases above.

The stored-NULL differential is kept as a documented limitation: a
nullability-based decline cannot ship until PaimonExternalTable.loadSchema
stops hardcoding isAllowNull=true (today every paimon column, even PK
columns, maps as nullable, so the gate would disable the rewrite for every
table). Follow-ups recorded in the review thread.

Tests: rewrite rule 36 -> 42 cases, PaimonScanNode +3 (fence twin, loud
per-file backstop, schemaId-matching encode); the ANN e2e suite stays
green with a new assert_true error-parity leg. BE untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- Paimon 2.1 turned SchemaManager into an interface; the connector test
  moves to the FileSystemSchemaManager default implementation.
- The LogicalFileScan conflict resolution missed a blank line between
  constructors (checkstyle).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@pzhdfy
pzhdfy requested a review from yiguolei as a code owner October 23, 2026 02:35
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@Gabriel39

Copy link
Copy Markdown
Contributor

/review

@Gabriel39

Copy link
Copy Markdown
Contributor

run buildall

Comment thread gensrc/thrift/HeartbeatService.thrift Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review of #69493 at 8fd3bec. Six verified P2 findings are inline: stored-NULL error suppression, missing TIMESTAMP_NS preflight, reserved materializer names, an overbroad nested-distance exemption, retained ORC/LTZ files, and loss of literal-string identity in the shared regression oracle.

Critical checkpoints:

  1. Goal and behavior: the SDK upgrade and PK-vector ANN path are connected from Nereids through split serialization to Rust. The six findings prevent full correctness/compatibility; new tests do not cover these inputs.
  2. Scope and clarity: changes span all 61 authoritative paths; the shared eligibility refactor is relevant. The regression helper affects comparisons beyond ANN and needs the inline correction.
  3. Concurrency: no new threads or lock order; Backend capability fields are volatile and heartbeat/replay updates were traced. Scan-local and split-local ownership examined; no additional concrete race found.
  4. Lifecycle/static initialization: C ABI setters copy inputs, filters transfer ownership, returned streams own required state, and RAII handles/Arrow callbacks cover examined error paths. No new cross-translation-unit static dependency identified.
  5. Configuration: existing Rust-reader and FileScannerV2 session switches gate the rewrite; no new dynamic configuration item.
  6. Compatibility: Java Paimon 1.4.2 -> 2.1.0 and Hive shade 3.1.3 -> 4.1.0 reviewed, including VECTOR/JNI physical layout, removed privilege wrapper, S3 options and retained schema/file compatibility. Inline findings cover remaining proven input-shape failures.
  7. Thrift: touched definitions compared with master and branch-4.2/4.1/4.0/3.1. Added IDs 12/21/6/42 avoid collisions, including master reservations 20/41. Required members are inside a new optional, capability-gated payload type; no old-sender required-field failure demonstrated.
  8. Parallel paths: batch Rust, vector Rust, JNI/native fallback, logical/physical/lazy scan copies, filesystem/HMS/JDBC and relevant REST/DLF paths reviewed. New vector plans have no fallback, which makes the reported preflight gaps observable failures.
  9. Conditions: predicate whitelists, NULL query elements, IN bounds, incremental/file-time exclusions, branch/snapshot identity and pinned-empty state traced. Canonical field casing is preserved; apparent lowercasing issues were dismissed from actual descriptor code.
  10. Tests: inspected FE/BE unit and differential regression additions; no builds or tests executed under the static-only contract. Missing cases are stated inline. Profile presence alone is not proof of vector execution.
  11. Expected results: inspected changed temporal/date, table-property and oversized-row expectations; no additional proven expectation defect. The new shared binary normalization can hide mismatches (inline).
  12. Observability: ANN explain fields, fallback reason logging and Rust timers are present. No additional critical logging/metrics defect established; large-K behavior was not benchmarked.
  13. Transactions/persistence: no changed write/commit/EditLog protocol. New heartbeat capability serialization and replay/default-false downgrade behavior checked.
  14. Data writes/crashes: production changes are read/planning paths; no new table mutation or transaction atomicity change. Reader cleanup/error propagation inspected statically.
  15. FE/BE state: AnnTopNInfo survives logical/physical copies and translation; query-wide request and per-bucket bytes reach the Rust reader. Old BEs are excluded by independently negotiated vector support.
  16. Performance/memory: source reads stream into bounded search heaps; selected TopK payloads are eagerly materialized and ignore ordinary batch-size controls. Static inspection does not establish a separate lifetime/tracker defect; runtime memory/cancellation and dependency-linkage validation remain outside this review.
  17. Other concerns: the whole PR and upstream/downstream special cases were checked beyond the first finding; candidate dispositions and risk coverage are recorded in the shared ledger.

User focus: no additional focus was supplied. Existing thread 4357063534 about reusing the heartbeat flag was reviewed as a duplicate fence and not reposted; no existing P0/P1 blocker was independently confirmed. Coverage limits: static source review only, with no build, test, external-service execution or performance measurements. No repository source changes or submodule initialization were performed.

Review converged after 2 round(s).

dengfangyuan and others added 3 commits October 23, 2026 16:39
Per review: drop the separate supports_paimon_rust_vector_reader field
and gate the PK-vector rewrite on supports_paimon_rust_reader alone. The
rust reader bit has not shipped in any release yet, and the PK-vector
protocol ships in the same release, so no deployed BE can ever report
the rust bit without the vector protocol — the separate negotiation
(and its mixed-version window) cannot occur in practice.

Removes the thrift field, the BE heartbeat report, the FE backend-state
plumbing, and the vectorEligible layer; the vector gates now reuse the
plain eligible() computation.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Per the static review round on 8fd3bec:

- Nanosecond pre-flight: a TIMESTAMP_NS column in the CURRENT schema (no
  evolution history) passed the pre-flight but tripped the scan node's
  nanosecond-reader gate, which a no-fallback vector split turns into a
  query error. The pre-flight now mirrors PaimonUtil.containsTimestampNs
  over the slots the Project and Filter reference.
- Reserved materializer names: a user column named __paimon_search_score
  or _PKEY_VECTOR_POSITION makes the rust table open fail after the
  one-way rewrite; both names join the synthetic-distance collision check.
- Distance exemption narrowed: only the call the rewrite actually
  replaces (the one equal to the order-key expression) may exempt its
  slots; a distinct distance call keeps its complex-slot whole-column
  guard instead of shipping a projection rust cannot materialize.
- ORC era detection: the orc-ltz pre-flight checked only the CURRENT file
  format, so a table written ORC with TIMESTAMP_LTZ and later switched
  to Parquet passed while setPaimonParams still detected the retained
  ORC files. Any schema era that declared ORC and carried LTZ columns
  (its own or the current schema's) now declines.

Tests: four new rewrite-rule cases (45 total, all green); the ANN e2e
suite stays green against the tighter pre-flight.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ries

The 0x-token substitution ran as a substring replacement on every
normalized string, so a literal-text fragment shaped like a token could
collapse distinct values across engines (Spark "prefixA" vs Doris
"prefix0x41" comparing equal after the decode), and quoted strings and
map keys were equally exposed.

The token pattern now requires a value/element boundary (negative
lookbehind on alphanumerics, quotes and backslash), so only shapes Doris
can only have produced as a binary element ("[0x616C, ", "{0x41: ",
"ROW(0x61") decode; the quantifier also stops matching a bare "0x" with
zero byte pairs. A literal string whose whole value coincides with a
bare token remains the one documented ambiguity — distinguishing it
needs column types the comparison does not have.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Gabriel39

Copy link
Copy Markdown
Contributor

/review

@Gabriel39

Copy link
Copy Markdown
Contributor

run buildall

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed #69493 at 199ad37. Request changes for two new P1 findings (regression-framework syntax and unaccounted eager vector materialization) and one P2 S3 credential-precedence regression.

Critical checkpoint conclusions:

  1. Goal and proof: the SDK upgrade and PK-vector ANN path are implemented across planner, split transport and BE; focused FE/BE tests and differential regression cases are present, but this static review does not prove runtime success.
  2. Scope: the production changes form a coherent feature/SDK migration; shared regression normalization expands the affected surface and contains the syntax finding.
  3. Concurrency and locks: query planning and scanner-local state introduce no new shared lock order; Rust executes through its Tokio runtime. Its unaccounted eager allocations are covered by the memory finding.
  4. Lifecycle: table reuse keys include schema/options/branch, split cleanup follows ownership order, and the pinned eager API returns an independently owned Arrow stream before local handles are freed. No additional lifetime defect established.
  5. Configuration: existing Rust-reader and FileScannerV2 session switches gate the feature; no new dynamic server configuration is introduced.
  6. Compatibility: VECTOR is consistently mapped to Doris ARRAY with the corresponding JNI physical accessor. Unsupported reader shapes mostly decline before the one-way rewrite; existing NULL-vector and retained-ORC concerns remain below.
  7. Thrift: touched definitions were compared on HEAD, branch-4.2, branch-4.1, branch-4.0, branch-3.1 and master. New parent fields do not reuse IDs; master's reserved fields20/41 are avoided. Required children belong to a wholly new optional payload, so old readers skip that payload.
  8. Parallel paths: normal batch/raw/JNI paths, Hudi/lazy scan copies and both metrics were checked. The shared filesystem/HMS/JDBC S3-option mirror overwrites explicit provider options, as reported inline; generated Hadoop defaults must preserve explicit catalog choices.
  9. Conditional checks: filter shapes/types/NULL literals/IN size, snapshot/branch/options/empty generation, nested projection, nanoseconds and reserved names were traced through callers and consumers. Downstream TopN analysis rejects limit overflow; runtime filters do not cross the retained TopN.
  10. Test coverage: positive and negative planner cases, wire/schema guards, score conversion, partition metadata, filter fallback, assertions and both metrics are represented. No eager-memory admission test covers the new resource defect.
  11. Changed expected results: timestamp/date, property-default and error-prefix changes were inspected; no golden result files were edited. Framework syntax must be repaired before these suites can run.
  12. Observability: existing reader open/read/Arrow timers cover execution, and fallback-reason logs explain dispatch without logging credential values. No additional observability blocker established.
  13. Transactions and persistence: production EditLog, commit and failover logic are unchanged; relation snapshot selection and pinned-empty fencing were traced.
  14. Writes and atomicity: production write/transaction paths are unchanged; the adjusted write-failure test still checks rows and snapshot state after failure.
  15. FE-BE variables: AnnTopNInfo survives logical/physical copies and translation; query-wide search parameters and per-split payload agree with BE consumption.
  16. Performance and memory: table-handle reuse and merge-free compacted batch reads are retained. Eager all-K payload collection/reordering bypasses adaptive batch sizing and tracked admission, as detailed inline.
  17. Other checks: source casing prevents the suspected ordinary score-name misrouting, and small f32 score/tie differences were not raised as a separate defect under the approximate ANN contract.

Existing review context was revalidated and not reposted. The stored-NULL-vector validation issue in discussion4357228424 still applies. Discussion4357228441 also remains applicable to per-level file formats: a Parquet default plus file.format.per.level='0:orc' can retain ORC/LTZ files that the preflight misses. Its original schema-history trigger is now guarded. Nanosecond projection (4357228428), reserved vector materializer names (4357228431), distinct distance-call exemptions (4357228435), and the redundant heartbeat capability (4357063534) are addressed. Generic string/binary normalization ambiguity remains covered by4357228447; the syntax failure reported here is distinct. No existing P0/P1 inline finding required carrying forward.

User focus: no additional focus points were supplied. All 55 authoritative changed paths and relevant upstream/downstream contracts received static coverage. Builds, tests, live query execution and SDK interoperability matrices were not run, as required by the review contract; no source files or submodules were modified.

Review converged after 3 round(s).

…Groovy

The lookbehind's escaped quote terminated the double-quoted string literal
mid-pattern, so the shared framework fails to compile and no suite can
start. The pattern moves to a slashy string literal, where neither the
backslash nor either quote character needs escaping.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 61.19% (454/742) 🎉
Increment coverage report
Complete coverage report

The mirrorHadoopS3OptionsToCatalogOptions loop set every fs.s3a.* entry
from the generated Hadoop configuration unconditionally, so for a catalog
with static s3 keys plus an explicit assumed-role credentials provider
the Hadoop side's SimpleAWSCredentialsProvider replaced the requested
provider in the catalog options — the warehouse then re-opened under the
base identity and failed with AccessDenied. The mirror now fills only
options the catalog has not already set: the user's explicit fs.s3a.*
entries keep precedence over the generated defaults. This affects the
filesystem, HMS and JDBC paimon catalog variants alike.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 61.14% (461/754) 🎉
Increment coverage report
Complete coverage report

@Gabriel39

Copy link
Copy Markdown
Contributor

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes on exact head af5c7cc. Four new verified findings are inline: legacy Paimon authorization is silently removed, legacy serialized privilege tables break BE-first upgrades, vector scans bypass cross-storage file eligibility, and non-finite query vectors change supported queries into errors.

Existing blocking finding 4358943088 still applies: uncapped LIMIT+OFFSET reaches eager Rust materialization without tracked admission or a byte bound. It is carried in existing_blocking_comment_ids rather than reposted. The previous Groovy quoting P1 is fixed by the slashy literal; the explicit S3-provider overwrite is fixed by filling only absent options. Existing stored-NULL-vector, per-level ORC/LTZ eligibility and literal-comparator ambiguities remain covered by their existing threads and are not duplicated. Reserved-name, projected nanosecond timestamp and exact distance-call exemption guards are present.

Critical checkpoint conclusions:

  1. Goal and proof: the PR adds the complete Nereids -> Java bucket planning -> Rust ANN pipeline and focused tests, but the four findings prevent accepting its behavior as complete.
  2. Scope: the SDK, VECTOR/JNI mappings, credentials and plan plumbing changes were reviewed together across all 56 changed paths.
  3. Concurrency and locks: immutable ANN plan data is copied defensively; no new Doris thread entry or lock-order change was identified. Rust asynchronous work remains SDK-owned, including the already-reported untracked allocations.
  4. Lifecycle: split/table handles, early error cleanup, Arrow ownership, nullable score conversion and query-homogeneous split reuse were traced; no additional lifetime or static-initialization defect was verified.
  5. Configuration: existing reader/scanner session switches are reused; no new dynamic Doris configuration was introduced.
  6. Compatibility: both supported BE-first serialized-table compatibility and fully upgraded catalog authorization have new regressions, reported inline. The reverse-order v9 split concern was dismissed using the documented BE-before-FE upgrade order.
  7. Thrift/protobuf: touched Thrift definitions were compared with branch-3.1, branch-4.0, branch-4.1, branch-4.2 and master. New outer fields are optional and avoid master IDs 20/41; no conflicting ID reuse or required addition to an existing struct was found. No protobuf change.
  8. Parallel paths: ordinary native/JNI/Rust readers, vector readers, all scan-copy/translation paths, Hudi constructor adaptation and filesystem/HMS/JDBC catalog variants were covered.
  9. Conditional gates: unsupported filter shapes, NULL query literals, oversized IN, data predicates without the required DV mode, projection and schema-history guards were checked. Cross-storage files and non-finite queries are the new missing preflights.
  10. Tests: FE/BE unit tests and external regression suites were inspected for positive, negative, partition, snapshot, schema and metric cases; no builds or tests were executed.
  11. Expected results: changed expectations and error assertions were reviewed statically; no generated .out file was modified. This review does not certify runtime output.
  12. Observability: ANN explain fields and reader timers exist; fallback reasons are logged once per combination. The regression profile assertion only checks PaimonRustReader, which also exists for ordinary Rust scans and cannot alone prove ANN executed.
  13. Transaction/persistence: no Doris EditLog, transaction-commit or persistence-format modification was found; statement snapshot/branch/pinned-empty handling was traced.
  14. Writes/atomicity: direct changes are on read/planning paths; no new Doris data-write atomicity change was found. The dependency upgrade's authorization effect is reported rather than assumed safe.
  15. FE/BE propagation: vector column, f32 bytes, metric, retrieval K, synthetic output and per-bucket payload were traced through logical/physical copies, translation and decoding.
  16. Performance/memory: the existing eager-materialization P1 remains blocking. The relaxed ordinary compacted-file gate was checked against Java split guarantees and Rust dispatch; no additional losing-batch retention trigger was verified.
  17. Further recheck: predicate canonicalization, runtime-filter boundaries, branch/options identity, external file storage, legacy privilege metadata, Java serialization and ordinary score-named columns were rechecked; every candidate has an accepted, existing-thread or evidence-based dismissal disposition.

User focus: no additional focus was supplied; the complete PR was reviewed. Coverage limits: static analysis only, with no live query, build, test or benchmark validation. No unresolved review candidate or uncovered changed-file scope remains. Convergence describes review stability; the new authorization P1 and existing memory P1 still require changes.

Review converged after 2 round(s).

Existing P0/P1 findings confirmed for this head: #69493 (comment)

Comment thread fe/pom.xml Resolved
Comment thread fe/pom.xml Resolved
dengfangyuan and others added 3 commits October 26, 2026 14:07
…or scans

Per the static review round on af5c7cc (the legacy-privilege P1 is
deliberately deferred this round):

- Non-finite query-vector literals (CAST('infinity' AS FLOAT), NaN): the
  ordinary path answers these with an infinite-distance row, while
  paimon-rust's validate_query rejects non-finite coordinates and the
  one-way rewrite has no fallback. The pre-flight now declines any
  non-finite coordinate literal (both metrics).
- External-file data (data-file.external-paths behind a
  resolving-file-io catalog): Java dispatches each URI to its matching
  backend, but the rust reader opens the table through a single FileIO
  and rejects foreign schemes (an oss:// external path on an S3 table).
  The external-file gate now applies to the vector path too — the scan
  node checks the split's external files in the base rust gate (with the
  fallback reason now also reported for vector splits), and the rewrite
  pre-flight declines a catalog (or table option) that opts into the
  resolving-file-io layout.

Tests: non-finite coordinate × both metrics and the resolving-file-io
catalog case join the rewrite suite (47/47 green).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A BE-first rolling upgrade against a legacy Paimon 1.4 warehouse can
receive objects the 2.1 connector can no longer decode: the old FE
serializes the table as a PrivilegedFileStoreTable (for example with
scan.manifest.parallelism=1) whose privilege classes were removed in
2.1, and the bare ClassNotFoundException from this classloader says
nothing about the upgrade. Deserialization failures that bottom out in
ClassNotFoundException now rethrow with the upgrade/migration cause and
remedy, so BE-first windows fail diagnosably instead of cryptically.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@pzhdfy
pzhdfy requested a review from Gabriel39 October 28, 2026 06:21
### What problem does this PR solve?

Related PR: apache#69493

Problem Summary: Paimon vector_search(use_index=false) previously only sent
vector-index.search-mode=full as a query option. The pinned PK reader resolves
that mode from the table schema instead, and FULL still searches ANN segments
for indexed files. A FAST table with uncovered data files could therefore
omit the nearest rows even when the user requested an unindexed search.

Carry use_index through the existing shared search options. For flat searches,
copy the read table with FULL in its schema and omit ANN payload files from
the bucket splits while preserving their snapshot, data files and row ranges.
The existing Rust exact fallback then searches all planned active files.
Keep default/true and ordinary SQL ANN behavior unchanged.

### Release note

Make Paimon vector_search(use_index=false) bypass ANN index segments and
include uncovered data files in exact Top-K searches.

### Check List (For Author)

- Test: Added FE payload round-trip coverage for indexed/flat controls and an
  external regression with data written before index configuration. Static
  self-review and git diff --check completed. No local build, Checkstyle,
  unit tests or regression execution, as requested.
- Behavior changed: Yes; use_index=false performs exact search over every
  planned active data file instead of continuing to use ANN.
- Does this need documentation: No; implements the existing option's behavior.
@suxiaogang223 suxiaogang223 changed the title branch-4.2:[feat](paimon) upgrade to 2.1 and support SQL/TVF ANN search [feature](paimon) Add SQL and TVF ANN search with Paimon 2.1 Nov 4, 2026
@suxiaogang223

Copy link
Copy Markdown
Member

run buildall

@suxiaogang223

Copy link
Copy Markdown
Member

/review

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.44% (2005/2623)
Line Coverage 64.96% (36152/55652)
Region Coverage 52.90% (34579/65367)
Branch Coverage 55.77% (10776/19322)

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Selected model is at capacity. Please try a different model.
Workflow run: https://github.com/apache/doris/actions/runs/41788470352

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 70.77% (758/1071) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 37.25% (152/408) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 64.81% (30383/46882)
Line Coverage 49.70% (321860/647621)
Region Coverage 45.47% (259337/570381)
Branch Coverage 47.16% (122694/260181)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 36.00% (144/400) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.34% (34760/45533)
Line Coverage 61.19% (392963/642214)
Region Coverage 57.92% (330835/571236)
Branch Coverage 58.93% (153150/259869)

suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Nov 18, 2026
### Background

Master uses an isolated Paimon connector rather than the source PR's engine-side Paimon scan classes.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#69493 (source implementation), apache#70704 (migration Draft)
PR Type: Other

Problem Summary:

Carry vector payloads through the connector's Rust split representation and restore the source PR's explicit rejection of removed warehouse ACLs. SQL/TVF admission and search planning remain incomplete in the migration Draft.

### Details

- **Change map:** +92 production lines across catalog creation, its compatibility helper and range transport; +330 test lines across recording-fake warehouse tests, range dispatch tests and protocol round trips.
- **Why Other:** An intermediate migration checkpoint in the user-requested Draft, with no SQL ANN or TVF entry point connected yet.
- **Behavior change:** Legacy ACL warehouses fail catalog initialization; vector range construction uses reserved payload fields, preserves Rust dispatch and gives buckets distinct identities.

### Testing

Paimon connector reactor install passed, including main/test compilation, Checkstyle, plugin packaging and 15 focused tests with zero failures, errors or skips. Connector forbidden-import gate and git diff --cached --check passed. Full BE/FE and external end-to-end validation are pending.

### Release note

None; this is an intermediate Draft migration checkpoint.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (describe ANN syntax and legacy ACL rejection in the completed feature)
- Pre-submission status: Not ready: SQL/TVF integration and search admission/planning remain incomplete.

### AI Disclosure

- Tool: OpenAI Codex (GPT-6)
- Generated: Connector adaptation, tests and this description, reusing source PR logic.
- Human review: Not stated for this adaptation.
suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Nov 18, 2026
### Background

Doris reads Paimon logical splits through the Rust reader in FileScannerV2. Paimon primary-key vector indexes additionally need bucket-level search plans and metric-aware score materialization.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#69493 (prior ANN implementation), apache#70075 (reserved vector protocol), apache#70598 (Rust 0.5.0)
PR Type: Other

Problem Summary:

Add Rust bucket search readers, request validation, metric-aware distance materialization and native fixture coverage. SQL ANN pushdown, connector search admission/planning and the `vector_search` TVF are still under development, so this PR remains a Draft.

### Details

- **Change map:** Production code: +758/-47 lines across three reader/converter files. Tests and SDK-generated fixture metadata: +1810/-0 lines across 61 files, including binary fixtures. No dependency versions or protocol definitions change.
- **Why Other:** This Draft implements the execution layer; query-planner integration and SQL entry points are incomplete.
- **Behavior change:** Native vector reads consume preplanned bucket payloads and materialize L2 or inner-product distances with the requested SQL/TVF conventions. Connector ranges retain Rust dispatch and distinguish bucket identities. Catalog initialization rejects warehouses containing both `user.sys` and `privilege.sys`; checks and cleanup run inside the authentication context, and metadata access errors propagate.
- **Compatibility:** Use Java Paimon 2.1, paimon-rust 0.5.0 and existing optional Thrift fields. Preserve adaptive batch slicing and predicate profile counters. Mixed-version queries may fail explicitly; process crashes are unacceptable. Rust eager materialization memory budgeting remains a known limitation.

### Testing

- BE build hygiene, clang-format 16 and whitespace checks passed.
- Native fixture cases cover multi-file materialization, SQL/TVF metrics, physical row ranges, NULL vectors, reader reuse, failures, cancellation, score-only projection and malformed requests. Master-native build/runtime validation is in progress.
- External Spark/Doris regression and complete SQL/TVF execution are pending. FULL-mode fixtures do not establish ANN index correctness.

### Notes for Reviewers

The native reader and connector payload transport are implemented; the planner does not emit search requests yet. Complete connector admission and bucket planning, SQL TopN/slot propagation, TVF binding and their FE tests before marking this PR ready.

### Release note

Reject Paimon warehouses using legacy ACL metadata removed in Paimon 2.1. Native primary-key vector search is under development; SQL entry points are not yet available in this Draft.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (document vector search syntax, supported table shapes and legacy ACL rejection with the completed feature)
- Pre-submission status: Not ready: connector search planning, SQL ANN and TVF entry points are incomplete; native runtime and end-to-end validation are pending.

### AI Disclosure

- Tool: OpenAI Codex (GPT-6)
- Generated: Native reader and connector changes, tests and this description, building on the prior work in apache#69493.
- Human review: Not stated for the current changes.

Co-authored-by: dengfangyuan <dengfangyuan@kuaishou.com>
suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Nov 18, 2026
### Background

Doris reads Paimon logical splits through the Rust reader in FileScannerV2. Paimon primary-key vector indexes additionally need bucket-level search plans and metric-aware score materialization.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#69493 (prior ANN implementation), apache#70075 (reserved vector protocol), apache#70598 (Rust 0.5.0)
PR Type: Other

Problem Summary:

Encode vector payloads in connector ranges, retain Rust dispatch and distinct bucket identities, and reject removed legacy warehouse ACLs inside the authentication context. SQL ANN pushdown, connector search admission/planning and the `vector_search` TVF are still under development, so this PR remains a Draft.

### Details

- **Change map:** Production code: +850/-47 lines across six reader, converter and connector files. Tests and SDK-generated fixture metadata: +2140/-0 lines across 64 files, including binary fixtures. No dependency versions or protocol definitions change.
- **Why Other:** This Draft implements the execution layer; query-planner integration and SQL entry points are incomplete.
- **Behavior change:** Native vector reads consume preplanned bucket payloads and materialize L2 or inner-product distances with the requested SQL/TVF conventions. Connector ranges retain Rust dispatch and distinguish bucket identities. Catalog initialization rejects warehouses containing both `user.sys` and `privilege.sys`; checks and cleanup run inside the authentication context, and metadata access errors propagate.
- **Compatibility:** Use Java Paimon 2.1, paimon-rust 0.5.0 and existing optional Thrift fields. Preserve adaptive batch slicing and predicate profile counters. Mixed-version queries may fail explicitly; process crashes are unacceptable. Rust eager materialization memory budgeting remains a known limitation.

### Testing

- Paimon connector reactor build: main/test compilation, Checkstyle and plugin packaging passed. `PaimonCatalogCompatibilityTest`, `PaimonScanRangeReaderTypeTest` and `PaimonVectorPayloadTest`: 15 tests passed, with no failures, errors or skips.
- Connector forbidden-import gate, BE build hygiene, clang-format 16 and whitespace checks passed.
- Native fixture cases cover multi-file materialization, SQL/TVF metrics, physical row ranges, NULL vectors, reader reuse, failures, cancellation, score-only projection and malformed requests. Master-native build/runtime validation is in progress.
- External Spark/Doris regression and complete SQL/TVF execution are pending. FULL-mode fixtures do not establish ANN index correctness.

### Notes for Reviewers

The native reader and connector payload transport are implemented; the planner does not emit search requests yet. Complete connector admission and bucket planning, SQL TopN/slot propagation, TVF binding and their FE tests before marking this PR ready.

### Release note

Reject Paimon warehouses using legacy ACL metadata removed in Paimon 2.1. Native primary-key vector search is under development; SQL entry points are not yet available in this Draft.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (document vector search syntax, supported table shapes and legacy ACL rejection with the completed feature)
- Pre-submission status: Not ready: connector search planning, SQL ANN and TVF entry points are incomplete; native runtime and end-to-end validation are pending.

### AI Disclosure

- Tool: OpenAI Codex (GPT-6)
- Generated: Native reader and connector changes, tests and this description, building on the prior work in apache#69493.
- Human review: Not stated for the current changes.

Co-authored-by: dengfangyuan <dengfangyuan@kuaishou.com>
suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Nov 18, 2026
### Background

Primary-key vector reads need a connector bucket plan and a global TopN above
per-bucket candidates. Master's generic connector scans did not expose this path.

### What problem does this PR solve?

Issue Number: TODO(author): the issue is opened with the PR
Related PR: apache#69493 (original implementation), apache#70704 (master implementation)
PR Type: Feature

Problem Summary:

Connect distance TopN and vector_search to native bucket retrieval through the
connector SPI. Preserve candidate-filter ordering, source privileges, snapshot
pins and conservative SQL fallback. Replace stored SDK tables with runtime
Spark fixtures and verify both indexed and exact-read paths.

### Details

- Scope: VECTOR<FLOAT>, L2 and inner product on admitted primary-key tables.
- Design: immutable SPI33 request, connector-specific admission and bucket
  planning, native Arrow reading, and a retained global TopN.
- Usage: distance TopN SQL or vector_search with optional prefilter/index options.
- Default behavior: existing reader flags gate SQL admission; unsupported SQL
  retains scalar scanning, while unsupported TVF requests fail explicitly.
- Compatibility: existing optional master wire fields; no persisted-format
  change. Live mixed-release operation remains unverified.
- Follow-up plan: Rust eager materialization memory budgeting remains deferred.

### Testing

Standard ASAN build.sh --be --fe and final build.sh --be passed. Native64,
SPI164, targeted connector20, planner/scan18 and source-policy4 tests passed;
additional mapping tests passed. All6 vector/ordinary-reader regression suites
passed in normal comparison, zero failures or skips. Goldens were generated by
the regression harness. Changed-line clang-tidy, clang-format16 and build hygiene
passed. HDFS and live rolling upgrades were not run.

### Release note

Support native primary-key vector retrieval through distance TopN and
vector_search on eligible Paimon2.1 tables.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (follow-up Paimon vector-search documentation)
- Pre-submission status: Partially verified: Feature issue pending; memory
  budgeting and live mixed releases remain unverified

### AI Disclosure

- Tool: Codex (GPT-6)
- Generated: master integration, fixes and tests based on dengfangyuan's work
- Human review: pending author review of this revision

Co-authored-by: dengfangyuan <dengfangyuan@kuaishou.com>
suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Nov 24, 2026
### Background

Doris reads Paimon logical splits through the Rust reader in FileScannerV2. Paimon primary-key vector indexes additionally need bucket-level search plans and metric-aware score materialization.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#69493 (prior ANN implementation), apache#70075 (reserved vector protocol), apache#70598 (Rust 0.5.0)
PR Type: Other

Problem Summary:

Add Rust bucket search readers, request validation, metric-aware distance materialization and native fixture coverage. SQL ANN pushdown, connector search admission/planning and the `vector_search` TVF are still under development, so this PR remains a Draft.

### Details

- **Change map:** Production code: +758/-47 lines across three reader/converter files. Tests and SDK-generated fixture metadata: +1810/-0 lines across 61 files, including binary fixtures. No dependency versions or protocol definitions change.
- **Why Other:** This Draft implements the execution layer; query-planner integration and SQL entry points are incomplete.
- **Behavior change:** Native vector reads consume preplanned bucket payloads and materialize L2 or inner-product distances with the requested SQL/TVF conventions. Connector ranges retain Rust dispatch and distinguish bucket identities. Catalog initialization rejects warehouses containing both `user.sys` and `privilege.sys`; checks and cleanup run inside the authentication context, and metadata access errors propagate.
- **Compatibility:** Use Java Paimon 2.1, paimon-rust 0.5.0 and existing optional Thrift fields. Preserve adaptive batch slicing and predicate profile counters. Mixed-version queries may fail explicitly; process crashes are unacceptable. Rust eager materialization memory budgeting remains a known limitation.

### Testing

- BE build hygiene, clang-format 16 and whitespace checks passed.
- Native fixture cases cover multi-file materialization, SQL/TVF metrics, physical row ranges, NULL vectors, reader reuse, failures, cancellation, score-only projection and malformed requests. Master-native build/runtime validation is in progress.
- External Spark/Doris regression and complete SQL/TVF execution are pending. FULL-mode fixtures do not establish ANN index correctness.

### Notes for Reviewers

The native reader and connector payload transport are implemented; the planner does not emit search requests yet. Complete connector admission and bucket planning, SQL TopN/slot propagation, TVF binding and their FE tests before marking this PR ready.

### Release note

Reject Paimon warehouses using legacy ACL metadata removed in Paimon 2.1. Native primary-key vector search is under development; SQL entry points are not yet available in this Draft.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (document vector search syntax, supported table shapes and legacy ACL rejection with the completed feature)
- Pre-submission status: Not ready: connector search planning, SQL ANN and TVF entry points are incomplete; native runtime and end-to-end validation are pending.

### AI Disclosure

- Tool: OpenAI Codex (GPT-6)
- Generated: Native reader and connector changes, tests and this description, building on the prior work in apache#69493.
- Human review: Not stated for the current changes.

Co-authored-by: dengfangyuan <dengfangyuan@kuaishou.com>
suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Nov 24, 2026
### Background

Doris reads Paimon logical splits through the Rust reader in FileScannerV2. Paimon primary-key vector indexes additionally need bucket-level search plans and metric-aware score materialization.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#69493 (prior ANN implementation), apache#70075 (reserved vector protocol), apache#70598 (Rust 0.5.0)
PR Type: Other

Problem Summary:

Encode vector payloads in connector ranges, retain Rust dispatch and distinct bucket identities, and reject removed legacy warehouse ACLs inside the authentication context. SQL ANN pushdown, connector search admission/planning and the `vector_search` TVF are still under development, so this PR remains a Draft.

### Details

- **Change map:** Production code: +850/-47 lines across six reader, converter and connector files. Tests and SDK-generated fixture metadata: +2140/-0 lines across 64 files, including binary fixtures. No dependency versions or protocol definitions change.
- **Why Other:** This Draft implements the execution layer; query-planner integration and SQL entry points are incomplete.
- **Behavior change:** Native vector reads consume preplanned bucket payloads and materialize L2 or inner-product distances with the requested SQL/TVF conventions. Connector ranges retain Rust dispatch and distinguish bucket identities. Catalog initialization rejects warehouses containing both `user.sys` and `privilege.sys`; checks and cleanup run inside the authentication context, and metadata access errors propagate.
- **Compatibility:** Use Java Paimon 2.1, paimon-rust 0.5.0 and existing optional Thrift fields. Preserve adaptive batch slicing and predicate profile counters. Mixed-version queries may fail explicitly; process crashes are unacceptable. Rust eager materialization memory budgeting remains a known limitation.

### Testing

- Paimon connector reactor build: main/test compilation, Checkstyle and plugin packaging passed. `PaimonCatalogCompatibilityTest`, `PaimonScanRangeReaderTypeTest` and `PaimonVectorPayloadTest`: 15 tests passed, with no failures, errors or skips.
- Connector forbidden-import gate, BE build hygiene, clang-format 16 and whitespace checks passed.
- Native fixture cases cover multi-file materialization, SQL/TVF metrics, physical row ranges, NULL vectors, reader reuse, failures, cancellation, score-only projection and malformed requests. Master-native build/runtime validation is in progress.
- External Spark/Doris regression and complete SQL/TVF execution are pending. FULL-mode fixtures do not establish ANN index correctness.

### Notes for Reviewers

The native reader and connector payload transport are implemented; the planner does not emit search requests yet. Complete connector admission and bucket planning, SQL TopN/slot propagation, TVF binding and their FE tests before marking this PR ready.

### Release note

Reject Paimon warehouses using legacy ACL metadata removed in Paimon 2.1. Native primary-key vector search is under development; SQL entry points are not yet available in this Draft.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (document vector search syntax, supported table shapes and legacy ACL rejection with the completed feature)
- Pre-submission status: Not ready: connector search planning, SQL ANN and TVF entry points are incomplete; native runtime and end-to-end validation are pending.

### AI Disclosure

- Tool: OpenAI Codex (GPT-6)
- Generated: Native reader and connector changes, tests and this description, building on the prior work in apache#69493.
- Human review: Not stated for the current changes.

Co-authored-by: dengfangyuan <dengfangyuan@kuaishou.com>
suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Nov 24, 2026
### Background

Primary-key vector reads need a connector bucket plan and a global TopN above
per-bucket candidates. Master's generic connector scans did not expose this path.

### What problem does this PR solve?

Issue Number: TODO(author): the issue is opened with the PR
Related PR: apache#69493 (original implementation), apache#70704 (master implementation)
PR Type: Feature

Problem Summary:

Connect distance TopN and vector_search to native bucket retrieval through the
connector SPI. Preserve candidate-filter ordering, source privileges, snapshot
pins and conservative SQL fallback. Replace stored SDK tables with runtime
Spark fixtures and verify both indexed and exact-read paths.

### Details

- Scope: VECTOR<FLOAT>, L2 and inner product on admitted primary-key tables.
- Design: immutable SPI33 request, connector-specific admission and bucket
  planning, native Arrow reading, and a retained global TopN.
- Usage: distance TopN SQL or vector_search with optional prefilter/index options.
- Default behavior: existing reader flags gate SQL admission; unsupported SQL
  retains scalar scanning, while unsupported TVF requests fail explicitly.
- Compatibility: existing optional master wire fields; no persisted-format
  change. Live mixed-release operation remains unverified.
- Follow-up plan: Rust eager materialization memory budgeting remains deferred.

### Testing

Standard ASAN build.sh --be --fe and final build.sh --be passed. Native64,
SPI164, targeted connector20, planner/scan18 and source-policy4 tests passed;
additional mapping tests passed. All6 vector/ordinary-reader regression suites
passed in normal comparison, zero failures or skips. Goldens were generated by
the regression harness. Changed-line clang-tidy, clang-format16 and build hygiene
passed. HDFS and live rolling upgrades were not run.

### Release note

Support native primary-key vector retrieval through distance TopN and
vector_search on eligible Paimon2.1 tables.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (follow-up Paimon vector-search documentation)
- Pre-submission status: Partially verified: Feature issue pending; memory
  budgeting and live mixed releases remain unverified

### AI Disclosure

- Tool: Codex (GPT-6)
- Generated: master integration, fixes and tests based on dengfangyuan's work
- Human review: pending author review of this revision

Co-authored-by: dengfangyuan <dengfangyuan@kuaishou.com>
morningman added a commit to morningman/doris that referenced this pull request Nov 25, 2026
…talogs

### Background

Lance datasets carry vector indexes (IVF_FLAT, IVF_PQ, IVF_SQ, IVF_HNSW_*) and full-text indexes. branch-4.1 and branch-4.2 expose them through two table functions, `vector_search(...)` and `full_text_search(...)`: each reads a table of a `lance` catalog and returns its columns plus `_distance` or `_score`; every index segment and every unindexed fragment becomes one scan range, and a Doris TopN merges the ranges' candidates. On master, Lance is a connector plugin (apache#70680), fe-core holds no Lance code, and the BE already executes these searches.

### What problem does this PR solve?

Issue Number: close apache#70970
Related PR: apache#65730, apache#66512, apache#66841, apache#67039, apache#67289, apache#68028, apache#68162, apache#68813, apache#68815 (the branch-4.x implementation this ports), apache#70680 (builds on: the Lance connector plugin)
PR Type: Feature

Problem Summary:

Users of `lance` catalogs lose vector and full-text search on master: both functions fail with `Can not found function 'vector_search'`. They come back with branch-4.2's arguments, defaults, limits, errors and EXPLAIN keys, through a new optional connector SPI: fe-core owns the two functions and the plan rules, the connector parses the arguments and plans the search. Two 4.x problems are fixed on the way: filters other than the function's own WHERE crossed the merge, so rows depended on the select list, and row policies, masks and column privileges did not apply. 60% of the diff is tests. Existing statements are unaffected; connector plugins move to API 38.0.

```sql
SELECT row_id, category, label, _distance
FROM vector_search("table" = "lance_ctl.doris.vs_ivf_pq_f32", "column" = "embedding",
                   "query_vector" = "[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]",
                   "top_k" = "5", "metric" = "l2", "nprobes" = "4", "refine_factor" = "10")
ORDER BY _distance, row_id;
```

| | Result |
|---|---|
| master | `Can not found function 'vector_search'` |
| this PR (same as branch-4.2) | `1 even item-0001 0.0`, `2 odd item-0002 16.0`, `3 even item-0003 64.0`, `4 odd item-0004 144.0`, `5 even item-0005 256.0` |

### Details

- **Change map:** 126 files, +7,321 / -59: production code +2,911 (40%), tests with their generated `.out` +4,397 (60%), docs and build +13. Production code by part, one commit each:
  1. Connector search SPI (+344): `ConnectorSearchOps`, the request, function and result types, the `applyTopnLazyMaterialization` overload with lazy column names, API 37.0 -> 38.0 and its surface baselines.
  2. Engine (+874: fe-core 865, fe-common 4, BE 5): the two functions, routing and the privilege and policy checks (`ExternalSearchTableValuedFunction`); binding with the merge TopN and PREPARE / EXECUTE parameters (`BindExpression`, `LogicalPlanBuilder`, `UnboundTVFRelation`); the WHERE placement (`PushDownWhereThroughSearchTopN`, an analysis rule); lazy materialization admission and hand-off (`MaterializeProbeVisitor`, `LazyMaterializeTopN`, the translator, `PluginDrivenScanNode`); `enable_lance_lazy_materialization`; BE exec version 20.
  3. Lance plugin (+1,693): argument parsing and vector encoding (`LanceSearchArguments`, `LanceVectorQuery`, 865), search planning over index segments and fragments (`LanceScanPlanner`, `LanceSearchPlan`, index metrics, about 470), the search handle, metadata and scan properties (about 360), with its unit tests.
  4. fe-core unit tests. 5. Regression suites, three small fixtures copied from branch-4.2 and their registration.
- **Scope:** `vector_search` over fixed-size-list vector columns of float16, float32, float64, uint8 and int8, with the `l2`, `cosine`, `dot` and `hamming` metrics, index or flat search (`use_index`, `nprobes`, `refine_factor`, `ef`, `query_parallelism`), a Lance `filter` with `prefilter`, and `distance_lower_bound` / `distance_upper_bound`; `full_text_search` with match and phrase queries and the `STRICT` / `INDEX_ONLY` coverage modes; server-side PREPARE with `?` for `vector_search`'s `query_vector`, `top_k`, `offset`, `filter` and both distance bounds. Not supported: `approx_mode` (apache#69852, which master's BE does not read yet), searching earlier versions, tags or branches (apache#68707), `?` in `full_text_search` (refused: `full_text_search properties must be constant in a prepared statement`), and catalogs whose connector does not implement the SPI (refused: `Catalog 'x' does not support vector_search()`). Modules: fe-connector-spi, fe-core, fe-common, fe-connector-lance, and one constant in the BE.
- **Design:** The engine keeps the two function names and routes by the catalog of the `table` argument to `ConnectorSearchOps#prepareSearch`, an optional interface of the connector metadata (implementing it is the declaration, as for `ConnectorFileSourceOps`). The request carries the function, every argument except `table` under its lower-case name, and the names a PREPARE defers; the connector answers with the scan handle, the columns ending with the result column, `top_k`, `offset`, and whether the engine may fetch top-level columns after the merge. The engine owns the result column, the merge order (`_distance` ascending, `_score` descending) and which WHERE filters the candidates. Rejected: plugin-registered function names (one name could belong to one plugin only, while branch-4.2's apache#69493 lets Paimon serve `vector_search` too) and engine-parsed common arguments (Lance and Paimon differ in ranges and in what `filter` means). Proposed in apache#70970, opened with this PR; not discussed yet.
- **Usage:**

  ```sql
  SELECT row_id, _score
  FROM full_text_search("table" = "lance_ctl.doris.full_text_search", "column" = "body",
                        "query" = "lance", "top_k" = "4")
  ORDER BY _score DESC, row_id;

  -- the WHERE written on the function filters the candidates of each range before the merge
  SELECT row_id, _distance
  FROM vector_search("table" = "lance_ctl.doris.vs_ivf_pq_f32", "column" = "embedding",
                     "query_vector" = "[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]", "top_k" = "3") v
  WHERE v.category = 'odd';

  -- as a server-side prepared statement (JDBC with useServerPrepStmts=true), each EXECUTE binding the values
  SELECT row_id, _distance
  FROM vector_search("table" = "lance_ctl.doris.vs_ivf_pq_f32", "column" = "embedding",
                     "query_vector" = ?, "top_k" = ?, "offset" = ?, "filter" = ?)
  ORDER BY _distance, row_id;
  ```

- **Default behavior:** Available on every `lance` catalog. `top_k` 10, `offset` 0, `prefilter` false, and the metric Lance's default (L2), as on branch-4.2. Two-phase fetch is on (`enable_lance_lazy_materialization` = true) once every BE reports exec version 20, and `topn_lazy_materialization_threshold` does not limit a search's TopN.
- **Compatibility:** A rolling upgrade with BEs below exec version 20 plans no row-location fetch and keeps the plain TopN, with the same rows. No Thrift or Protobuf change: the request fields already exist on master and branch-4.2. Nothing is persisted. Connector plugins built against earlier API majors are refused by the version gate, as after every SPI surface change.
- **Behavior change:** Two differences for users coming from 4.1 or 4.2. On 4.x, any filter that reaches the merge TopN with no column pruning in between moves below it, so rows depend on the select list: `SELECT v.*, w.row_id AS w_row_id FROM vector_search(... "top_k" = "3", "use_index" = "false") v JOIN lance_ctl.doris.vs_ivf_pq_f32 w ON v.row_id = w.row_id WHERE w.row_id > 2` returns rows 3, 513 and 514 there (the inferred `v.row_id > 2` filtered the candidates), and row 3 with three columns of `v`. Here only the WHERE written on the function (`FROM vector_search(...) [alias] WHERE ...`) filters the candidates; outer WHEREs, CTE consumer filters, a WHERE over a join and inferred predicates apply to the result, so the query returns row 3. Second, the privilege rules below.
- **Security and privileges:** SELECT on the table is checked before the connector is called, as on 4.2; then SELECT on every column, since the arguments (the searched column, a `filter`) may read any. A search is refused while a row policy or a data mask applies to the user (`vector_search() is not supported on table '<table>' while row policies apply to it for the current user`), since it can apply neither; `root` and `admin` are exempt, as from row policies on scans. No new outbound host.
- **Follow-up plan:** A second PR ports branch-4.2's coverage suites that need the large fixtures (index types, IVF_FLAT, the index matrix, indexed element types, metrics, multivector) together with the generators of those fixtures; apache#68707 and apache#69852 come after it.

### Testing

All local, on a Mac (arm64), on the head unless noted.

- fe-core, 185 tests in 20 classes: the search classes, including `SearchWherePlacementTest`, which plans SQL through the whole analyzer and rewriter against a mocked connector; the lazy-materialization classes; and the analysis and CTE classes that meet the changed analyzer. Lance plugin, 317 tests; connector SPI, 172 (before the last javadoc-only change).
- 32 single-point mutations of this PR's decisions, in three rounds, each turning only its target tests red; putting the WHERE rule back into the rewriter, as on 4.x, fails the CTE, join and outer-LIMIT cases.
- One FE and one BE built from this branch (the BE from an earlier commit with the same BE change), a read-only S3 server standing in for MinIO: all 17 suites in `external_table_p0/lance` pass, including the six ported suites, whose `.out` files match branch-4.2's, and `test_lance_search_where_and_policy`, which tests the policy as a non-root user. On an FE with the 4.x rule, the suite's outer-LIMIT and CTE queries and the join query above return the 4.x rows, and a user reads rows their row policy hides.
- Rolling upgrade: at `be_exec_version` 19 the search plans no `VMaterializeNode` and returns the same rows as at 20.

### Notes for Reviewers

- The WHERE is placed at analysis because only there is a filter right above the merge TopN surely the WHERE written on the function; later `MergeTopNs`, `RewriteCteChildren`, `InferJoinNotNull` and `InferPredicates` put other filters in the same place. Join runtime filters and TopN filters already stop at a TopN.
- Exec version 20 rather than 19: master BEs built before the Lance row-location reader landed already report 19.
- `LazyMaterializeTopN` now runs at every `topn_lazy_materialization_threshold`, as on 4.2, because the connector decides for a search; tables still follow the threshold (`TopnLazyMaterializeTest`).
- Unlike 4.2: Jackson parses the query vector, stricter than 4.2's Gson (`[1;2]` and comments are refused); an invalid property is named in lower case, as the SPI passes it; SELECT is checked on the table found, not on the name as written.
- Unchanged from 4.2: a search's columns can be fetched late at a TopN that is not its merge TopN (`ORDER BY t.x LIMIT 100000` over a join), outside `topn_lazy_materialization_threshold`; results are right.

### Release note

`vector_search` and `full_text_search` work on `lance` catalogs, served by the Lance connector plugin. Unlike 4.1 and 4.2, only the WHERE written on the function filters the search's candidates; other filters apply to its result, so rows no longer depend on the select list. A search needs SELECT on every column and is refused while a row policy or a data mask applies to the user. `approx_mode` and searching earlier versions, tags or branches are not supported yet.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (the doris-website pages of both functions for the dev version, including the WHERE and privilege rules; to follow)
- Pre-submission status: Partially verified: the suites ran against a local S3 stand-in, not the External pipeline's MinIO; PREPARE forwarded through a follower FE, data masks and column denials from an authorization plugin, and cloud mode were not run (masks and column denials are covered by unit tests)

### AI Disclosure

- Tool: Claude Code (Claude Opus 5.5)
- Generated: the code, the tests, the fixture registration and this description
- Human review: not stated
- Prompts:
  1. Port branch-4.2's `vector_search` / `full_text_search` to master as the next Lance task; show the generic SPI design first.
  2. The design as approved: the 4.2 snapshot plus distance bounds and `prefilter`; the SPI shape as proposed; a new BE exec version 20 as the lazy-fetch fence; two PRs, small fixtures first.
  3. Fix the three problems the self-review found that 4.x also has (filters crossing the merge TopN; row policies, masks and column privileges not applied) in this PR before publishing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Nov 25, 2026
### Background

Doris reads Paimon logical splits through the Rust reader in FileScannerV2. Paimon primary-key vector indexes additionally need bucket-level search plans and metric-aware score materialization.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#69493 (prior ANN implementation), apache#70075 (reserved vector protocol), apache#70598 (Rust 0.5.0)
PR Type: Other

Problem Summary:

Add Rust bucket search readers, request validation, metric-aware distance materialization and native fixture coverage. SQL ANN pushdown, connector search admission/planning and the `vector_search` TVF are still under development, so this PR remains a Draft.

### Details

- **Change map:** Production code: +758/-47 lines across three reader/converter files. Tests and SDK-generated fixture metadata: +1810/-0 lines across 61 files, including binary fixtures. No dependency versions or protocol definitions change.
- **Why Other:** This Draft implements the execution layer; query-planner integration and SQL entry points are incomplete.
- **Behavior change:** Native vector reads consume preplanned bucket payloads and materialize L2 or inner-product distances with the requested SQL/TVF conventions. Connector ranges retain Rust dispatch and distinguish bucket identities. Catalog initialization rejects warehouses containing both `user.sys` and `privilege.sys`; checks and cleanup run inside the authentication context, and metadata access errors propagate.
- **Compatibility:** Use Java Paimon 2.1, paimon-rust 0.5.0 and existing optional Thrift fields. Preserve adaptive batch slicing and predicate profile counters. Mixed-version queries may fail explicitly; process crashes are unacceptable. Rust eager materialization memory budgeting remains a known limitation.

### Testing

- BE build hygiene, clang-format 16 and whitespace checks passed.
- Native fixture cases cover multi-file materialization, SQL/TVF metrics, physical row ranges, NULL vectors, reader reuse, failures, cancellation, score-only projection and malformed requests. Master-native build/runtime validation is in progress.
- External Spark/Doris regression and complete SQL/TVF execution are pending. FULL-mode fixtures do not establish ANN index correctness.

### Notes for Reviewers

The native reader and connector payload transport are implemented; the planner does not emit search requests yet. Complete connector admission and bucket planning, SQL TopN/slot propagation, TVF binding and their FE tests before marking this PR ready.

### Release note

Reject Paimon warehouses using legacy ACL metadata removed in Paimon 2.1. Native primary-key vector search is under development; SQL entry points are not yet available in this Draft.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (document vector search syntax, supported table shapes and legacy ACL rejection with the completed feature)
- Pre-submission status: Not ready: connector search planning, SQL ANN and TVF entry points are incomplete; native runtime and end-to-end validation are pending.

### AI Disclosure

- Tool: OpenAI Codex (GPT-6)
- Generated: Native reader and connector changes, tests and this description, building on the prior work in apache#69493.
- Human review: Not stated for the current changes.

Co-authored-by: dengfangyuan <dengfangyuan@kuaishou.com>
suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Nov 25, 2026
### Background

Doris reads Paimon logical splits through the Rust reader in FileScannerV2. Paimon primary-key vector indexes additionally need bucket-level search plans and metric-aware score materialization.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#69493 (prior ANN implementation), apache#70075 (reserved vector protocol), apache#70598 (Rust 0.5.0)
PR Type: Other

Problem Summary:

Encode vector payloads in connector ranges, retain Rust dispatch and distinct bucket identities, and reject removed legacy warehouse ACLs inside the authentication context. SQL ANN pushdown, connector search admission/planning and the `vector_search` TVF are still under development, so this PR remains a Draft.

### Details

- **Change map:** Production code: +850/-47 lines across six reader, converter and connector files. Tests and SDK-generated fixture metadata: +2140/-0 lines across 64 files, including binary fixtures. No dependency versions or protocol definitions change.
- **Why Other:** This Draft implements the execution layer; query-planner integration and SQL entry points are incomplete.
- **Behavior change:** Native vector reads consume preplanned bucket payloads and materialize L2 or inner-product distances with the requested SQL/TVF conventions. Connector ranges retain Rust dispatch and distinguish bucket identities. Catalog initialization rejects warehouses containing both `user.sys` and `privilege.sys`; checks and cleanup run inside the authentication context, and metadata access errors propagate.
- **Compatibility:** Use Java Paimon 2.1, paimon-rust 0.5.0 and existing optional Thrift fields. Preserve adaptive batch slicing and predicate profile counters. Mixed-version queries may fail explicitly; process crashes are unacceptable. Rust eager materialization memory budgeting remains a known limitation.

### Testing

- Paimon connector reactor build: main/test compilation, Checkstyle and plugin packaging passed. `PaimonCatalogCompatibilityTest`, `PaimonScanRangeReaderTypeTest` and `PaimonVectorPayloadTest`: 15 tests passed, with no failures, errors or skips.
- Connector forbidden-import gate, BE build hygiene, clang-format 16 and whitespace checks passed.
- Native fixture cases cover multi-file materialization, SQL/TVF metrics, physical row ranges, NULL vectors, reader reuse, failures, cancellation, score-only projection and malformed requests. Master-native build/runtime validation is in progress.
- External Spark/Doris regression and complete SQL/TVF execution are pending. FULL-mode fixtures do not establish ANN index correctness.

### Notes for Reviewers

The native reader and connector payload transport are implemented; the planner does not emit search requests yet. Complete connector admission and bucket planning, SQL TopN/slot propagation, TVF binding and their FE tests before marking this PR ready.

### Release note

Reject Paimon warehouses using legacy ACL metadata removed in Paimon 2.1. Native primary-key vector search is under development; SQL entry points are not yet available in this Draft.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (document vector search syntax, supported table shapes and legacy ACL rejection with the completed feature)
- Pre-submission status: Not ready: connector search planning, SQL ANN and TVF entry points are incomplete; native runtime and end-to-end validation are pending.

### AI Disclosure

- Tool: OpenAI Codex (GPT-6)
- Generated: Native reader and connector changes, tests and this description, building on the prior work in apache#69493.
- Human review: Not stated for the current changes.

Co-authored-by: dengfangyuan <dengfangyuan@kuaishou.com>
suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Nov 25, 2026
### Background

Primary-key vector reads need a connector bucket plan and a global TopN above
per-bucket candidates. Master's generic connector scans did not expose this path.

### What problem does this PR solve?

Issue Number: TODO(author): the issue is opened with the PR
Related PR: apache#69493 (original implementation), apache#70704 (master implementation)
PR Type: Feature

Problem Summary:

Connect distance TopN and vector_search to native bucket retrieval through the
connector SPI. Preserve candidate-filter ordering, source privileges, snapshot
pins and conservative SQL fallback. Replace stored SDK tables with runtime
Spark fixtures and verify both indexed and exact-read paths.

### Details

- Scope: VECTOR<FLOAT>, L2 and inner product on admitted primary-key tables.
- Design: immutable SPI33 request, connector-specific admission and bucket
  planning, native Arrow reading, and a retained global TopN.
- Usage: distance TopN SQL or vector_search with optional prefilter/index options.
- Default behavior: existing reader flags gate SQL admission; unsupported SQL
  retains scalar scanning, while unsupported TVF requests fail explicitly.
- Compatibility: existing optional master wire fields; no persisted-format
  change. Live mixed-release operation remains unverified.
- Follow-up plan: Rust eager materialization memory budgeting remains deferred.

### Testing

Standard ASAN build.sh --be --fe and final build.sh --be passed. Native64,
SPI164, targeted connector20, planner/scan18 and source-policy4 tests passed;
additional mapping tests passed. All6 vector/ordinary-reader regression suites
passed in normal comparison, zero failures or skips. Goldens were generated by
the regression harness. Changed-line clang-tidy, clang-format16 and build hygiene
passed. HDFS and live rolling upgrades were not run.

### Release note

Support native primary-key vector retrieval through distance TopN and
vector_search on eligible Paimon2.1 tables.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (follow-up Paimon vector-search documentation)
- Pre-submission status: Partially verified: Feature issue pending; memory
  budgeting and live mixed releases remain unverified

### AI Disclosure

- Tool: Codex (GPT-6)
- Generated: master integration, fixes and tests based on dengfangyuan's work
- Human review: pending author review of this revision

Co-authored-by: dengfangyuan <dengfangyuan@kuaishou.com>
morningman added a commit to morningman/doris that referenced this pull request Nov 28, 2026
…talogs

### Background

Lance datasets carry vector indexes (IVF_FLAT, IVF_PQ, IVF_SQ, IVF_HNSW_*) and full-text indexes. branch-4.1 and branch-4.2 expose them through two table functions, `vector_search(...)` and `full_text_search(...)`: each reads a table of a `lance` catalog and returns its columns plus `_distance` or `_score`; every index segment and every unindexed fragment becomes one scan range, and a Doris TopN merges the ranges' candidates. On master, Lance is a connector plugin (apache#70680), fe-core holds no Lance code, and the BE already executes these searches.

### What problem does this PR solve?

Issue Number: close apache#70970
Related PR: apache#65730, apache#66512, apache#66841, apache#67039, apache#67289, apache#68028, apache#68162, apache#68813, apache#68815 (the branch-4.x implementation this ports), apache#70680 (builds on: the Lance connector plugin)
PR Type: Feature

Problem Summary:

Users of `lance` catalogs lose vector and full-text search on master: both functions fail with `Can not found function 'vector_search'`. They come back with branch-4.2's arguments, defaults, limits, errors and EXPLAIN keys, through a new optional connector SPI: fe-core owns the two functions and the plan rules, the connector parses the arguments and plans the search. Two 4.x problems are fixed on the way: filters other than the function's own WHERE crossed the merge, so rows depended on the select list, and row policies, masks and column privileges did not apply. 60% of the diff is tests. Existing statements are unaffected; connector plugins move to API 38.0.

```sql
SELECT row_id, category, label, _distance
FROM vector_search("table" = "lance_ctl.doris.vs_ivf_pq_f32", "column" = "embedding",
                   "query_vector" = "[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]",
                   "top_k" = "5", "metric" = "l2", "nprobes" = "4", "refine_factor" = "10")
ORDER BY _distance, row_id;
```

| | Result |
|---|---|
| master | `Can not found function 'vector_search'` |
| this PR (same as branch-4.2) | `1 even item-0001 0.0`, `2 odd item-0002 16.0`, `3 even item-0003 64.0`, `4 odd item-0004 144.0`, `5 even item-0005 256.0` |

### Details

- **Change map:** 126 files, +7,321 / -59: production code +2,911 (40%), tests with their generated `.out` +4,397 (60%), docs and build +13. Production code by part, one commit each:
  1. Connector search SPI (+344): `ConnectorSearchOps`, the request, function and result types, the `applyTopnLazyMaterialization` overload with lazy column names, API 37.0 -> 38.0 and its surface baselines.
  2. Engine (+874: fe-core 865, fe-common 4, BE 5): the two functions, routing and the privilege and policy checks (`ExternalSearchTableValuedFunction`); binding with the merge TopN and PREPARE / EXECUTE parameters (`BindExpression`, `LogicalPlanBuilder`, `UnboundTVFRelation`); the WHERE placement (`PushDownWhereThroughSearchTopN`, an analysis rule); lazy materialization admission and hand-off (`MaterializeProbeVisitor`, `LazyMaterializeTopN`, the translator, `PluginDrivenScanNode`); `enable_lance_lazy_materialization`; BE exec version 20.
  3. Lance plugin (+1,693): argument parsing and vector encoding (`LanceSearchArguments`, `LanceVectorQuery`, 865), search planning over index segments and fragments (`LanceScanPlanner`, `LanceSearchPlan`, index metrics, about 470), the search handle, metadata and scan properties (about 360), with its unit tests.
  4. fe-core unit tests. 5. Regression suites, three small fixtures copied from branch-4.2 and their registration.
- **Scope:** `vector_search` over fixed-size-list vector columns of float16, float32, float64, uint8 and int8, with the `l2`, `cosine`, `dot` and `hamming` metrics, index or flat search (`use_index`, `nprobes`, `refine_factor`, `ef`, `query_parallelism`), a Lance `filter` with `prefilter`, and `distance_lower_bound` / `distance_upper_bound`; `full_text_search` with match and phrase queries and the `STRICT` / `INDEX_ONLY` coverage modes; server-side PREPARE with `?` for `vector_search`'s `query_vector`, `top_k`, `offset`, `filter` and both distance bounds. Not supported: `approx_mode` (apache#69852, which master's BE does not read yet), searching earlier versions, tags or branches (apache#68707), `?` in `full_text_search` (refused: `full_text_search properties must be constant in a prepared statement`), and catalogs whose connector does not implement the SPI (refused: `Catalog 'x' does not support vector_search()`). Modules: fe-connector-spi, fe-core, fe-common, fe-connector-lance, and one constant in the BE.
- **Design:** The engine keeps the two function names and routes by the catalog of the `table` argument to `ConnectorSearchOps#prepareSearch`, an optional interface of the connector metadata (implementing it is the declaration, as for `ConnectorFileSourceOps`). The request carries the function, every argument except `table` under its lower-case name, and the names a PREPARE defers; the connector answers with the scan handle, the columns ending with the result column, `top_k`, `offset`, and whether the engine may fetch top-level columns after the merge. The engine owns the result column, the merge order (`_distance` ascending, `_score` descending) and which WHERE filters the candidates. Rejected: plugin-registered function names (one name could belong to one plugin only, while branch-4.2's apache#69493 lets Paimon serve `vector_search` too) and engine-parsed common arguments (Lance and Paimon differ in ranges and in what `filter` means). Proposed in apache#70970, opened with this PR; not discussed yet.
- **Usage:**

  ```sql
  SELECT row_id, _score
  FROM full_text_search("table" = "lance_ctl.doris.full_text_search", "column" = "body",
                        "query" = "lance", "top_k" = "4")
  ORDER BY _score DESC, row_id;

  -- the WHERE written on the function filters the candidates of each range before the merge
  SELECT row_id, _distance
  FROM vector_search("table" = "lance_ctl.doris.vs_ivf_pq_f32", "column" = "embedding",
                     "query_vector" = "[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]", "top_k" = "3") v
  WHERE v.category = 'odd';

  -- as a server-side prepared statement (JDBC with useServerPrepStmts=true), each EXECUTE binding the values
  SELECT row_id, _distance
  FROM vector_search("table" = "lance_ctl.doris.vs_ivf_pq_f32", "column" = "embedding",
                     "query_vector" = ?, "top_k" = ?, "offset" = ?, "filter" = ?)
  ORDER BY _distance, row_id;
  ```

- **Default behavior:** Available on every `lance` catalog. `top_k` 10, `offset` 0, `prefilter` false, and the metric Lance's default (L2), as on branch-4.2. Two-phase fetch is on (`enable_lance_lazy_materialization` = true) once every BE reports exec version 20, and `topn_lazy_materialization_threshold` does not limit a search's TopN.
- **Compatibility:** A rolling upgrade with BEs below exec version 20 plans no row-location fetch and keeps the plain TopN, with the same rows. No Thrift or Protobuf change: the request fields already exist on master and branch-4.2. Nothing is persisted. Connector plugins built against earlier API majors are refused by the version gate, as after every SPI surface change.
- **Behavior change:** Two differences for users coming from 4.1 or 4.2. On 4.x, any filter that reaches the merge TopN with no column pruning in between moves below it, so rows depend on the select list: `SELECT v.*, w.row_id AS w_row_id FROM vector_search(... "top_k" = "3", "use_index" = "false") v JOIN lance_ctl.doris.vs_ivf_pq_f32 w ON v.row_id = w.row_id WHERE w.row_id > 2` returns rows 3, 513 and 514 there (the inferred `v.row_id > 2` filtered the candidates), and row 3 with three columns of `v`. Here only the WHERE written on the function (`FROM vector_search(...) [alias] WHERE ...`) filters the candidates; outer WHEREs, CTE consumer filters, a WHERE over a join and inferred predicates apply to the result, so the query returns row 3. Second, the privilege rules below.
- **Security and privileges:** SELECT on the table is checked before the connector is called, as on 4.2; then SELECT on every column, since the arguments (the searched column, a `filter`) may read any. A search is refused while a row policy or a data mask applies to the user (`vector_search() is not supported on table '<table>' while row policies apply to it for the current user`), since it can apply neither; `root` and `admin` are exempt, as from row policies on scans. No new outbound host.
- **Follow-up plan:** A second PR ports branch-4.2's coverage suites that need the large fixtures (index types, IVF_FLAT, the index matrix, indexed element types, metrics, multivector) together with the generators of those fixtures; apache#68707 and apache#69852 come after it.

### Testing

All local, on a Mac (arm64), on the head unless noted.

- fe-core, 185 tests in 20 classes: the search classes, including `SearchWherePlacementTest`, which plans SQL through the whole analyzer and rewriter against a mocked connector; the lazy-materialization classes; and the analysis and CTE classes that meet the changed analyzer. Lance plugin, 317 tests; connector SPI, 172 (before the last javadoc-only change).
- 32 single-point mutations of this PR's decisions, in three rounds, each turning only its target tests red; putting the WHERE rule back into the rewriter, as on 4.x, fails the CTE, join and outer-LIMIT cases.
- One FE and one BE built from this branch (the BE from an earlier commit with the same BE change), a read-only S3 server standing in for MinIO: all 17 suites in `external_table_p0/lance` pass, including the six ported suites, whose `.out` files match branch-4.2's, and `test_lance_search_where_and_policy`, which tests the policy as a non-root user. On an FE with the 4.x rule, the suite's outer-LIMIT and CTE queries and the join query above return the 4.x rows, and a user reads rows their row policy hides.
- Rolling upgrade: at `be_exec_version` 19 the search plans no `VMaterializeNode` and returns the same rows as at 20.

### Notes for Reviewers

- The WHERE is placed at analysis because only there is a filter right above the merge TopN surely the WHERE written on the function; later `MergeTopNs`, `RewriteCteChildren`, `InferJoinNotNull` and `InferPredicates` put other filters in the same place. Join runtime filters and TopN filters already stop at a TopN.
- Exec version 20 rather than 19: master BEs built before the Lance row-location reader landed already report 19.
- `LazyMaterializeTopN` now runs at every `topn_lazy_materialization_threshold`, as on 4.2, because the connector decides for a search; tables still follow the threshold (`TopnLazyMaterializeTest`).
- Unlike 4.2: Jackson parses the query vector, stricter than 4.2's Gson (`[1;2]` and comments are refused); an invalid property is named in lower case, as the SPI passes it; SELECT is checked on the table found, not on the name as written.
- Unchanged from 4.2: a search's columns can be fetched late at a TopN that is not its merge TopN (`ORDER BY t.x LIMIT 100000` over a join), outside `topn_lazy_materialization_threshold`; results are right.

### Release note

`vector_search` and `full_text_search` work on `lance` catalogs, served by the Lance connector plugin. Unlike 4.1 and 4.2, only the WHERE written on the function filters the search's candidates; other filters apply to its result, so rows no longer depend on the select list. A search needs SELECT on every column and is refused while a row policy or a data mask applies to the user. `approx_mode` and searching earlier versions, tags or branches are not supported yet.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (the doris-website pages of both functions for the dev version, including the WHERE and privilege rules; to follow)
- Pre-submission status: Partially verified: the suites ran against a local S3 stand-in, not the External pipeline's MinIO; PREPARE forwarded through a follower FE, data masks and column denials from an authorization plugin, and cloud mode were not run (masks and column denials are covered by unit tests)

### AI Disclosure

- Tool: Claude Code (Claude Opus 5.5)
- Generated: the code, the tests, the fixture registration and this description
- Human review: not stated
- Prompts:
  1. Port branch-4.2's `vector_search` / `full_text_search` to master as the next Lance task; show the generic SPI design first.
  2. The design as approved: the 4.2 snapshot plus distance bounds and `prefilter`; the SPI shape as proposed; a new BE exec version 20 as the lazy-fetch fence; two PRs, small fixtures first.
  3. Fix the three problems the self-review found that 4.x also has (filters crossing the merge TopN; row policies, masks and column privileges not applied) in this PR before publishing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
morningman added a commit that referenced this pull request Nov 29, 2026
…talogs (#70971)

### Background

Lance datasets carry vector indexes (IVF_FLAT, IVF_PQ, IVF_SQ,
IVF_HNSW_*) and full-text indexes. branch-4.1 and branch-4.2 expose them
through two table functions, `vector_search(...)` and
`full_text_search(...)`: each reads a table of a `lance` catalog and
returns its columns plus `_distance` or `_score`; every index segment
and every unindexed fragment becomes one scan range, and a Doris TopN
merges the ranges' candidates. On master, Lance is a connector plugin
(#70680), fe-core holds no Lance code, and the BE already executes these
searches.

### What problem does this PR solve?

Issue Number: close #70970
Related PR: #65730, #66512, #66841, #67039, #67289, #68028, #68162,
#68813, #68815 (the branch-4.x implementation this ports), #70680
(builds on: the Lance connector plugin)
PR Type: Feature

Problem Summary:

Users of `lance` catalogs lose vector and full-text search on master:
both functions fail with `Can not found function 'vector_search'`. They
come back with branch-4.2's arguments, defaults, limits, errors and
EXPLAIN keys, through a new optional connector SPI: fe-core owns the two
functions and the plan rules, the connector parses the arguments and
plans the search. Two 4.x problems are fixed on the way: filters other
than the function's own WHERE crossed the merge, so rows depended on the
select list, and row policies, masks and column privileges did not
apply. 60% of the diff is tests. Existing statements are unaffected;
connector plugins move to API 38.0.

```sql
SELECT row_id, category, label, _distance
FROM vector_search("table" = "lance_ctl.doris.vs_ivf_pq_f32", "column" = "embedding",
                   "query_vector" = "[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]",
                   "top_k" = "5", "metric" = "l2", "nprobes" = "4", "refine_factor" = "10")
ORDER BY _distance, row_id;
```

| | Result |
|---|---|
| master | `Can not found function 'vector_search'` |
| this PR (same as branch-4.2) | `1 even item-0001 0.0`, `2 odd
item-0002 16.0`, `3 even item-0003 64.0`, `4 odd item-0004 144.0`, `5
even item-0005 256.0` |

### Details

- **Change map:** 126 files, +7,315 / -59: production code +2,911 (40%),
tests with their generated `.out` +4,391 (60%), docs and build +13. The
six commits cover:
1. Connector search SPI (+344): `ConnectorSearchOps`, the request,
function and result types, the `applyTopnLazyMaterialization` overload
with lazy column names, API 37.0 -> 38.0 and its surface baselines.
2. Engine (+874: fe-core 865, fe-common 4, BE 5): the two functions,
routing and the privilege and policy checks
(`ExternalSearchTableValuedFunction`); binding with the merge TopN and
PREPARE / EXECUTE parameters (`BindExpression`, `LogicalPlanBuilder`,
`UnboundTVFRelation`); the WHERE placement
(`PushDownWhereThroughSearchTopN`, an analysis rule); lazy
materialization admission and hand-off (`MaterializeProbeVisitor`,
`LazyMaterializeTopN`, the translator, `PluginDrivenScanNode`);
`enable_lance_lazy_materialization`; BE exec version 20.
3. Lance plugin (+1,693): argument parsing and vector encoding
(`LanceSearchArguments`, `LanceVectorQuery`, 865), search planning over
index segments and fragments (`LanceScanPlanner`, `LanceSearchPlan`,
index metrics, about 470), the search handle, metadata and scan
properties (about 360), with its unit tests.
4. fe-core unit tests. 5. Regression suites, three small fixtures copied
from branch-4.2 and their registration. 6. Nullable INT8 vector-search
regression.
- **Scope:** `vector_search` over fixed-size-list vector columns of
float16, float32, float64, uint8 and int8, with the `l2`, `cosine`,
`dot` and `hamming` metrics, index or flat search (`use_index`,
`nprobes`, `refine_factor`, `ef`, `query_parallelism`), a Lance `filter`
with `prefilter`, and `distance_lower_bound` / `distance_upper_bound`;
`full_text_search` with match and phrase queries and the `STRICT` /
`INDEX_ONLY` coverage modes; server-side PREPARE with `?` for
`vector_search`'s `query_vector`, `top_k`, `offset`, `filter` and both
distance bounds. Not supported: `approx_mode` (#69852, which master's BE
does not read yet), searching earlier versions, tags or branches
(#68707), `?` in `full_text_search` (refused: `full_text_search
properties must be constant in a prepared statement`), and catalogs
whose connector does not implement the SPI (refused: `Catalog 'x' does
not support vector_search()`). Modules: fe-connector-spi, fe-core,
fe-common, fe-connector-lance, and one constant in the BE.
- **Design:** The engine keeps the two function names and routes by the
catalog of the `table` argument to `ConnectorSearchOps#prepareSearch`,
an optional interface of the connector metadata (implementing it is the
declaration, as for `ConnectorFileSourceOps`). The request carries the
function, every argument except `table` under its lower-case name, and
the names a PREPARE defers; the connector answers with the scan handle,
the columns ending with the result column, `top_k`, `offset`, and
whether the engine may fetch top-level columns after the merge. The
engine owns the result column, the merge order (`_distance` ascending,
`_score` descending) and which WHERE filters the candidates. Rejected:
plugin-registered function names (one name could belong to one plugin
only, while branch-4.2's #69493 lets Paimon serve `vector_search` too)
and engine-parsed common arguments (Lance and Paimon differ in ranges
and in what `filter` means). Proposed in #70970, opened with this PR;
not discussed yet.
- **Usage:**

  ```sql
  SELECT row_id, _score
FROM full_text_search("table" = "lance_ctl.doris.full_text_search",
"column" = "body",
                        "query" = "lance", "top_k" = "4")
  ORDER BY _score DESC, row_id;

-- the WHERE written on the function filters the candidates of each
range before the merge
  SELECT row_id, _distance
FROM vector_search("table" = "lance_ctl.doris.vs_ivf_pq_f32", "column" =
"embedding",
"query_vector" = "[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]", "top_k" =
"3") v
  WHERE v.category = 'odd';

-- as a server-side prepared statement (JDBC with
useServerPrepStmts=true), each EXECUTE binding the values
  SELECT row_id, _distance
FROM vector_search("table" = "lance_ctl.doris.vs_ivf_pq_f32", "column" =
"embedding",
"query_vector" = ?, "top_k" = ?, "offset" = ?, "filter" = ?)
  ORDER BY _distance, row_id;
  ```

- **Default behavior:** Available on every `lance` catalog. `top_k` 10,
`offset` 0, `prefilter` false, and the metric Lance's default (L2), as
on branch-4.2. Two-phase fetch is on
(`enable_lance_lazy_materialization` = true) once every BE reports exec
version 20, and `topn_lazy_materialization_threshold` does not limit a
search's TopN.
- **Compatibility:** A rolling upgrade with BEs below exec version 20
plans no row-location fetch and keeps the plain TopN, with the same
rows. No Thrift or Protobuf change: the request fields already exist on
master and branch-4.2. Nothing is persisted. Connector plugins built
against earlier API majors are refused by the version gate, as after
every SPI surface change.
- **Behavior change:** Two differences for users coming from 4.1 or 4.2.
On 4.x, any filter that reaches the merge TopN with no column pruning in
between moves below it, so rows depend on the select list: `SELECT v.*,
w.row_id AS w_row_id FROM vector_search(... "top_k" = "3", "use_index" =
"false") v JOIN lance_ctl.doris.vs_ivf_pq_f32 w ON v.row_id = w.row_id
WHERE w.row_id > 2` returns rows 3, 513 and 514 there (the inferred
`v.row_id > 2` filtered the candidates), and row 3 with three columns of
`v`. Here only the WHERE written on the function (`FROM
vector_search(...) [alias] WHERE ...`) filters the candidates; outer
WHEREs, CTE consumer filters, a WHERE over a join and inferred
predicates apply to the result, so the query returns row 3. Second, the
privilege rules below.
- **Security and privileges:** SELECT on the table is checked before the
connector is called, as on 4.2; then SELECT on every column, since the
arguments (the searched column, a `filter`) may read any. A search is
refused while a row policy or a data mask applies to the user
(`vector_search() is not supported on table '<table>' while row policies
apply to it for the current user`), since it can apply neither; `root`
and `admin` are exempt, as from row policies on scans. No new outbound
host.
- **Follow-up plan:** A second PR ports branch-4.2's coverage suites
that need the large fixtures (index types, IVF_FLAT, the index matrix,
indexed element types, metrics, multivector) together with the
generators of those fixtures; #68707 and #69852 come after it.

### Testing

Initial feature validation ran locally on macOS (arm64) before the
rebase.

- fe-core, 185 tests in 20 classes: the search classes, including
`SearchWherePlacementTest`, which plans SQL through the whole analyzer
and rewriter against a mocked connector; the lazy-materialization
classes; and the analysis and CTE classes that meet the changed
analyzer. Lance plugin, 317 tests; connector SPI, 172 (before the last
javadoc-only change).
- 32 single-point mutations of this PR's decisions, in three rounds,
each turning only its target tests red; putting the WHERE rule back into
the rewriter, as on 4.x, fails the CTE, join and outer-LIMIT cases.
- One FE and one BE built from this branch (the BE from an earlier
commit with the same BE change), a read-only S3 server standing in for
MinIO: all 17 suites in `external_table_p0/lance` pass, including the
six ported suites, whose `.out` files match branch-4.2's, and
`test_lance_search_where_and_policy`, which tests the policy as a
non-root user. On an FE with the 4.x rule, the suite's outer-LIMIT and
CTE queries and the join query above return the 4.x rows, and a user
reads rows their row policy hides.
- Rolling upgrade: at `be_exec_version` 19 the search plans no
`VMaterializeNode` and returns the same rows as at 20.

- Review follow-up: four Lance vector-search regression suites passed
against the local pre-rebase binaries and S3 fixture service. The new
nullable INT8 case returned only row 1 at distance zero. The IVF_PQ
EXPLAIN reported `USED`, one index segment, and coverage of both
fragments.
- After rebasing, 96 targeted FE tests passed (32 FE Core, 12 connector
SPI and 52 Lance connector). Checkstyle passed for all three modules.

### Notes for Reviewers

- The WHERE is placed at analysis because only there is a filter right
above the merge TopN surely the WHERE written on the function; later
`MergeTopNs`, `RewriteCteChildren`, `InferJoinNotNull` and
`InferPredicates` put other filters in the same place. Join runtime
filters and TopN filters already stop at a TopN.
- Lance-C's pinned Lance revision preserves nulls during INT8
conversion. The Java SDK reports `metric_type` for both committed IVF
fixtures, while `distance_type` is part of the index file.
- Exec version 20 rather than 19: master BEs built before the Lance
row-location reader landed already report 19.
- `LazyMaterializeTopN` now runs at every
`topn_lazy_materialization_threshold`, as on 4.2, because the connector
decides for a search; tables still follow the threshold
(`TopnLazyMaterializeTest`).
- Unlike 4.2: Jackson parses the query vector, stricter than 4.2's Gson
(`[1;2]` and comments are refused); an invalid property is named in
lower case, as the SPI passes it; SELECT is checked on the table found,
not on the name as written.
- Unchanged from 4.2: a search's columns can be fetched late at a TopN
that is not its merge TopN (`ORDER BY t.x LIMIT 100000` over a join),
outside `topn_lazy_materialization_threshold`; results are right.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants