Skip to content

[refactor](lance) improve lance catalog implementation in FE - #66581

Merged
yiguolei merged 2 commits into
apache:branch-4.1from
zhangstar333:lance-refactor-code
Aug 7, 2026
Merged

yiguolei merged 2 commits into
apache:branch-4.1from
zhangstar333:lance-refactor-code

Conversation

@zhangstar333

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Problem Summary:
refactor some code including:

  • Adds dedicated properties for filesystem and REST catalogs.
  • Uses the Lance tableExists API for table existence checks.
  • Refactors metadata loading and snapshot version resolution.
  • Improves method naming and documentation for readability.

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@zhangstar333
zhangstar333 requested a review from yiguolei as a code owner August 7, 2026 09:19
@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?

@zhangstar333

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor

I found one blocking compatibility issue with the tableExist change.

LanceExternalCatalog.tableExist() now calls namespace.tableExists(), which uses POST /v1/table/:id/exists for a REST namespace. However, the existing Doris Lance REST fixture (docker/thirdparties/docker-compose/iceberg/scripts/lance_rest_server.py) only implements ListNamespaces, ListTables, and DescribeTable; every other POST request returns 404. The unit-test mock in LanceRestCatalogTest has the same limitation.

Consequently, a table that can be listed and described successfully by the currently supported REST fixture can be reported as non-existent (or fail with an exception, depending on the SDK error mapping) whenever a caller uses tableExist().

Please update the REST fixture and unit-test mock to implement the table-exists endpoint, and add coverage for:

  • an existing table;
  • a missing table/namespace;
  • authentication or service errors, which must not be converted to false.

If Doris intends to remain compatible with namespace implementations that support List/Describe but not TableExists, please also fall back to describeTable() when TableExists is unsupported.

Also, the PR checklist currently says that this is a pure refactor with no behavior change and no tests needed. That is inaccurate: the previous implementation converted every RuntimeException to false, while the new implementation only converts explicit not-found errors and propagates other failures. This is a desirable behavior change, but it should be documented in the PR description and covered by tests.

@zhangstar333

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 66.67% (160/240) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 59.17% (142/240) 🎉
Increment coverage report
Complete coverage report

@yiguolei
yiguolei merged commit 8375559 into apache:branch-4.1 Aug 7, 2026
29 of 32 checks passed
yiguolei pushed a commit that referenced this pull request Aug 14, 2026
### What problem does this PR solve?

Issue Number: N/A

Related PR: #65730, #66581

Problem Summary:

Ordinary Lance scans currently read **every row of a fragment** even
when the
query only needs the first N rows (e.g. `SELECT ... LIMIT 10`). Lance
applies
its own LIMIT *after* the scanner's filter, so the query LIMIT can be
forwarded
to each fragment scanner and let it stop early, cutting IO and decode
cost.

**How it is fixed**

- `thrift`: add an optional `TLanceFileDesc.limit`.
- `FE` (`LanceScanNode`): push the query limit into each fragment split
via
  `canPushDownLimit()`, and surface `lanceLimit` in the explain output.
- `BE` (`lance_reader`): forward it to the scanner through
`lance_scanner_set_limit` for ordinary scans; vector search keeps its
own
  `top_k` limit.

**Correctness**

The limit is pushed **only when all predicates are already pushed into
Lance**
(no residual Doris conjunct). Otherwise Doris still re-filters the
returned rows,
and truncating a fragment early could drop valid results.

`OFFSET` needs no special handling: Nereids' `SplitLimit` rewrites
`Limit(limit, offset)` into a global `Limit(limit, offset)` over a local
`Limit(limit + offset, 0)`, and that local bound is what reaches the
scan node.
So `getLimit()` already includes the offset; each fragment fetches up to
`limit + offset` rows and the upper global LIMIT still applies the
offset and
the final bound. Per-fragment truncation is therefore always safe.

**Behavior change**

Query results are unchanged. Only the number of rows scanned per
fragment is
reduced for LIMIT queries; the explain output shows an extra
`lanceLimit=N`
line when the limit is pushed.

### Release note

Push down LIMIT into Lance fragment scanners to reduce the rows scanned
for
`LIMIT` / `LIMIT ... OFFSET` queries over Lance tables.

### Check List (For Author)

