morningman opened a new pull request, #71133:
URL: https://github.com/apache/doris/pull/71133

   ### Background
   
   A Lance dataset records indexes built by Lance writers: logical indexes such 
as an `IVF_PQ` vector index or a `BTree` scalar index, each stored as one or 
more physical segments with a UUID and the dataset version they were built at. 
On master, Lance catalogs run as the `fe-connector-lance` plugin. `SHOW INDEX` 
on a plugin table returns no rows in the legacy layout, and only rows derived 
from constraints in the MySQL-compatible one. Metadata table functions such as 
`partitions()` are planned as a BE meta scan that the BE relays to the master 
FE, which computes the rows.
   
   ### What problem does this PR solve?
   
   Issue Number: close #71132
   Related PR: #66637, #66671 (the branch-4.1 / branch-4.2 implementations this 
ports, issue #66497), #71125 (conflicts: also raises the connector plugin API 
to 39.0 and edits `LanceCatalogClient`)
   PR Type: Feature
   
   Problem Summary:
   
   Users inspect the indexes of Lance tables with `SHOW INDEX` (since 4.1.4) 
and the `lance_index_entries()` table function (since 4.1.5); on master the 
first returns an empty set and the second does not exist. This PR adds both 
through generic SPI: a connector lists a table's indexes for `SHOW INDEX`, and 
a plugin declares a metadata table function that the engine plans, routes, 
checks privileges for and fills from the connector, so fe-core and the SPI 
carry no Lance names. The BE relays such calls through a new thrift call type. 
Half of the diff is tests. Other catalogs see no change.
   
   | Statement (outputs from runs; catalog name shortened to `ctl`) | Before 
(master `d97993b7256`) | After |
   |---|---|---|
   | `SHOW INDEX FROM ctl.doris.vs_ivf_pq_f32` | `Empty set` | `vs_ivf_pq_f32`, 
`embedding_ivf_pq_f32`, `1`, `embedding`, `IVF_PQ`, 
`{"compression":{"num_bits":4,"num_sub_vectors":4,"type":"pq"},"metric_type":"L2"}`
 in Table, Key_name, Seq_in_index, Column_name, Index_type, Properties; the 
other columns empty |
   | `SELECT * FROM lance_index_entries("table" = "ctl.doris.vs_ivf_pq_f32")` | 
`Can not found function 'lance_index_entries'` | `ctl  doris  vs_ivf_pq_f32  
embedding_ivf_pq_f32`, then the segment's UUID and dataset version |
   
   ### Details
   
   - **Change map:** +3476 / -34 in 72 files: production code +1632 / -21 in 25 
files; tests +1791 / -11 in 43 files plus +47 lines of `.out` and a 16-file 
fixture copied byte for byte from branch-4.2; one pom line and five README 
lines. One commit per part, in reading order:
     1. SPI (+317): `ConnectorIndexOps` / `ConnectorIndex` for SHOW INDEX; 
`ConnectorProvider#getMetadataTableFunctions` with 
`ConnectorMetadataTableFunction` / `ConnectorMetadataTableOps`; connector 
plugin API 38.0 to 39.0.
     2. BE and thrift (+79): `TMetadataType.CONNECTOR_TABLE_FUNCTION = 17`, 
`TConnectorTableFunctionParams`, `TMetaScanRange.20`, 
`TMetadataTableRequestParams.17`; `MetaScanner` relays the new type with the 
querying user, and relays branch-4.2's reserved type 15 (`LANCE_INDEX_ENTRIES`) 
as branch-4.2 does.
     3. fe-core (+676 / -18): `ConnectorPluginManager` registers the declared 
names, `BindExpression` binds them, `PluginMetadataTableValuedFunction` 
analyzes, plans the scan range and computes rows on the master FE, and 
`ShowIndexCommand` renders connector indexes.
     4. Lance plugin (+560 / -3): `LanceIndexInspection` ported from 
