morningman opened a new pull request, #70903:
URL: https://github.com/apache/doris/pull/70903
### Background
A Lance dataset is a directory of versioned manifests that list its
fragments (data files) and indexes. branch-4.1 (since 4.1.4) and branch-4.2
read one with `s3("uri" = ..., "format" = "lance")`: the FE opens the dataset,
pins its newest version and plans one range per fragment. On master, Lance
lives in the `fe-connector-lance` plugin, which serves Lance catalogs (#70681,
#70725, #70827). The file table functions (`s3()`, `file()`, `hdfs()`, ...)
read only the formats of a closed list in fe-core: the FE lists the files and
the BE's file readers read them.
### What problem does this PR solve?
Issue Number: #70680
Related PR: #70830 (builds on it; its commits are in this branch until it
merges), #70827 (the pushdown this scan reuses), #65730, #66805, #67325,
#67921, #68078 (the branch-4.x implementation this ports)
PR Type: Feature
Problem Summary:
Users who read Lance datasets with `s3()` on 4.1.4 and 4.2 get an error on
master, because fe-core no longer knows the format. This PR lets a connector
plugin serve a format to the file table functions: `s3()`, and `file()` over
S3-compatible storage, hand the dataset's location and storage to the plugin,
which pins the newest version, gives the columns, and plans the scan through
the scan node of catalog tables, pushdown included. The Lance plugin serves
`lance`. Half of the diff is tests. The branch also carries three review fixes
for the Lance plugin, each in its own commit. Other formats and table functions
are unchanged.
```sql
SELECT count(*), sum(row_id) FROM s3(
"uri" = "s3://warehouse/lance/all_types.lance", "s3.endpoint" =
"http://127.0.0.1:19001",
"s3.access_key" = "<ak>", "s3.secret_key" = "<sk>", "s3.region" =
"us-east-1",
"use_path_style" = "true", "format" = "lance");
```
| FE | Result |
|---|---|
| master before this PR | `ERROR 1105 (HY000): errCode = 2, detailMessage =
Can not build s3(): format:lance is not supported.` |
| this PR | `12 78` |
### Details
- **Change map:** This PR's own commit is +2043 −69 in 37 files, more than
half of it tests: unit tests +613, two regression suites with a fixture builder
+341, their generated `.out` +116, and a 5 KB Lance fixture copied from
branch-4.2. The production code is +967 −63, in three parts, in reading order:
1. The SPI (+150 −1): `ConnectorProvider#getFileFormats` and
`#createFileFormatConnector`, `ConnectorFileSource`, `ConnectorFileSourceOps`;
connector plugin API 35.0 -> 36.0 with its surface baseline.
2. fe-core (+310 −12): format claims and one connector per format
(`ConnectorPluginManager`, `PluginFileFormat`);
`ExternalFileTableValuedFunction` and `S3TableValuedFunction` hand the location
to the plugin and scan with `PluginDrivenScanNode`; two small
`PluginDrivenScanNode` fixes for a table that belongs to no catalog (Notes for
Reviewers).
3. The Lance plugin (+508 −51): `LanceFileFormatConnector`,
`LanceFileMetadata`, `LanceFileTableHandle`, and `LanceScanPlanProvider` split
by where the metadata comes from (`CatalogSource`, the old behavior;
`FileSource`, the new one).
The two commits before it hold the carried review fixes (+248 −194); the
two before those are #70830.
- **Scope:** `s3()`, and `file()` over S3-compatible storage. The uri is the
dataset root: nothing is listed and no glob applies. The statement reads the
version that is newest when it is analyzed. `DESC FUNCTION` shows the columns
as a Lance catalog does. Predicates, LIMIT and `COUNT(*)` are pushed as for a
catalog table; the 4.x table function pushed none. Read only: `INSERT INTO
s3(...)`, `OUTFILE ... FORMAT AS lance` and routine load still fail with
`format:lance is not supported.`. `hdfs()` and `http()` refuse the format, as
on 4.x, and so do `path_partition_keys` and a streaming job's file list.
`local()` is out: master disables it for every format (#69591).
- **Design:** A plugin declares its formats
(`ConnectorProvider#getFileFormats()`) and builds, for each, a connector that
belongs to no catalog (`createFileFormatConnector`). Its metadata implements
`ConnectorFileSourceOps#getFileTableHandle(session, ConnectorFileSource)`,
which resolves the location and storage to a table handle and pins the version;
from there the engine uses the existing interfaces, as the `query()` table
function does: `getTableSchema` for the columns, `PluginDrivenScanNode` for the
scan. fe-core claims format names when it admits a plugin: case-insensitive,
one plugin per name, and the formats the engine reads itself are reserved. A
format's connector is built on first use, kept for the life of the FE, and
given a negative catalog id, which no catalog has, so its per-statement state
stays apart. Rejected: a narrow `TVFScanNode` interface returning a schema and
splits, which would duplicate the plugin scan node's range and storage plumbing
and lose the pushdow
n. Not discussed publicly; #70680 lists this as a follow-up.
- **Usage:**
```sql
DESC FUNCTION s3("uri" = "s3://bucket/path/data.lance", "s3.endpoint" =
"...",
"s3.access_key" = "...", "s3.secret_key" = "...", "s3.region" = "...",
"format" = "lance");
SELECT row_id FROM file("uri" = "s3://bucket/path/data.lance",
"s3.endpoint" = "...",
"s3.access_key" = "...", "s3.secret_key" = "...", "s3.region" = "...",
"format" = "lance")
WHERE int64_col > 0;
```
EXPLAIN of the second statement:
```
TABLE: null.null.S3TableValuedFunction
CONNECTOR: lance
lanceCatalogType=tvf
lanceVersion=1
lanceFragments=1
lancePushdownPredicate=(int64_col > 0)
```
- **Default behavior:** Available whenever the Lance plugin is installed, as
the FE package does by default.
- **Compatibility:** FE only: the ranges carry the same `TLanceFileDesc` and
`TLanceScanParams` as a catalog scan, so neither the BE nor thrift changes. A
column of the types the BE reader added in 4.2 keeps a smooth-upgrade source BE
out of the scan, as for a catalog table. Plugins built for API 35.0 are refused
by the version gate, as after every SPI change. Nothing is persisted.
- **Security and privileges:** The FE reads the dataset's manifest and
fragment list at the endpoint the user names, with the user's credentials: the
request `s3()` already makes to list files, behind the same gate, which runs
before the plugin opens anything (`s3_load_endpoint_white_list`, and the SSRF
check when `security_checker_class_name` is set). The privilege is that of
`s3()`: none beyond running the query, USAGE when a `resource` is named.
Credentials stay out of EXPLAIN, the handle's `toString` and error messages.
- **Carried review fixes:**
1. REFRESH TABLE and REFRESH DATABASE also start a new Lance Session
(`c486a184727`, [#70830
r4661513530](https://github.com/apache/doris/pull/70830#discussion_r4661513530)).
A dataset deleted and written again at the same URI with V1 manifest names
kept a stale index list after REFRESH TABLE, and the BE refused filtered scans
(`scalar index segment ... is absent from the dataset snapshot`); lance-core
12's Java `Session` cannot drop one URI's entries. Cost: REFRESH TABLE drops
the catalog's cached Lance metadata, where branch-4.x rotates the Session only
on REFRESH CATALOG.
2. Reads with namespace-vended storage options use a Session of their own
(`c486a184727`, [#70830
r4665616715](https://github.com/apache/doris/pull/70830#discussion_r4665616715)):
a namespace vending a new token per describe grew the shared Session's
object-store registry without bound.
3. `planScan` no longer serializes the pushed Substrait filter
(`c14dc1755a2`, [#70827
r4656423962](https://github.com/apache/doris/pull/70827#discussion_r4656423962)):
the conversion is lazy.
- **Follow-up plan:** The Lance search table functions, index DDL and
inspection, and tag and branch versioning follow in their own PRs (#70680).
### Testing
- fe-core: the new `PluginFileFormatTableValuedFunctionTest` (8 cases)
drives `s3()`, `file()`, `hdfs()` and `http()` against a mocked plugin: the
endpoint gate runs first and a refused endpoint never reaches the plugin,
nothing is listed, the plugin gets the normalized location and storage, the
columns are its own, the scan and its EXPLAIN go through
`PluginDrivenScanNode`, a predicate reaches the plugin while the statement
holds an internal table's plan read lock, and the refusals hold.
`ConnectorPluginManagerTest` covers the claims. With the other table function
tests, the `PluginDrivenScanNode*Test` family and
`PluginDrivenMissingTableTest`, 479 fe-core tests in 45 classes pass.
- `fe-connector-spi`: 166 tests with the new surface baseline and API 36.0,
run on the first version of this commit; the SPI is unchanged since.
- Lance plugin: 264 tests, none skipped (macOS arm64, lance-core 12.0.0
JNI), among them `LanceFileFormatNativeTest`: the pinned version holds after a
newer commit, the table function's storage goes into the scan and stays out of
EXPLAIN, filter and `COUNT(*)` are pushed, the added types raise the upgrade
fence, a missing dataset fails with a message.
- Mutations: 13 targeted mutations of this commit fail their tests, among
them the old EXPLAIN code (`NullPointerException`), the unguarded cast
(`FunctionGenTable cannot be cast to class PluginDrivenExternalTable`), the
endpoint gate skipped, an engine format claimable, and the version pin dropped.
- Regression, locally: the 10 `external_table_p0/lance` suites, the two new
ones included, pass on an FE built from this branch and a BE built from
#70827's head, against a host S3 stand-in and the REST stub instead of MinIO.
The 7 result blocks ported from branch-4.2's `.out` are identical; the new
blocks (EXPLAIN, pushdown, `COUNT(*)` over three fragments with deletions,
`file()`, `INSERT ... SELECT` into an OLAP table, a join with one, the
refusals) match what pylance 7.0.0 reads from the same fixtures.
- Carried fixes: 257 plugin tests at `c14dc1755a2`, and one mutation per
changed behavior, each failing its new test.
### Notes for Reviewers
- Review the last three commits; the first two are #70830 and leave once it
merges.
- `PluginDrivenScanNode` assumed a catalog table in two places that a table
function's table (no database, no catalog) broke: EXPLAIN read
`getDatabase().getCatalog()`, and `convertPredicate` cast the table to
`PluginDrivenExternalTable` whenever the statement also held an internal table
(a join, or `INSERT INTO olap_table SELECT ...`).
- `ConnectorFileSource` hands over no other table function properties: they
cannot be told apart from storage keys reliably, and passing them would copy
the credentials again.
- A format's connector holds nothing to close: every read opens and closes
its own Arrow allocator and Lance Session, so one table function's credentials
never reach a cache another reads. The statement memo, keyed by URI and
version, only spares the scan a second read; every table function resolves its
handle with its own storage.
### Release note
`s3()`, and `file()` over S3-compatible storage, read Lance datasets with
`"format" = "lance"` as on 4.1 and 4.2, and now push predicates, LIMIT and
`COUNT(*)` into the scan.
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: Yes (the `s3()` and `file()` pages need
`"format" = "lance"` for releases built from master; a doris-website PR follows)
- Pre-submission status: Partially verified: the regression suites ran on
macOS against a local S3 stand-in instead of the MinIO container, with a BE
built from #70827's head (this PR changes no BE code); the External pipeline
runs them in docker
### AI Disclosure
- Tool: Claude Code (Claude Opus 5.5)
- Generated: the code, the tests and this description
- Human review: not stated
- Prompts:
1. Port branch-4.x's `"format" = "lance"` file table function to master as
the next Lance task, on a branch stacked on #70830.
2. Fix in the same PR the two round-4 review findings on #70830 and
r4656423962 on #70827.
3. The design as approved: plugins declare formats and build a
catalog-less connector; only `s3()` and `file()` over S3 hand over a data set;
keep the pushdown the catalog scan already has.
--
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]