- Test
- [x] Unit Test (`LanceThriftContractTest` covers the limit round-trip
and the no-limit case)
- [ ] Manual test — `SELECT * FROM <lance_tbl> LIMIT 10` returns 10 rows
and `EXPLAIN` shows `lanceLimit=10`; a query with a non-pushable
predicate keeps the limit out of the scan
- Behavior changed:
  - [x] No.
- Does this need documentation?
  - [x] No.
morningman added a commit that referenced this pull request Nov 18, 2026
…ogs and basic reads (#70681)

### Background

Lance datasets store schemas, versions and fragment lists in manifests.
FE reads those manifests to plan a query, and BE reads the fragments
through lance-c. Doris 4.1/4.2 provide Lance catalogs in fe-core; master
uses connector plugins and already has the BE reader (#69581) and legacy
image migration (#69575).

### What problem does this PR solve?

Issue Number: #70680
Related PR: #65730, #66581, #66597, #66805 (source read-path changes);
#70338 (secret masking), #70351 (TIMEV2 precision), #69581 (BE reader),
#69575 (legacy images)
PR Type: Feature

Problem Summary:

Master has no plugin serving the `lance` catalog type, so users cannot
query Lance catalogs after upgrading from 4.1/4.2. This ports the first
part of that read path: filesystem catalogs, static S3 credentials,
Arrow type mapping, basic scans and main-chain time travel. The plugin
also needs JNI packaging and resource management; other catalog types
keep their existing behavior.

### Details

- **Change map:** 57 files, +6732/-2: production code +3377, tests
+2974, generated test output +75, build/CI +306/-2. Production has four
parts: property binding and namespace lifetime; schema and version
resolution; S3 storage-option translation shared by FE/BE; fragment scan
planning. Tests cover those contracts, native datasets and a regression
suite. Packaging registers the module, plugin distribution, JNI
replacement and MinIO fixture.
- **Scope:** Local/file and S3 filesystem catalogs; `SHOW
DATABASES/TABLES`, `DESC`, `SELECT`, `FOR VERSION AS OF n`, and `FOR
TIME AS OF 'yyyy-MM-dd HH:mm:ss[.SSS]'`. REST catalogs fail explicitly
until the next PR, including first access to replayed REST catalogs.
Tags, branches, OSS warehouses, pushdown and writes are outside this PR.
S3 access without static AK/SK, including anonymous and credential-chain
access, fails explicitly. AssumeRole is also rejected, even when source
AK/SK are provided.
- **Design:** Follow the existing connector plugins, rather than add
Lance catalog classes to fe-core. The plugin opts into MVCC and memoizes
metadata per statement, so schema, fragments, statistics and BE ranges
use one immutable dataset version. Ordinary query pins retain their
schema across the engine schema-cache boundary; historical statistics
also apply the snapshot to unpinned handles. Time travel compares
manifest commit times at their original precision in the session time
zone. The final S3 endpoint fills both native endpoint coordinates after
namespace options are merged, preventing ambient AWS endpoint overrides
while preserving namespace service-endpoint precedence. Each fragment
becomes one scan range. An in-flight call count delays native resource
disposal after catalog retirement. Proposed in #70680, opened with this
PR; no community design discussion has taken place yet.
- **Usage:**

  ```sql
  CREATE CATALOG lance_s3 PROPERTIES (
      "type" = "lance",
      "warehouse" = "s3://warehouse/lance",
      "s3.endpoint" = "http://127.0.0.1:9000",
      "s3.access_key" = "admin",
      "s3.secret_key" = "password",
      "s3.region" = "us-east-1",
      "use_path_style" = "true"
  );
  SELECT count(*) FROM lance_s3.`default`.all_types FOR VERSION AS OF 1;
  SELECT count(*) FROM lance_s3.`default`.all_types
      FOR TIME AS OF '2026-07-30 10:11:50';
  ```

- **Default behavior:** Enabled by creating a Lance catalog.
`lance.conf` contains the optional
`lance_catalog_arrow_memory_limit_bytes`, default 256 MiB per catalog;
changes require an FE restart.
- **Compatibility:** Preserve the 4.1/4.2 property map and names. Legacy
catalogs use the existing image migration. The Arrow memory setting
moves from fe.conf to lance.conf; copy any customized value. `SHOW
CREATE TABLE` uses `ENGINE=lance`, as other plugins do. No Thrift or
persisted-metadata format changes. BE needs #69581; projecting Arrow
Null, Duration, JSON or bfloat16 fences out smooth-upgrade source BEs.
Newer catalog features remain unsupported during this staged port. Both
cloud and shared-nothing use this planning path; a cloud deployment was
not tested locally.
- **Persistence and failure handling:** Catalog metadata uses the
existing plugin catalog journal/image path; dataset contents are
read-only. The namespace opens lazily, avoiding storage I/O and JNI
loading during replay. Missing versions and unavailable native libraries
fail explicitly. Statement cleanup releases its metadata memo; dropping
or altering a catalog retires its client and closes resources after
active calls finish.
- **Security and privileges:** CREATE_PRIV permits catalog creation;
ALTER_PRIV is required to change its properties. FE and BE make outbound
HTTP requests to the configured S3 endpoint, an SSRF surface. The
provider declares S3-compatible endpoint aliases for the existing
CREATE/ALTER gate when `security_checker_class_name` is configured. REST
credential keys are declared for masking even though REST reads are
deferred. Build-time JNI replacement downloads fixed, checksum-pinned
Lance JNI and Apache Arrow Java source assets.
- **Follow-up plan:** REST/OSS and namespace-vended credentials;
predicate/LIMIT/COUNT pushdown, fragment grouping and scalar indexes;
then session/table caches and profile counters. Search TVFs, index
operations and tag/branch/managed versioning follow separately under
#70680.

### Testing

- Storage/JNI fixes at `536982b`, macOS arm64/JDK 17: all 81 Lance tests
in 14 classes passed, with no skips, through `run-fe-ut.sh --run` and a
scoped `CUSTOM_MVN` wrapper. Checkstyle was enabled and Maven build
cache disabled. Cases include role plus source keys, generic/service
endpoint precedence, explicit HTTP policy, and native HTTP requests
under unrelated AWS endpoint and credential variables.
- On the unfixed `b62c94c`, the same targeted Java tests produced 5
assertion failures across 14 tests with no skips. The native child
actually requested the unrelated endpoint at port 1. The real shell
helper also failed with JAVA_HOME unset; all three JDK-selection cases
pass with the fix.
- Shell packaging tests cover JAVA_HOME, selected JAVA, PATH-only
discovery, jar/platform isolation, checksum/version/runtime gates and
failure atomicity. The real Arrow JNI helper compiled with JAVA_HOME
unset, and the native HTTP test passed using that rebuilt library; JVM
library logs confirmed its path.
- External CI at `536982b` passed 809 of 810 tests. The AssumeRole
negative case failed because its private endpoint selected the MinIO
provider, whose HMAC-only validation ran before Lance. The fixture now
sets `provider=S3` for that catalog and keeps the exact Lance exception
assertion.
- Provider fixture fix, macOS arm64/JDK 17: `run-fe-ut.sh --run` with a
scoped `CUSTOM_MVN` wrapper passed 54 tests in
`LanceStorageOptionsTest`, `S3FileSystemProviderTest`,
`MinioFileSystemProviderTest` and `MinioFileSystemPropertiesTest`, with
no skips, Checkstyle enabled and Maven build cache disabled. A probe
extracted the baseline and candidate catalog properties from the Groovy
suite and used freshly compiled production providers and Lance options:
the baseline reproduced the MinIO rejection; the candidate retained the
role and reached the exact Lance AssumeRole rejection. Groovy parsing
and `git diff --check` passed. The complete SQL suite and full External
rerun remain pending at the new head.
- Earlier validation at `b62c94c` reported 78 Lance tests, 162 Connector
SPI tests and 16 foundation binding tests passing. Initial feature
validation reported 507 related FE tests, `build.sh --fe`, and the MinIO
regression with this worktree's compatible BE `33d48fcf6da`. Those runs
predate this follow-up and are not current cluster verification. A full
External rerun, cloud, current-master BE and Linux/glibc 2.17 execution
remain unverified at the new head.

### Notes for Reviewers

- The BE Lance reader does not consume `history_schema_info`. Omitting
it retains FileScannerV2's exact-name matching, which the reader tests
exercise.
- Native FE tests skip explicitly on hosts unable to load Lance or Arrow
C Data JNI. The External pipeline enables the MinIO fixture and runs the
new regression suite. Linux x86_64 deployment rebuilds Arrow C Data JNI
with the Doris C++ toolchain, statically links its C++ runtimes and
replaces only that jar entry. This build step needs a JDK, C++ compiler
and `readelf`; it honors JAVA_HOME or discovers java.home from the JVM
selected by env.sh, including PATH-only JDK installations; releases
targeting glibc 2.17 must use the corresponding Doris build environment.
Linux/CentOS 7 execution of this new build step remains untested
locally.
morningman added a commit that referenced this pull request Nov 21, 2026
…70725)

### Background

Lance catalogs expose a namespace as Doris databases and tables. The FE
reads dataset manifests through the Lance Java SDK and passes the pinned
version and storage options to the BE's lance-c reader. Master now
serves filesystem namespaces through the Lance connector plugin;
released 4.1/4.2 versions also serve REST namespaces and OSS storage.

### What problem does this PR solve?

Issue Number: #70680
Related PR: #70681 (filesystem plugin foundation), #66581 (REST
namespace source), #66805 (vended storage options source), #67157 (OSS
source), #70338 (property masking), #70364 (endpoint checks with default
ports)
PR Type: Feature