branch-4.2, read through `LanceCatalogClient`'s existing pooled table read; the 
provider declares `lance_index_entries`.
     5. Regression suites, the `nested_index` fixture and the generator part 
that builds it.
   - **Scope:** Filesystem Lance catalogs, latest version. `SHOW INDEX | 
INDEXES | KEY | KEYS` lists one row per index column: nested columns as full 
paths with backquoted segments (``attributes.`child.with.dot` ``), the type 
string Lance reports, allow-listed details of at most 400 bytes; Lance's system 
indexes (`__lance_frag_reuse`, `__lance_mem_wal`) are hidden. In the 
MySQL-compatible layout the rows have `Non_unique` 1 and `Visible` YES, after 
any constraint rows. `lance_index_entries` returns one row per physical 
segment, 6 NOT NULL columns, at most 16,384 entries. Errors: REST catalogs, 
with branch-4.2's messages (`SHOW INDEX is not supported for Lance REST 
catalogs`); arguments other than `table` (`'snapshot' is an invalid property 
for lance_index_entries`); a catalog whose connector does not declare the 
function (`Catalog 'x' does not support lance_index_entries()`). A plugin 
declaring a built-in table function's name, or one another plugin claimed, is 
not loaded. Not ported
 : Lance index DDL (#67201, #67630; on branch-4.2 no statement creates or drops 
a Lance index) and the index job framework (#67235, removed on 4.x by #68781).
   - **Design:** SHOW INDEX asks an optional `ConnectorIndexOps` on the 
connector's metadata, and the engine renders both layouts. Rejected: going 
through `TableKeyMeta`, which also feeds `information_schema` STATISTICS, 
KEY_COLUMN_USAGE and TABLE_CONSTRAINTS and the Key column of SHOW COLUMNS, so 
those would open every Lance dataset. `lance_index_entries` is declared by the 
plugin; the engine owns the `table` argument, routing, both privilege checks 
and row conversion, and asks `ConnectorMetadataTableOps.listMetadataTableRows` 
for the rows. The BE relays it as a generic call type that other connectors' 
functions can reuse. Rejected: reusing type 15 from fe-core (Lance-named thrift 
in fe-core, a transport only Lance could use); plugins building thrift through 
the SPI; a system table `t$index_entries` (changes syntax 4.1.5 ships); rows 
computed at analysis into a constant relation (plans grow with the entries). 
Proposed in #71132, opened with this PR; not discussed yet.
   - **Usage:**
   
     ```sql
     SHOW INDEX FROM lance_ctl.doris.vs_ivf_pq_f32;          -- also SHOW 
INDEXES / KEY / KEYS
     SET enable_mysql_compatible_index_metadata = true;      -- the 16-column 
