[#9021] feat(lance-rest): Support create & list index for LRS#9097
[#9021] feat(lance-rest): Support create & list index for LRS#9097yuqi1129 wants to merge 48 commits intoapache:mainfrom
Conversation
…eric lakehouse catalog. (apache#8842) ### What changes were proposed in this pull request? Introduce a basic framework for generic lakehouse catalog. ### Why are the changes needed? To better manage more lakehouse system. Fix: apache#8833 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? It's just framework, and I just tested it locally. Co-authored-by: Jerry Shao <jerryshao@datastrato.com>
### What changes were proposed in this pull request?
- add the new lance-common and lance-rest-server modules that bootstrap
a minimal Lance catalog REST facade backed by in-memory state
- introduce REST resources (LanceCatalogOperations,
LanceMetadataOperations) plus a GravitinoLanceRESTServer entry point and
auxiliary service wiring
- package assets for the Lance REST server (config + startup script) and
hook the module into Gradle distribution/standalone tarball tasks with
checksums
- extend build dependencies (SLF4J, Dropwizard metrics, Prometheus
bridge) so the service runs using existing Gravitino telemetry
components
- surface scaffolding build.gradle.kts under lance/ to disable blanket
task execution and ensure module resolution
### Why are the changes needed?
- the Lance integration needs a thin REST façade to iterate on metadata
APIs before the backend is available; this scaffolding mirrors the
Iceberg REST
flow
- distribution packaging must include the new service so it can be
assembled, tested, and deployed alongside other Gravitino auxiliaries
Fix: #N/A
### Does this PR introduce any user-facing change?
- new Lance REST server tarball and config/script templates shipped with
the distribution
- new REST endpoints under /lance/v1/... exposing catalog metadata
(namespaces, tables)
- no breaking changes to existing services
### How was this patch tested?
- ./gradlew :lance:lance-rest-server:build
- started the service locally with java -cp
lance/lance-rest-server/build/libs/* ...GravitinoLanceRESTServer
/tmp/gravitino-lance-rest-server.conf
- curl http://127.0.0.1:9101/lance/v1/catalog
- curl http://127.0.0.1:9101/lance/v1/catalog/namespaces
- curl
"http://127.0.0.1:9101/lance/v1/metadata/table?namespace=default&name=sample_table"
- curl -X POST http://127.0.0.1:9101/lance/v1/catalog/namespaces -H
'Content-Type: application/json' -d '{"namespace":"demo"}'
- curl -X DELETE http://127.0.0.1:9101/lance/v1/catalog/namespaces/demo
---------
Co-authored-by: mchades <liminghuang@datastrato.com>
Co-authored-by: Mini Yu <yuqi@datastrato.com>
Co-authored-by: Jerry Shao <jerryshao@datastrato.com>
…nd schema operations for lakehouse catalog (apache#8851) ### What changes were proposed in this pull request? supports catalog and schema operations for lakehouse catalog ### Why are the changes needed? Fix: apache#8835 Fix: apache#8836 ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? tests added
…n of Gravitino managed tables. (apache#8847) ### What changes were proposed in this pull request? Add a new table to store table details for Gravitino-managed tables. ### Why are the changes needed? To support the managed catalog. Fix: apache#8834 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? Test the process of create table locally.
apache#8895) ### What changes were proposed in this pull request? - add lance-rest-server framework - support list namespaces ### Why are the changes needed? Fix: apache#8890 ### Does this PR introduce _any_ user-facing change? yes ### How was this patch tested? no tests now
…ode support for Lance REST service (apache#8903) ### What changes were proposed in this pull request? 1. Created service discovery file (META-INF/services/org.apache.gravitino.auxiliary.GravitinoAuxiliaryService) 2. Added unit tests (TestLanceConfig.java) ### Why are the changes needed? Fix: apache#8891 To enable flexible deployment of Lance REST service: Standalone mode (independent JVM): - Lance needs to connect to Gravitino server via HTTP to access catalog/schema/table metadata - GRAVITINO_URI and GRAVITINO_METALAKE configs specify the connection parameters - Use case: Deploy Lance REST separately for isolation or scaling Auxiliary mode (embedded in Gravitino server): - Lance runs in the same JVM as Gravitino, enabling direct memory access (zero overhead) - META-INF/services file enables automatic service discovery via Java ServiceLoader - Use case: Simplified deployment with shared resources and unified monitoring ### Does this PR introduce _any_ user-facing change? Yes - New configuration properties For Standalone Mode: ``` # Required: Gravitino server URI gravitino.lance-rest.gravitino-uri=http://gravitino-server:8090 # Required: Metalake name gravitino.lance-rest.gravitino-metalake=production ``` For Auxiliary Mode: ``` # Enable Lance REST as auxiliary service gravitino.auxService.names=iceberg-rest,lance-rest # Classpath for Lance REST JAR gravitino.lance-rest.classpath=lance/lance-rest-server/build/libs ``` Deployment modes supported: Standalone: Lance REST runs independently, connects to Gravitino via HTTP Auxiliary: Lance REST runs embedded in Gravitino, uses direct memory access No breaking changes - all changes are additive and backward compatible. ### How was this patch tested? 1. unit test 2. manual test **Standalone mode test:** ``` junda@java(junda.devpod-us-or) ~/gravitino/distribution/package/bin % ./gravitino.sh start Gravitino Server is running[PID:3907790] junda@java(junda.devpod-us-or) ~ % curl http://localhost:8090/api/version {"code":0,"version":{"version":"1.1.0-SNAPSHOT","compileDate":"23/10/2025 21:03:17","gitCommit":"35bd819975badea2493b4dbd9d0de68425229945"}}% junda@java(junda.devpod-us-or) ~/gravitino/distribution/package/bin % ./gravitino-lance-rest-server.sh start GravitinoLanceRESTServer is running[PID:3930096] junda@java(junda.devpod-us-or) ~ % curl "http://localhost:9101/lance/v1/namespace/root/list" {"id":"root","delimiter":"$","namespaces":["default"]}% ``` **Auxiliary mode test:** ``` junda@java(junda.devpod-us-or) ~/gravitino/distribution/package % cd /home/user/gravitino && cat >> distribution/package/conf/gravitino.conf << 'EOF' # ===== Lance REST Auxiliary Service ===== gravitino.auxService.names = iceberg-rest,lance-rest gravitino.lance-rest.classpath = /home/user/gravitino/lance/lance-rest-server/build/libs gravitino.lance-rest.catalog-name = lance_catalog EOF junda@java(junda.devpod-us-or) ~/gravitino/distribution/package % ./bin/gravitino.sh start Gravitino Server is running[PID:274396] junda@java(junda.devpod-us-or) ~/gravitino/distribution/package % tail -50 logs/gravitino-server.log | grep -i lance | grep -i started 2025-10-23 21:34:41.495 INFO [main] [org.apache.gravitino.server.web.JettyServer.start(JettyServer.java:202)] - lance-rest web server started on host 0.0.0.0 port 9101. 2025-10-23 21:34:41.495 INFO [main] [org.apache.gravitino.lance.LanceRESTService.serviceStart(LanceRESTService.java:77)] - Lance REST service started ```
…#8862) ### What changes were proposed in this pull request? Bump timeout from 5 seconds to 10 seconds ### Why are the changes needed? ``` TestCacheConfig > testPolicyAndTagCacheWeigher() FAILED org.awaitility.core.ConditionTimeoutException: Condition with Lambda expression in org.apache.gravitino.cache.TestCacheConfig was not fulfilled within 5 seconds. at app//org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:167) at app//org.awaitility.core.CallableCondition.await(CallableCondition.java:78) at app//org.awaitility.core.CallableCondition.await(CallableCondition.java:26) at app//org.awaitility.core.ConditionFactory.until(ConditionFactory.java:1006) at app//org.awaitility.core.ConditionFactory.until(ConditionFactory.java:975) at app//org.apache.gravitino.cache.TestCacheConfig.testPolicyAndTagCacheWeigher(TestCacheConfig.java:162) ``` see failure: https://github.com/apache/gravitino/actions/runs/18668130387/job/53223578211?pr=8859 Fix: apache#8861 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Updated unit tests
…TagCacheWeigher (apache#8871) ### What changes were proposed in this pull request? Fix EntityCacheWeigher priorities and update cache eviction test This commit corrects the entity weight configuration in EntityCacheWeigher and updates the corresponding test to validate the new behavior. The previous weight configuration was inverted: - Schema: weight=500 (incorrectly high, causing unwanted evictions) - Tag/Policy: weight=100 (incorrectly low, preventing desired evictions) This violated the Caffeine cache principle where higher weights lead to higher eviction priority. ### Why are the changes needed? Correct EntityCacheWeigher and fix the flaky test of testPolicyAndTagCacheWeigher Fix: apache#8861 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Unit test updated
…filesystem module (apache#8907) ### What changes were proposed in this pull request? Disable the CI to build fuse-filesystem module. ### Why are the changes needed? apache#8827 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? CI (cherry picked from commit 7c35997)
…#8904) ### What changes were proposed in this pull request? 1. Added Lance REST server metrics constant (MetricsSource.java) 2. Added MapperConfig rule to transform Dropwizard metrics to Prometheus format 3. Integrated metrics collection in Lance REST service (LanceRESTService.java) 4. Enables automatic exposure of metrics at /metrics and /prometheus/metrics endpoints ### Why are the changes needed? Observability is needed for the new lance rest service. Fix: apache#8909 ### Does this PR introduce _any_ user-facing change? Yes - New metrics endpoints Standalone mode: - http://localhost:9101/metrics (Dropwizard JSON format) - http://localhost:9101/prometheus/metrics (Prometheus text format) Auxiliary mode: - Metrics exposed on all service ports (8090, 9001, 9101) showing unified metrics from all services ### How was this patch tested? Unit tests --------- Co-authored-by: Jerry Shao <jerryshao@datastrato.com>
…n for lance table. (apache#8879) ### What changes were proposed in this pull request? Add support create and load table operations for lance table. ### Why are the changes needed? It's a need. Fix: apache#8838 Fix: apache#8837 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? Currently, I have only tested it locally ```shell ➜ [/Users/yuqi/Downloads] curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \ -H "Content-Type: application/json" -d '{ "name": "lance_table14", "comment": "This is an example table", "columns": [ { "name": "id", "type": "integer", "comment": "id column comment", "nullable": false, "autoIncrement": true, "defaultValue": { "type": "literal", "dataType": "integer", "value": "-1" } } ], "indexes": [ { "indexType": "primary_key", "name": "PRIMARY", "fieldNames": [["id"]] } ], "properties": { "format": "lance", "location": "/tmp/lance_catalog/schema/lance_table14" } }' http://localhost:8090/api/metalakes/test/catalogs/lance_catalog/schemas/schema/tables {"code":0,"table":{"name":"lance_table14","comment":"This is an example table","columns":[{"name":"id","type":"integer","comment":"id column comment","nullable":false,"autoIncrement":true,"defaultValue":{"type":"literal","dataType":"integer","value":"-1"}}],"properties":{"format":"lance","location":"/tmp/lance_catalog/schema/lance_table14/"},"audit":{"creator":"anonymous","createTime":"2025-10-23T03:18:39.123151Z"},"distribution":{"strategy":"none","number":0,"funcArgs":[]},"sortOrders":[],"partitioning":[],"indexes":[{"indexType":"PRIMARY_KEY","name":"PRIMARY","fieldNames":[["id"]]}]}} ➜ [/Users/yuqi/Downloads] curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \ -H "Content-Type: application/json" http://localhost:8090/api/metalakes/test/catalogs/lance_catalog/schemas/schema/tables/lance_table14 {"code":0,"table":{"name":"lance_table14","comment":"This is an example table","columns":[{"name":"id","type":"integer","comment":"id column comment","nullable":false,"autoIncrement":false,"defaultValue":{"type":"literal","dataType":"integer","value":"-1"}}],"properties":{"format":"lance","location":"/tmp/lance_catalog/schema/lance_table14/"},"audit":{"creator":"anonymous","createTime":"2025-10-23T03:18:39.123151Z"},"distribution":{"strategy":"none","number":0,"funcArgs":[]},"sortOrders":[],"partitioning":[],"indexes":[{"indexType":"PRIMARY_KEY","name":"PRIMARY","fieldNames":[["id"]]}]}} ➜ [/Users/yuqi/Downloads] curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \ -H "Content-Type: application/json" http://localhost:8090/api/metalakes/test/catalogs/lance_catalog/schemas/schema/tables {"code":0,"identifiers":[{"namespace":["test","lance_catalog","schema"],"name":"lance_table10"},{"namespace":["test","lance_catalog","schema"],"name":"lance_table11"},{"namespace":["test","lance_catalog","schema"],"name":"lance_table12"},{"namespace":["test","lance_catalog","schema"],"name":"lance_table13"},{"namespace":["test","lance_catalog","schema"],"name":"lance_table14"}]} ➜ [/Users/yuqi/Downloads] ``` And the lance location ```shell ➜ [/tmp/lance_catalog/schema] ls lance_table10 lance_table11 lance_table12 lance_table13 lance_table14 ➜ [/tmp/lance_catalog/schema] cd lance_table14 ➜ [/tmp/lance_catalog/schema/lance_table14] ls -al total 0 drwxr-xr-x@ 4 yuqi wheel 128 10 23 11:18 . drwxr-xr-x@ 7 yuqi wheel 224 10 23 11:18 .. drwxr-xr-x@ 3 yuqi wheel 96 10 23 11:18 _transactions drwxr-xr-x@ 3 yuqi wheel 96 10 23 11:18 _versions ➜ [/tmp/lance_catalog/schema/lance_table14] ls -al _versions total 8 drwxr-xr-x@ 3 yuqi wheel 96 10 23 11:18 . drwxr-xr-x@ 4 yuqi wheel 128 10 23 11:18 .. -rw-r--r--@ 1 yuqi wheel 225 10 23 11:18 1.manifest ➜ [/tmp/lance_catalog/schema/lance_table14] ```
…APIs for LRS (apache#8902) ### What changes were proposed in this pull request? implement namespace operation APIs for LRS ### Why are the changes needed? Fix: apache#8892 ### Does this PR introduce _any_ user-facing change? yes, new REST APIs added ### How was this patch tested? not now
…ations for lance (apache#8911) ### What changes were proposed in this pull request? 1. Support alter lance table 2. Support API for table operations in Lance REST server. ### Why are the changes needed? It's a feature. Fix: apache#8893 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? Test locally with Spark and curl --------- Co-authored-by: mchades <liminghuang@datastrato.com>
…and build script (apache#8918) ### What changes were proposed in this pull request? This PR improves the configuration key and also the build kts for lance namespace service. ### Why are the changes needed? ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Local test.
…ons for Lance table (apache#8920) ### What changes were proposed in this pull request? - The properties with the prefix `lance.storage.` will be used for lance table storage ### Why are the changes needed? Fix: apache#8919 ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? by hand
…ns. (apache#8923) ### What changes were proposed in this pull request? Add some ITs to covert lance table operations and fix a bug by the way. ### Why are the changes needed? It's a improvement. Fix: apache#8921 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? It's self just the test.
### What changes were proposed in this pull request? Fix the CI failure when configuring the lance rest aux service. ### Why are the changes needed? Fix: apache#8933 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Existing CI.
…configurations. (apache#8960) ### What changes were proposed in this pull request? Remove excessive LANCE_CONFIG_PREFIX; ### Why are the changes needed? Prefix LANCE_CONFIG_PREFIX has been removed when Lance server starts. Fix: apache#8959 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? Test locally.
…able creation (apache#8947) ### What changes were proposed in this pull request? supports more dataTypes for lance table creation ### Why are the changes needed? Fix: apache#8946 ### Does this PR introduce _any_ user-facing change? yes, more column data types supports ### How was this patch tested? tests added
…pache#8922) ### What changes were proposed in this pull request? This PR trys to resolve the comments that have not been addressed in apache#8879 ### Why are the changes needed? It's an improvement. Fix: apache#8915 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? Test locally, and we will add ITs in apache#8921
…ce rest server (apache#8963) ### What changes were proposed in this pull request? supports more dataTypes for the Lance rest server ### Why are the changes needed? Fix: apache#8962 ### Does this PR introduce _any_ user-facing change? yes, more dataTypes supported ### How was this patch tested? tests added
… in Lance REST server. (apache#8964) ### What changes were proposed in this pull request? Support API `registerTable` and `deregisterTable` in Lance REST server. ### Why are the changes needed? It's from user requirement. Fix: apache#8955 ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? Test locally.
### What changes were proposed in this pull request? remove encoded annotation ### Why are the changes needed? most http client will encode the specify chart automatically, so we don't need to disable automatic decoding of parameter ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? tested locally
…e operations (apache#9008) ### What changes were proposed in this pull request? add ITs for LRS namespace operations ### Why are the changes needed? Fix: apache#9009 ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? CI pass
…er (apache#8931) ### What changes were proposed in this pull request? Comment out the flaky test cases. ### Why are the changes needed? As the weight mechanism in the Caffeine cache is probabilistic, the CI pipeline will fail occasionally(failure rate is about 10% or so). Fix: apache#8937 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? The existing tests.
…stributionImpl and sortOrderImpl (apache#8975) ### What changes were proposed in this pull request? - Add serializer and deserializer for class `DistributionImpl` and `SortOrderImpl` - Optimize sortOrderImpl serialization. ### Why are the changes needed? It's a improvment. Fix: apache#8940 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? UTs and ITs.
… table operations (apache#9016) ### What changes were proposed in this pull request? Add ITs for lance rest service and test lance table operations. ### Why are the changes needed? To make code robust Fix: apache#9015 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? It's self a test.
…void introducing unnecessary interfaces (apache#9029) ### What changes were proposed in this pull request? Refactor the table and table entity to avoid introducing unnecessary interfaces ### Why are the changes needed? To make the generic lakehouse catalog more stable Fix: apache#9028 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Exisiting UT and IT.
There was a problem hiding this comment.
Pull request overview
This PR adds create and list index APIs to the Lance REST server, enabling users to create various types of indexes (BTREE, BITMAP, vector indexes like IVF_FLAT, IVF_PQ, etc.) and list existing indexes on Lance tables.
Key Changes:
- Added
createTableIndex,listTableIndices, anddescribeTableIndexStatsREST endpoints and implementations - Extended the
IndexandTableChange.AddIndexAPIs to support index properties - Implemented Lance-specific index creation logic with support for scalar and vector index types
- Refactored table operation tests into a dedicated
TestLanceTableOperationsclass
Reviewed changes
Copilot reviewed 24 out of 28 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/rest/LanceTableOperations.java | Added REST endpoints for creating and listing table indexes |
| lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/LanceTableOperations.java | Extended interface with index operation methods |
| lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceTableOperations.java | Implemented index creation and listing logic using Gravitino catalog operations |
| catalogs/catalog-generic-lakehouse/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceCatalogOperations.java | Added Lance dataset index creation with support for various index types and parameters |
| api/src/main/java/org/apache/gravitino/rel/indexes/Index.java | Added properties support to Index interface and new index types (IVF_HNSW_PQ, FTS) |
| api/src/main/java/org/apache/gravitino/rel/indexes/Indexes.java | Extended factory methods to support index properties |
| api/src/main/java/org/apache/gravitino/rel/TableChange.java | Extended AddIndex change to include index properties |
| common/src/main/java/org/apache/gravitino/dto/rel/indexes/IndexDTO.java | Added properties field to index DTO |
| common/src/main/java/org/apache/gravitino/json/JsonUtils.java | Updated serialization/deserialization to handle index properties |
| lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/rest/TestLanceTableOperations.java | Added comprehensive unit tests for table operations including index creation and listing |
| lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/integration/test/LanceRESTServiceIT.java | Added integration tests for index creation with various index types |
| gradle/libs.versions.toml | Updated lance-namespace version from 0.0.19 to 0.0.20 |
| lance/lance-rest-server/build.gradle.kts | Added dependency exclusions for commons-lang3 and guava |
| core/src/main/java/org/apache/gravitino/storage/relational/utils/POConverters.java | Fixed table property deserialization to handle null properties |
| bin/gravitino-lance-rest-server.sh.template | Added startup script for Lance REST server |
| build.gradle.kts | Added build tasks for Lance REST server distribution |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| default -> throw new IllegalArgumentException("Unsupported index type: " + indexType); | ||
| } |
There was a problem hiding this comment.
Missing handling for IVF_HNSW_PQ index type. The enum is defined in the API but is not handled in either the getIndexType() method (line 328) or the generateIndexParams() method (line 345). This will cause an IllegalArgumentException when users try to create an IVF_HNSW_PQ index.
| default -> throw new IllegalArgumentException("Unsupported index type: " + indexType); | |
| } | |
| case IVF_HNSW_PQ -> builder.setVectorIndexParams( | |
| new VectorIndexParams.Builder(new IvfBuildParams.Builder().build()) | |
| .setDistanceType(toLanceDistanceType(request.getMetricType())) | |
| .setHnswParams(new HnswBuildParams.Builder().build()) | |
| .setPqParams( | |
| new PQBuildParams.Builder() | |
| .setNumSubVectors(1) // others use default value. | |
| .build()) | |
| .build()); | |
| default -> throw new IllegalArgumentException("Unsupported index type: " + indexType); |
| private IndexType getIndexType(Index index) { | ||
| IndexType indexType = IndexType.valueOf(index.type().name()); | ||
| return switch (indexType) { | ||
| // API only supports these index types for now, but there are more index types in Lance. | ||
| case SCALAR, BTREE, INVERTED, BITMAP -> indexType; | ||
| // According to real test, we need to map IVF_SQ/IVF_PQ/IVF_HNSW_SQ to VECTOR type in Lance, | ||
| // or it will throw exception. For more, please refer to | ||
| // https://github.com/lancedb/lance/issues/5182#issuecomment-3524372490 | ||
| case IVF_FLAT, IVF_PQ, IVF_HNSW_SQ -> IndexType.VECTOR; | ||
| default -> throw new IllegalArgumentException("Unsupported index type: " + indexType); | ||
| }; | ||
| } | ||
|
|
||
| private IndexParams generateIndexParams(Index index) { | ||
| IndexType indexType = IndexType.valueOf(index.type().name()); | ||
|
|
||
| String configJson = index.properties().get(LANCE_INDEX_CONFIG_KEY); | ||
| CreateTableIndexRequest request; | ||
| try { | ||
| request = JsonUtil.mapper().readValue(configJson, CreateTableIndexRequest.class); | ||
| } catch (Exception e) { | ||
| throw new IllegalArgumentException("Lance index config is invalid", e); | ||
| } | ||
|
|
||
| IndexParams.Builder builder = IndexParams.builder(); | ||
| switch (indexType) { | ||
| case SCALAR: | ||
| return IndexParams.builder().build(); | ||
| case VECTOR: | ||
| // TODO make these parameters configurable | ||
| int numberOfDimensions = 3; // this value should be determined dynamically based on the data | ||
| // Add properties to Index to set this value. | ||
| return IndexParams.builder() | ||
| .setVectorIndexParams( | ||
| VectorIndexParams.ivfPq(2, 8, numberOfDimensions, DistanceType.L2, 2)) | ||
| .build(); | ||
| default: | ||
| throw new IllegalArgumentException("Unsupported index type: " + indexType); | ||
| case SCALAR, BTREE, INVERTED, BITMAP -> builder.setScalarIndexParams( | ||
| ScalarIndexParams.create(indexType.name())); | ||
|
|
||
| case IVF_FLAT -> builder.setVectorIndexParams( | ||
| new VectorIndexParams.Builder(new IvfBuildParams.Builder().build()) | ||
| .setDistanceType(toLanceDistanceType(request.getMetricType())) | ||
| .build()); | ||
| case IVF_PQ -> builder.setVectorIndexParams( | ||
| new VectorIndexParams.Builder(new IvfBuildParams.Builder().build()) | ||
| .setDistanceType(toLanceDistanceType(request.getMetricType())) | ||
| .setPqParams( | ||
| new PQBuildParams.Builder() | ||
| .setNumSubVectors(1) // others use default value. | ||
| .build()) | ||
| .build()); | ||
|
|
||
| case IVF_SQ -> builder.setVectorIndexParams( | ||
| new VectorIndexParams.Builder(new IvfBuildParams.Builder().build()) | ||
| .setDistanceType(toLanceDistanceType(request.getMetricType())) | ||
| .setSqParams(new SQBuildParams.Builder().build()) | ||
| .build()); | ||
|
|
||
| case IVF_HNSW_SQ -> builder.setVectorIndexParams( | ||
| new VectorIndexParams.Builder(new IvfBuildParams.Builder().build()) | ||
| .setDistanceType(toLanceDistanceType(request.getMetricType())) | ||
| .setHnswParams(new HnswBuildParams.Builder().build()) | ||
| .build()); | ||
| default -> throw new IllegalArgumentException("Unsupported index type: " + indexType); |
There was a problem hiding this comment.
Missing handling for LABEL_LIST index type. The enum is defined in the API (line 101) but is not handled in the getIndexType() or generateIndexParams() methods, which will cause failures when users try to create this type of index.
There was a problem hiding this comment.
It's not supported by the client side.
| switch (indexType) { | ||
| case SCALAR: | ||
| return IndexParams.builder().build(); | ||
| case VECTOR: | ||
| // TODO make these parameters configurable | ||
| int numberOfDimensions = 3; // this value should be determined dynamically based on the data | ||
| // Add properties to Index to set this value. | ||
| return IndexParams.builder() | ||
| .setVectorIndexParams( | ||
| VectorIndexParams.ivfPq(2, 8, numberOfDimensions, DistanceType.L2, 2)) | ||
| .build(); | ||
| default: | ||
| throw new IllegalArgumentException("Unsupported index type: " + indexType); | ||
| case SCALAR, BTREE, INVERTED, BITMAP -> builder.setScalarIndexParams( | ||
| ScalarIndexParams.create(indexType.name())); | ||
|
|
||
| case IVF_FLAT -> builder.setVectorIndexParams( | ||
| new VectorIndexParams.Builder(new IvfBuildParams.Builder().build()) | ||
| .setDistanceType(toLanceDistanceType(request.getMetricType())) | ||
| .build()); | ||
| case IVF_PQ -> builder.setVectorIndexParams( | ||
| new VectorIndexParams.Builder(new IvfBuildParams.Builder().build()) | ||
| .setDistanceType(toLanceDistanceType(request.getMetricType())) | ||
| .setPqParams( | ||
| new PQBuildParams.Builder() | ||
| .setNumSubVectors(1) // others use default value. | ||
| .build()) | ||
| .build()); | ||
|
|
||
| case IVF_SQ -> builder.setVectorIndexParams( | ||
| new VectorIndexParams.Builder(new IvfBuildParams.Builder().build()) | ||
| .setDistanceType(toLanceDistanceType(request.getMetricType())) | ||
| .setSqParams(new SQBuildParams.Builder().build()) | ||
| .build()); | ||
|
|
||
| case IVF_HNSW_SQ -> builder.setVectorIndexParams( | ||
| new VectorIndexParams.Builder(new IvfBuildParams.Builder().build()) | ||
| .setDistanceType(toLanceDistanceType(request.getMetricType())) | ||
| .setHnswParams(new HnswBuildParams.Builder().build()) | ||
| .build()); | ||
| default -> throw new IllegalArgumentException("Unsupported index type: " + indexType); |
There was a problem hiding this comment.
Invalid switch statement syntax. The switch cases use arrow syntax (->) but are missing the arrow for the first case (line 346-347). The correct syntax should be either traditional case SCALAR: case BTREE: case INVERTED: case BITMAP: with breaks, or case SCALAR, BTREE, INVERTED, BITMAP -> with an arrow. The current mixed syntax will cause compilation errors.
There was a problem hiding this comment.
case SCALAR, BTREE, INVERTED, BITMAP -> builder.setScalarIndexParams(
ScalarIndexParams.create(indexType.name()));The code is as above, so what's the problem.
| // Now try to create FTS index on an existing table | ||
| createTableIndexRequest.setId(ids); | ||
| createTableIndexRequest.setIndexType(IndexTypeEnum.FTS); | ||
| createTableIndexRequest.setColumn("value"); | ||
|
|
||
| LanceNamespaceException exception = | ||
| Assertions.assertThrows( | ||
| LanceNamespaceException.class, () -> ns.createTableIndex(createTableIndexRequest)); | ||
| // com.lancedb.lance.index.IndexType does not have FTS yet, so it should throw exception | ||
| Assertions.assertTrue( | ||
| exception.getMessage().contains("No enum constant com.lancedb.lance.index.IndexType.FTS")); | ||
| } |
There was a problem hiding this comment.
The test expects FTS index to fail with a specific error message about "No enum constant com.lancedb.lance.index.IndexType.FTS". However, the FTS enum has been added to Index.IndexType in the API changes. This test should be updated to either handle FTS properly if Lance now supports it, or the FTS enum should be removed from the API if it's not yet supported.
There was a problem hiding this comment.
This is thirty-party API and I can't remove it.
|
|
What changes were proposed in this pull request?
Add create and list index APIs in the Lance rest server.
Why are the changes needed?
It's a feature that benefits users.
Fix: #9021
Does this PR introduce any user-facing change?
N/A.
How was this patch tested?
UTs and ITs