Problem Summary:

This ports REST namespaces, namespace-vended credentials and OSS support
from branch-4.x to the master Lance plugin. Users can read tables
through a namespace service without configuring static dataset
credentials in Doris. The change also validates REST authentication and
headers, declares the new endpoint and secrets, and adds the REST
fixture and behavior tests. Filesystem catalogs keep their existing
defaults and checks.

Original authors: @zhangstar333 and @FANNG1.

### Details

- **Change map:** Production code +585/-76 lines; tests and fixtures
+2011/-48; generated regression output +20; pipeline configuration +3.
Most changed lines are tests or fixture infrastructure.

  | Part | Purpose | Approximate changed production lines |
  | --- | --- | --- |
| REST namespace access | Validate properties, select the namespace
client, request table credentials, and sanitize errors | 330 |
| OSS storage | Adapt OSS properties, refuse OSS-HDFS and unresolved
AssumeRole, canonicalize options, and isolate explicit identities | 206
|
| S3 option reconciliation | Validate merged credentials, reset a
missing replacement token, and reconcile endpoint addressing using
native boolean semantics | 125 |

- **Scope:** REST authentication supports `none`, `bearer` and
`api_key`, plus extra headers; ALTER can switch modes by clearing the
inactive credential with `""`; namespace-vended options override catalog
options for FE metadata and BE scans. OSS uses Lance's OpenDAL provider.
Declared-only and namespace-managed-version tables fail explicitly;
their version protocol belongs to a later phase.
- **Design:** Reuse the namespace and storage-provider contracts from
4.1/4.2 inside the existing plugin, without adding Lance branches to the
engine. The four-phase plan is tracked in #70680. Reading storage-latest
for managed tables was rejected because the namespace may not have
published that version; this phase refuses them instead. Credential
validation follows the catalog/vended merge so an endpoint-only catalog
can receive valid credentials. Reconcile inherited S3 endpoints with the
final addressing mode using object_store's boolean vocabulary; a
namespace value such as `on` must qualify the bucket just like `true`.
- **Usage:** With the external regression namespace fixture:

  ```sql
  CREATE CATALOG lance_rest PROPERTIES (
      "type" = "lance",
      "lance.catalog.type" = "rest",
      "lance.rest.uri" = "http://127.0.0.1:19102",
      "lance.rest.security.type" = "bearer",
      "lance.rest.bearer-token" = "doris-lance-rest-test-token",
      "s3.endpoint" = "http://127.0.0.1:19001",
      "s3.region" = "us-east-1",
      "use_path_style" = "true"
  );
  SELECT count(*), sum(row_id) FROM lance_rest.`default`.all_types;
  ```