layout
     SHOW INDEX FROM lance_ctl.doris.vs_ivf_pq_f32;
     SELECT IndexName, IndexUuid, DatasetVersion
     FROM lance_index_entries("table" = "lance_ctl.doris.vs_ivf_pq_f32");
     DESC FUNCTION lance_index_entries("table" = 
"lance_ctl.doris.vs_ivf_pq_f32");
     ```
   - **Default behavior:** No switch: every filesystem Lance catalog supports 
both. The layout follows the existing session variable 
`enable_mysql_compatible_index_metadata` (default `false`).
   - **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. Thrift gains one enum value, 
one struct and two optional fields, ids unused on branch-3.1, 4.0, 4.1, 4.2 and 
master. Doris upgrades BEs first: an upgraded BE still relays the type-15 calls 
a 4.1.5+ or 4.2 FE plans, so `lance_index_entries` keeps returning rows during 
the upgrade. In the unsupported order, FE before BE, an old BE answers the 
unknown type with an empty result instead of an error; no exec-version fence 
was added for it. Nothing is persisted (no EditLog, image or metadata change), 
so downgrade leaves nothing behind.
   - **Security and privileges:** Both need the SHOW privilege on the table, 
checked at analysis before the table is looked up. `lance_index_entries` checks 
it again on the master FE for the user the BE relays, as branch-4.2 does. No 
new outbound host: the connector reads the catalog's own storage with the 
catalog's credentials, and REST catalogs are refused before any read.
   - **Behavior change:** `SHOW INDEX` on a table of a Lance REST catalog now 
fails with `SHOW INDEX is not supported for Lance REST catalogs` instead of 
returning an empty set; on a filesystem catalog it opens the dataset, so it 
fails with `Failed to load Lance index metadata for <db>.<table>: ...` when the 
storage cannot be read. Both as in 4.1.4 and later.
   
   ### Testing
   
   - Regression, local (macOS arm64, FE and BE built from the branch before its 
rebase onto `3e8e7b5af23`; a read-only S3 stand-in and the REST stub in place 
of the MinIO and lance-rest containers): `test_lance_show_index` and 
`test_lance_index_entries` pass, and every result block branch-4.2 has is 
identical to branch-4.2's `.out`; the new blocks are the MySQL-compatible 
layout and `DESC FUNCTION`. `test {}` cases cover both REST refusals, the 
invalid argument, and the denied error for a user with no privilege on the 
Lance catalog.
   - Mutations, each reverted: fe-core routing that skips the connector, 
`Non_unique` 0 in the MySQL-compatible layout, no SHOW recheck on the master 
FE, and no system-index filter each fail their target FE or plugin test; a 
cluster BE without the new relay returns no rows and fails `entries_vector`.
   - Unit tests, local: fe-connector-spi (177, including 
`ConnectorPluginSurfaceTest`); fe-connector-lance `LanceIndexInspectionTest` 
(9) and `LanceIndexInspectionNativeTest` (5, real datasets and indexes through 
JNI); fe-core `PluginMetadataTableValuedFunctionTest` (9) and 
`ShowIndexCommandConnectorTest` (5), with checkstyle, 
`ConnectorPluginManagerTest` (29) and five neighbouring classes (26); BE 
`MetaScannerTest` (6, ASAN, macOS): request building and dispatch for the new 
type and type 15; an unknown type still returns no rows.
   
   ### Notes for Reviewers
   
   - Original author of the branch-4.1 / branch-4.2 inspection code, BE relay, 
suites and fixture: @u70b3 (#66637, #66671).
   - #71125 also raises the connector plugin API from 38.0 to 39.0 and changes 
`LanceCatalogClient.readTable`; whichever merges second is rebased onto the 
other and moves to 40.0.
   - On a REST catalog, `lance_index_entries` fails at execution, through the 
BE, not at analysis as on branch-4.2, because the refusal is now the 
connector's.
   - branch-4.2's dedicated inspection executor (4 threads, queue 16, 60 s) is 
not ported: `LanceCatalogClient.readTable` already bounds each read with its 
catalog generation's allocator and sanitizes errors.
   - Release note is None because 4.1.4 ships `SHOW INDEX` for Lance and 4.1.5 
ships `lance_index_entries`; this 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 and the 
`lance-index-entries` function page already document both, in the dev docs and 
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 runs predate 
the rebase onto `3e8e7b5af23`, whose new commits do not touch the changed paths
   
   ### AI Disclosure
   
   - Tool: Claude Code (Claude Opus 5.5)
   - Generated: the SPI, fe-core and BE code, the master port of the plugin 
code, the new unit tests, the test adaptations and this description; the 
inspection logic, the type-15 BE relay and its tests, the suites and the 
fixture are ported from branch-4.2 (#66637, #66671)
   - Human review: not stated
   - Prompts: The author asked to port branch-4.2's SHOW INDEX and 
`lance_index_entries` for Lance to master's connector plugin, then chose from 
the agent's design: only these two (no index DDL or job framework), an optional 
SPI for SHOW INDEX outside `TableKeyMeta`, a plugin-declared table function 
with engine-owned routing and privilege checks, a new generic thrift call type 
plus branch-4.2's type 15 on the BE, no exec-version fence, and branch-4.2's 
REST refusals; and asked to open the PR once development completed.
   


-- 
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]

Reply via email to