morningman opened a new pull request, #71125:
URL: https://github.com/apache/doris/pull/71125
### Background
A Lance dataset keeps a chain of numbered versions; a tag names one version,
and a branch is a separate chain forked from one, stored under `tree/<name>/`.
A REST namespace may also manage a table's versions (`managed_versioning =
true`): it records which versions exist, and the newest manifest in storage may
not be published yet. On master, Lance catalogs run as the `fe-connector-lance`
plugin, which reads the latest version or one chosen with `FOR VERSION AS OF
<n>` / `FOR TIME AS OF` on the main chain. fe-core rejects a relation that has
both a `FOR ... AS OF` clause and a scan parameter such as `@branch`.
### What problem does this PR solve?
Issue Number: close #71124
Related PR: #68453 (the branch-4.1 / branch-4.2 implementation this ports,
closing #66491)
PR Type: Feature
Problem Summary:
Lance tables with tags, branches, or versions managed by a REST namespace
cannot be read on master, while 4.1.5 and branch-4.2 read them since #68453.
This PR ports that support to the Lance connector plugin: `@tag`, `@branch`, a
tag name in `FOR VERSION AS OF`, `FOR VERSION / TIME AS OF` inside an `@branch`
on the branch's own chain, and managed tables whose versions come from the
namespace. The `@branch` plus `FOR ... AS OF` case needs a small SPI addition,
because fe-core refused that combination for every connector; other connectors
keep the refusal. Three quarters of the diff is tests. No BE or thrift change,
and queries without these selectors are unchanged.
| Query (outputs from runs) | Before (master `d97993b7256`) | After |
|---|---|---|
| `SELECT * FROM t@tag(v2)` | `Lance tables do not support @tag yet; read a
version with FOR VERSION AS OF or FOR TIME AS OF instead` | rows 1 to 6
(version 2) |
| `SELECT count(*), max(row_id) FROM t@branch(dev) FOR VERSION AS OF 3` |
`Can not specify scan params and table snapshot at same time.` | `7 100`
(main's version 3: `9 9`) |
| `SELECT count(*), max(row_id) FROM managed_lagging` (namespace records
versions 1 and 2, storage has 3) | `Lance table
default.time_travel_managed_lagging has its versions managed by the namespace
(managed_versioning), which is not supported yet` | `6 6` (version 2) |
### Details
- **Change map:** production code +1202 / -165 in 16 files, tests +3256 /
-76 in 43 files plus +285 lines of `.out`, one pom line. One commit per part,
in reading order:
1. SPI (+61): `ConnectorCapability.SUPPORTS_BRANCH_TIME_TRAVEL`,
`ConnectorTimeTravelSpec#withinBranch` / `#getBranch`, connector plugin API
38.0 to 39.0.
2. fe-core (+35): `PluginDrivenMvccExternalTable` passes `@branch` plus a
snapshot to a connector that declares the capability; the search functions'
`table` argument gets a clear error for a selector.
3. Lance plugin (+1106): tag and branch selection (`LanceRefSelector`,
`LanceCatalogClient`), managed versions through the namespace
(`LanceNamespaceClient`, `LanceManifestPaths`), branch-aware statement memo
keys and EXPLAIN fields.
4. Fixture: `time_travel.lance` and its generator copied from branch-4.2;
the REST stub serves `ListTableVersions` / `DescribeTableVersion` for eight
managed tables declared in the compose file.
5. Regression suites and one connector-level unit test.
- **Scope:** Filesystem and REST Lance catalogs, with the selectors in
Usage; `main` is the main chain, and a tag also selects its branch. Managed
tables: latest from `ListTableVersions`, explicit versions checked with
`DescribeTableVersion`, `FOR TIME AS OF` only among recorded versions. Refused
with an error: `@tag` with `FOR ... AS OF`, a tag name inside `@branch`, a
selector in a search function's `table`, a version recorded only at a staged
manifest (a commit the namespace reserved but did not finalize), and a recorded
manifest path other than the one Doris reads. Out of scope: creating or
dropping tags and branches, and writes. Other connectors do not change.
- **Design:** The Lance behavior and error texts follow #68453. For
`@branch` with `FOR ... AS OF`, the spec carried one selector and fe-core
refused the combination. Chosen: a catalog-wide capability plus a branch
qualifier on SNAPSHOT_ID, VERSION_REF and TIMESTAMP specs, qualified only for
declaring connectors, since one that ignored the qualifier would read its main
chain. Catalog-wide because fe-core decides before reading the table, whose
latest schema a branch read may not reach. Rejected: no SPI change and dropping
about ten such cases, which loses a capability 4.1.5 ships; passing raw scan
parameters through the SPI to keep branch-4.2's Lance-only "takes exactly one
name" check, which adds surface for one message. So extra `@tag` / `@branch`
parameters are ignored, as for Iceberg and Paimon. Proposed in #71124, opened
with this PR; not discussed yet.
- **Usage:**
```sql
SELECT * FROM lance_ctl.db.t@tag(v2);
SELECT * FROM lance_ctl.db.t FOR VERSION AS OF 'v2'; -- a tag
SELECT * FROM lance_ctl.db.t@branch(dev);
SELECT * FROM lance_ctl.db.t@branch(dev) FOR VERSION AS OF 3;
SELECT * FROM lance_ctl.db.t@branch(dev) FOR TIME AS OF '2026-09-19
13:06:10';
SELECT * FROM lance_rest.db.managed_t FOR VERSION AS OF 2; --
managed_versioning = true
EXPLAIN SELECT * FROM lance_ctl.db.t@branch(dev); --
lanceBranch=dev
```
- **Default behavior:** No switch; every Lance catalog supports it. Whether
a REST table is managed comes from the namespace's `DescribeTable`.
- **Compatibility:** The connector plugin API goes from 38.0 to 39.0, so the
version gate rejects connector plugins built against 38.x until they are
rebuilt; the in-tree ones are built with the FE. Nothing is persisted: the
branch travels in the statement's snapshot pin, not in the EditLog or image,
and no thrift or protobuf message changes. The BE gets a branch as a dataset
URI and version, which today's BE already reads, so a rolling upgrade works in
any order; an FE without this change keeps refusing these selectors. Downgrade
leaves nothing behind.
- **Behavior change:** EXPLAIN of a Lance scan adds
`lanceManagedVersioning=<true|false>`, and `lanceBranch=<name>` on a branch. A
main-chain `FOR TIME AS OF` now checks the chosen version out of the already
open latest dataset instead of opening it again: same result, different Lance
metadata profile counts.
- **Security and privileges:** No new host: the managed-version calls go to
the catalog's existing `lance.rest.uri`, already in the connector's SSRF
surface, and storage is read where `DescribeTable` says, as before. Recorded
manifest paths are compared, never opened. Reading needs SELECT on the table,
as before.
### Testing
- Regression, local (macOS arm64; FE built from `72a30ab9c97`, the head
minus the suites; BE from an older master, `8ede923c73a`, whose later BE
commits do not touch the Lance reader; a read-only S3 stand-in and the REST
stub, run with the compose file's values, in place of the MinIO and lance-rest
containers): `test_lance_time_travel` (30 result blocks),
`test_lance_rest_time_travel` (30) and `test_lance_rest_catalog` pass, and
their `.out` files are byte-identical to the ones #68453 generated on
branch-4.2. All 19 Lance suites pass.
- Mutations, each reverted afterwards: with a plugin jar that drops the
engine's branch qualifier, both time-travel suites fail on the cluster
(`@branch(dev) FOR TIME AS OF '2026-09-19 13:06:10'` raised no error;
`managed_branch_dev_time` returned `9` instead of `7 100`), and
`snapshotsWithinABranchResolveOnTheBranchChain` fails. Selectors that never
name a branch fail 10 plugin tests; a managed table's newest version taken from
storage fails 9 (`latestVersionComesFromNamespaceNotStorage`: 3 instead of 2);
accepting any recorded manifest path fails 3; treating staged manifests as
canonical fails 4; fe-core combining without the capability, or for `@tag`,
fails 3 tests in `PluginDrivenMvccExternalTableTest`.
- Unit tests, local, with checkstyle: fe-connector-spi
`ConnectorTimeTravelSpecTest` and `ConnectorPluginSurfaceTest` (13);
fe-connector-lance 359 at the head, among them `LanceManagedVersioningTest`
(27, real JNI; `@Disabled` on branch-4.2), `LanceManagedAccessTest`,
`LanceManifestPathsTest`, `LanceSnapshotResolverTest` (with 20,000 random
histories) and `LanceConnectorNativeTest`; fe-core
`PluginDrivenMvccExternalTableTest` (120) and
`ExternalSearchTableValuedFunctionTest` (12). Native Lance tests skip on hosts
that cannot load the Lance JNI library; none skipped here.
### Notes for Reviewers
- Original author of the branch-4.1 / branch-4.2 implementation, fixture and
suites: @zy-kkk (#68453).
- The suites differ from branch-4.2 in four places: no
`enable_file_scanner_v2` (deprecated on master, where file scans always use
V2), no `DROP CATALOG` at the end (dropped before use instead), no case for
extra `@tag` parameters (see Design), and `@tag(v2) FOR VERSION AS OF 1`
expects fe-core's refusal instead of a Lance one.
- `LanceManagedVersioningTest` is `@Disabled` on branch-4.2 (C++ ABI on its
CI) and runs here as a native test through a small adapter. Master's
managed-table refusal cases are gone from `LanceRestCatalogTest`,
`LanceTableAccessCacheTest` and `test_lance_rest_catalog`.
- `PluginDrivenMvccExternalTable` now initializes the catalog before raising
the mutual-exclusion error, because the error depends on the connector's
capabilities; nothing else is reordered.
- Release note is None because 4.1.5 already reads all of this; the PR keeps
master at parity.
### Release note
None
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No (the Lance catalog page already documents
these selectors and the managed-versioning rules, in the dev docs and, since
apache/doris-website#4172, for 4.x)
- Pre-submission status: Partially verified: not run on the External
pipeline's MinIO and lance-rest containers or on Linux; the local BE predates
master's latest BE commits, none of which touches the Lance reader
### AI Disclosure
- Tool: Claude Code (Claude Opus 5.5)
- Generated: the master port of the plugin code, the SPI and fe-core
changes, the test adaptations, the new connector-level test and this
description; the fixture, its generator, the suites and most plugin tests are
ported from branch-4.2 (#68453)
- Human review: not stated
- Prompts: The author asked to port branch-4.2's Lance time travel, tag,
branch and managed-versioning support to master's connector plugin. When the
agent found that master's SPI could not express `@branch` with `FOR VERSION /
TIME AS OF`, the author chose a new capability plus a branch qualifier on the
time-travel spec over dropping those cases, kept master's lenient `@tag` /
`@branch` parameters, and a connector-neutral error for a selector in a search
function's `table`; then asked to continue to the PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]