The committed fixture returns `12, 78` without a static access key or
secret key in the catalog.
- **Default behavior:** `lance.catalog.type` remains `filesystem`; REST
authentication defaults to `none`. REST requires `lance.rest.uri` and
rejects `warehouse`. No new FE configuration or session variable is
introduced.
- **Compatibility:** Preserve the 4.1/4.2 property names and raw catalog
map. Catalog reconstruction and replay perform no native connection;
first use opens the namespace. No shared SPI, Thrift, Protobuf or
storage-format change; the plugin API stays at master's 34.0. Reads
retain the foundation's FE/BE compatibility checks. A downgrade needs a
version that already supports the chosen Lance namespace and storage
provider.
- **Security and privileges:** `lance.rest.uri` is a user-controlled
outbound HTTP/SSRF surface. Catalog creation requires scoped
`CREATE_PRIV`, endpoint changes require `ALTER_PRIV`, and reads require
`SELECT_PRIV`. Declare REST alongside all existing S3-compatible
endpoint aliases so the configured engine gate covers CREATE and ALTER.
Mask bearer/API-key values and credential-bearing extra headers; strip
them from provider errors. Existing engine audit handling is reused.
- **Follow-up plan:** Predicate/LIMIT/COUNT pushdown and caches remain
later phases of #70680; namespace-managed versioning remains a separate
follow-up.

### Testing

- With the review fixes, `run-fe-ut.sh --run
'org.apache.doris.connector.lance.*Test'` passed all 149 Lance tests
locally on macOS aarch64/JDK 17.0.19, with zero failures, errors or
skips. This includes pass-through credential redaction, merged OSS
credential-pair validation, REST authentication/header checks and actual
JNI REST/S3/OSS tests.
- On unchanged production at `5471c9ebe0e`, the three new tests failed
on the intended assertions: an echoed vended token remained visible and
incomplete OSS identities were accepted. Zero errors or skips. The fixed
cases also cover case variants, catalog-completed pairs and clearing
just one credential.
- At `ccbffd65cd3`, four control-byte tests ran through `run-fe-ut.sh`:
both rejection tests failed on missing exceptions; both legal-value
controls passed. Zero errors or skips. They cover CREATE/merged ALTER,
leading/interior/trailing controls, extra headers and both credentials.
- At `1365c0a4849`, 77 engine tests for catalog privileges, endpoint
gating, plugin registration and 4.1.5 replay passed; thirteen SPI tests
passed. Those engine and SPI paths have no later production changes in
this PR.
- At `1365c0a4849`, `test_lance_catalog_all_types` and
`test_lance_rest_catalog` passed on freshly built FE/ASAN BE using the
committed dataset and a local S3 substitute that validated SigV4. The
runner generated the REST output, whose shared blocks matched
branch-4.2; scoped CREATE/ALTER/SELECT privileges and SHOW CREATE
masking were verified there.
- The SQL regression now covers all six authentication transitions,
conflicting header-name case variants, and SQL control escapes in extra
headers and both credentials. These later SQL additions have not been
run against a local cluster; expected-output files are unchanged. The
External pipeline enables this suite and its fixture.

### Notes for Reviewers

- Mask runtime credentials including Azure/GCS aliases; validate OSS
pairs after merging and before authentication inference.
- The SSRF gate checks literal CREATE/ALTER endpoint properties at
statement time. Namespace-returned destinations remain trusted external
metadata under `threat-model.md`; this port adds no runtime FE/BE egress
policy. Both credential-handling defects also exist in the inspected
4.1/4.2 implementations and need separate adaptation.
- Reject C0 controls except HTAB, and DEL, in headers and both
credentials before Lance silently omits the header, potentially
selecting a server default. Preserve valid values. The CR/LF-only
4.1/4.2 validators need separate adaptation.
- Case-equivalent custom header names must agree; validation emits one
lowercase SDK header while preserving raw catalog properties. ALTER can
update the original spelling or all retained aliases together.
- An empty inactive REST credential clears its value during ALTER;
whitespace-only inactive credentials remain invalid.
- Keep the filesystem AssumeRole rejection and all endpoint aliases
added during the foundation review. Only the obsolete REST-rejection
regression assertion is removed.
- A complete vended S3 pair without a token clears the inherited
catalog/environment token; an explicitly vended token is preserved. The
4.x maintainers need the same fix.
- S3 reconciliation accepts the pinned object_store true/false spellings
and case variants, preserves namespace option values, and rejects
invalid booleans. OSS keeps its separate native grammar.
- Docker cannot read cached image blobs here. Full MinIO/Compose, remote
OSS and Linux runs are unverified; the External pipeline enables the
fixture.

Co-authored-by: zhangstar333 <zhangsida@selectdb.com>
Co-authored-by: FANNG <fanng@apache.org>
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