Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#8890][#8891][#8909] feat(lance server): Lance rest server framework (#9174)

Junda Yang8def4021b6e1
diff --git a/build.gradle.kts b/build.gradle.kts
index 0a98b6779b..4ad385c5cb 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -683,6 +683,7 @@ tasks {
"copyCliLib",
":authorizations:copyLibAndConfig",
":iceberg:iceberg-rest-server:copyLibAndConfigs",
+ ":lance:lance-rest-server:copyLibAndConfigs",
":web:web:build"
)
@@ -916,6 +917,7 @@ tasks {
!it.name.startsWith("filesystem") &&
!it.name.startsWith("flink") &&
!it.name.startsWith("iceberg") &&
+ !it.name.startsWith("lance") &&
!it.name.startsWith("integration-test") &&
!it.name.startsWith("spark") &&
!it.name.startsWith("trino-connector") &&
diff --git a/core/build.gradle.kts b/core/build.gradle.kts
index 38dfc219de..7e0867dc71 100644
--- a/core/build.gradle.kts
+++ b/core/build.gradle.kts
@@ -47,6 +47,9 @@ dependencies {
exclude(group = "com.fasterxml.jackson.core", module = "*") // provided by gravitino
exclude(group = "com.fasterxml.jackson.datatype", module = "*") // provided by gravitino
exclude(group = "commons-codec", module = "commons-codec") // provided by jcasbin
+ exclude(group = "com.google.guava", module = "guava") // provided by gravitino
+ exclude(group = "org.apache.commons", module = "commons-lang3") // provided by gravitino
+ exclude(group = "org.junit.jupiter", module = "*") // provided by test scope
}
implementation(libs.mybatis)
diff --git a/core/src/main/java/org/apache/gravitino/metrics/MetricsSystem.java b/core/src/main/java/org/apache/gravitino/metrics/MetricsSystem.java
index dde401bfd1..27ae051a7d 100644
--- a/core/src/main/java/org/apache/gravitino/metrics/MetricsSystem.java
+++ b/core/src/main/java/org/apache/gravitino/metrics/MetricsSystem.java
@@ -203,6 +203,10 @@ public class MetricsSystem implements Closeable {
MetricsSource.ICEBERG_REST_SERVER_METRIC_NAME + ".*.*",
MetricsSource.ICEBERG_REST_SERVER_METRIC_NAME + "_${1}",
ImmutableMap.of("operation", "${0}")),
+ new MapperConfig(
+ MetricsSource.LANCE_REST_SERVER_METRIC_NAME + ".*.*",
+ MetricsSource.LANCE_REST_SERVER_METRIC_NAME + "_${1}",
+ ImmutableMap.of("operation", "${0}")),
new MapperConfig(
MetricsSource.GRAVITINO_SERVER_METRIC_NAME + ".*.*",
MetricsSource.GRAVITINO_SERVER_METRIC_NAME + "_${1}",
diff --git a/core/src/main/java/org/apache/gravitino/metrics/source/MetricsSource.java b/core/src/main/java/org/apache/gravitino/metrics/source/MetricsSource.java
index cee2d6afe5..1d079f49ae 100644
--- a/core/src/main/java/org/apache/gravitino/metrics/source/MetricsSource.java
+++ b/core/src/main/java/org/apache/gravitino/metrics/source/MetricsSource.java
@@ -40,6 +40,7 @@ public abstract class MetricsSource {
// metrics source name
public static final String ICEBERG_REST_SERVER_METRIC_NAME = "iceberg-rest-server";
+ public static final String LANCE_REST_SERVER_METRIC_NAME = "lance-rest-server";
public static final String GRAVITINO_SERVER_METRIC_NAME = "gravitino-server";
public static final String GRAVITINO_RELATIONAL_STORE_METRIC_NAME = "gravitino-relational-store";
public static final String GRAVITINO_CATALOG_METRIC_PREFIX = "gravitino-catalog";
diff --git a/core/src/test/java/org/apache/gravitino/metrics/TestExtractMetricNameAndLabel.java b/core/src/test/java/org/apache/gravitino/metrics/TestExtractMetricNameAndLabel.java
index 4f3a1feba2..c6a57f3c87 100644
--- a/core/src/test/java/org/apache/gravitino/metrics/TestExtractMetricNameAndLabel.java
+++ b/core/src/test/java/org/apache/gravitino/metrics/TestExtractMetricNameAndLabel.java
@@ -62,6 +62,13 @@ public class TestExtractMetricNameAndLabel {
+ Collector.sanitizeMetricName(MetricNames.SERVER_IDLE_THREAD_NUM),
ImmutableMap.of());
+ checkResult(
+ MetricsSource.LANCE_REST_SERVER_METRIC_NAME + "." + MetricNames.SERVER_IDLE_THREAD_NUM,
+ Collector.sanitizeMetricName(MetricsSource.LANCE_REST_SERVER_METRIC_NAME)
+ + "_"
+ + Collector.sanitizeMetricName(MetricNames.SERVER_IDLE_THREAD_NUM),
+ ImmutableMap.of());
+
checkResult(
MetricsSource.ICEBERG_REST_SERVER_METRIC_NAME
+ ".update-table."
@@ -71,6 +78,15 @@ public class TestExtractMetricNameAndLabel {
+ Collector.sanitizeMetricName(MetricNames.HTTP_PROCESS_DURATION),
ImmutableMap.of("operation", "update-table"));
+ checkResult(
+ MetricsSource.LANCE_REST_SERVER_METRIC_NAME
+ + ".load-namespace."
+ + MetricNames.HTTP_PROCESS_DURATION,
+ Collector.sanitizeMetricName(MetricsSource.LANCE_REST_SERVER_METRIC_NAME)
+ + "_"
+ + Collector.sanitizeMetricName(MetricNames.HTTP_PROCESS_DURATION),
+ ImmutableMap.of("operation", "load-namespace"));
+
checkResult(
MetricsSource.GRAVITINO_SERVER_METRIC_NAME
+ ".update-table."
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 1b357e543b..4d650636eb 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -28,7 +28,8 @@ guava = "32.1.3-jre"
lombok = "1.18.20"
slf4j = "2.0.16"
log4j = "2.24.3"
-lance = "0.34.0"
+lance = "0.39.0"
+lance-namespace = "0.0.19"
jetty = "9.4.51.v20230217"
jersey = "2.41"
mockito = "4.11.0"
@@ -161,6 +162,7 @@ log4j-core = { group = "org.apache.logging.log4j", name = "log4j-core", version.
log4j-12-api = { group = "org.apache.logging.log4j", name = "log4j-1.2-api", version.ref = "log4j" }
log4j-layout-template-json = { group = "org.apache.logging.log4j", name = "log4j-layout-template-json", version.ref = "log4j" }
lance = { group = "com.lancedb", name = "lance-core", version.ref = "lance" }
+lance-namespace-core = { group = "com.lancedb", name = "lance-namespace-core", version.ref = "lance-namespace" }
jakarta-validation-api = { group = "jakarta.validation", name = "jakarta.validation-api", version.ref = "jakarta-validation" }
jetty-server = { group = "org.eclipse.jetty", name = "jetty-server", version.ref = "jetty" }
jetty-servlet = { group = "org.eclipse.jetty", name = "jetty-servlet", version.ref = "jetty" }
diff --git a/lance/build.gradle.kts b/lance/build.gradle.kts
new file mode 100644
index 0000000000..fa6eb7d5ef
--- /dev/null
+++ b/lance/build.gradle.kts
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+tasks.all {
+ enabled = false
+}
diff --git a/lance/lance-common/build.gradle.kts b/lance/lance-common/build.gradle.kts
new file mode 100644
index 0000000000..4ec9046e3d
--- /dev/null
+++ b/lance/lance-common/build.gradle.kts
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+description = "lance-common"
+
+plugins {
+ `maven-publish`
+ id("java")
+ id("idea")
+}
+
+dependencies {
+ implementation(project(":clients:client-java"))
+ implementation(project(":api"))
+ implementation(project(":common")) {
+ exclude("*")
+ }
+ implementation(project(":core")) {
+ exclude("*")
+ }
+
+ implementation(libs.guava)
+ implementation(libs.commons.lang3)
+ implementation(libs.lance.namespace.core) {
+ exclude(group = "com.lancedb", module = "lance-core")
+ }
+ implementation(libs.slf4j.api)
+
+ testImplementation(project(":server-common"))
+ testImplementation(libs.junit.jupiter.api)
+ testRuntimeOnly(libs.junit.jupiter.engine)
+}
diff --git a/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/config/LanceConfig.java b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/config/LanceConfig.java
new file mode 100644
index 0000000000..b6614c87ee
--- /dev/null
+++ b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/config/LanceConfig.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.lance.common.config;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.OverwriteDefaultConfig;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+
+/** Base Lance REST configuration. */
+public class LanceConfig extends Config implements OverwriteDefaultConfig {
+
+ public static final String LANCE_CONFIG_PREFIX = "gravitino.lance-rest.";
+ public static final String CONFIG_NAMESPACE_BACKEND = "namespace-backend";
+ public static final String CONFIG_METALAKE = "metalake-name";
+ public static final String CONFIG_URI = "uri";
+
+ public static final int DEFAULT_LANCE_REST_SERVICE_HTTP_PORT = 9101;
+ public static final int DEFAULT_LANCE_REST_SERVICE_HTTPS_PORT = 9533;
+ public static final String DEFAULT_NAMESPACE_BACKEND = "gravitino";
+ public static final String DEFAULT_URI = "http://localhost:8090";
+
+ public static final ConfigEntry<String> CATALOG_NAME =
+ new ConfigBuilder(LANCE_CONFIG_PREFIX + "catalog-name")
+ .doc("Logical Lance catalog served by the REST endpoint")
+ .version(ConfigConstants.VERSION_0_1_0)
+ .stringConf()
+ .createWithDefault("default");
+
+ public static final ConfigEntry<String> NAMESPACE_BACKEND =
+ new ConfigBuilder(LANCE_CONFIG_PREFIX + CONFIG_NAMESPACE_BACKEND)
+ .doc("The backend implementation for namespace operations")
+ .version(ConfigConstants.VERSION_0_1_0)
+ .stringConf()
+ .createWithDefault(DEFAULT_NAMESPACE_BACKEND);
+
+ public static final ConfigEntry<String> METALAKE_NAME =
+ new ConfigBuilder(LANCE_CONFIG_PREFIX + CONFIG_METALAKE)
+ .doc("The Metalake name for Gravitino namespace backend")
+ .version(ConfigConstants.VERSION_0_1_0)
+ .stringConf()
+ .create();
+
+ public static final ConfigEntry<String> NAMESPACE_URI =
+ new ConfigBuilder(LANCE_CONFIG_PREFIX + CONFIG_URI)
+ .doc("The URI for the namespace backend, e.g., Gravitino server URI")
+ .version(ConfigConstants.VERSION_0_1_0)
+ .stringConf()
+ .createWithDefault(DEFAULT_URI);
+
+ public LanceConfig(Map<String, String> properties) {
+ super(false);
+ loadFromMap(properties, key -> true);
+ }
+
+ public LanceConfig() {
+ super(false);
+ }
+
+ public String getCatalogName() {
+ return get(CATALOG_NAME);
+ }
+
+ public String getNamespaceUri() {
+ return get(NAMESPACE_URI);
+ }
+
+ public String getGravitinoMetalake() {
+ return get(METALAKE_NAME);
+ }
+
+ @Override
+ public Map<String, String> getOverwriteDefaultConfig() {
+ return ImmutableMap.of(
+ ConfigConstants.WEBSERVER_HTTP_PORT,
+ String.valueOf(DEFAULT_LANCE_REST_SERVICE_HTTP_PORT),
+ ConfigConstants.WEBSERVER_HTTPS_PORT,
+ String.valueOf(DEFAULT_LANCE_REST_SERVICE_HTTPS_PORT));
+ }
+}
diff --git a/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/LanceNamespaceBackend.java b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/LanceNamespaceBackend.java
new file mode 100644
index 0000000000..57d393f5ad
--- /dev/null
+++ b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/LanceNamespaceBackend.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.lance.common.ops;
+
+import java.util.Arrays;
+import org.apache.gravitino.lance.common.ops.gravitino.GravitinoLanceNamespaceWrapper;
+
+public enum LanceNamespaceBackend {
+ GRAVITINO("gravitino", GravitinoLanceNamespaceWrapper.class);
+
+ private final String type;
+ private final Class<? extends NamespaceWrapper> wrapperClass;
+
+ public static LanceNamespaceBackend fromType(String type) {
+ for (LanceNamespaceBackend backend : values()) {
+ if (backend.type.equalsIgnoreCase(type)) {
+ return backend;
+ }
+ }
+ throw new IllegalArgumentException(
+ String.format(
+ "Unknown backend type %s, available types: %s",
+ type, Arrays.toString(LanceNamespaceBackend.values())));
+ }
+
+ LanceNamespaceBackend(String type, Class<? extends NamespaceWrapper> wrapperClass) {
+ this.type = type;
+ this.wrapperClass = wrapperClass;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public Class<? extends NamespaceWrapper> getWrapperClass() {
+ return wrapperClass;
+ }
+}
diff --git a/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/LanceNamespaceOperations.java b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/LanceNamespaceOperations.java
new file mode 100644
index 0000000000..1b5da98ec0
--- /dev/null
+++ b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/LanceNamespaceOperations.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.lance.common.ops;
+
+import com.lancedb.lance.namespace.LanceNamespaceException;
+import com.lancedb.lance.namespace.model.CreateNamespaceRequest;
+import com.lancedb.lance.namespace.model.CreateNamespaceResponse;
+import com.lancedb.lance.namespace.model.DescribeNamespaceResponse;
+import com.lancedb.lance.namespace.model.DropNamespaceRequest;
+import com.lancedb.lance.namespace.model.DropNamespaceResponse;
+import com.lancedb.lance.namespace.model.ListNamespacesResponse;
+import java.util.Map;
+
+public interface LanceNamespaceOperations {
+
+ ListNamespacesResponse listNamespaces(
+ String namespaceId, String delimiter, String pageToken, Integer limit);
+
+ DescribeNamespaceResponse describeNamespace(String id, String delimiter);
+
+ CreateNamespaceResponse createNamespace(
+ String id,
+ String delimiter,
+ CreateNamespaceRequest.ModeEnum mode,
+ Map<String, String> properties);
+
+ DropNamespaceResponse dropNamespace(
+ String id,
+ String delimiter,
+ DropNamespaceRequest.ModeEnum mode,
+ DropNamespaceRequest.BehaviorEnum behavior);
+
+ void namespaceExists(String id, String delimiter) throws LanceNamespaceException;
+}
diff --git a/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/LanceTableOperations.java b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/LanceTableOperations.java
new file mode 100644
index 0000000000..057dce8fb3
--- /dev/null
+++ b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/LanceTableOperations.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.lance.common.ops;
+
+import com.lancedb.lance.namespace.model.ListTablesResponse;
+
+public interface LanceTableOperations {
+
+ ListTablesResponse listTables(String id, String delimiter, String pageToken, Integer limit);
+
+ // todo: add more table operation methods
+}
diff --git a/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/NamespaceWrapper.java b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/NamespaceWrapper.java
new file mode 100644
index 0000000000..936a5a7069
--- /dev/null
+++ b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/NamespaceWrapper.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.lance.common.ops;
+
+import org.apache.gravitino.lance.common.config.LanceConfig;
+
+public abstract class NamespaceWrapper {
+
+ public static final String NAMESPACE_DELIMITER_DEFAULT = "$";
+ private final LanceConfig config;
+
+ private volatile boolean initialized = false;
+ private LanceNamespaceOperations namespaceOps;
+ private LanceTableOperations tableOps;
+
+ public NamespaceWrapper(LanceConfig config) {
+ this.config = config;
+ }
+
+ protected abstract void initialize();
+
+ protected abstract LanceNamespaceOperations newNamespaceOps();
+
+ protected abstract LanceTableOperations newTableOps();
+
+ public abstract void close() throws Exception;
+
+ public LanceNamespaceOperations asNamespaceOps() {
+ // lazy initialize the operations because it may block the startup
+ initIfNeeded();
+ return namespaceOps;
+ }
+
+ public LanceTableOperations asTableOps() {
+ // lazy initialize the operations because it may block the startup
+ initIfNeeded();
+ return tableOps;
+ }
+
+ public LanceConfig config() {
+ return config;
+ }
+
+ private void initAll() {
+ initialize();
+ namespaceOps = newNamespaceOps();
+ tableOps = newTableOps();
+ initialized = true;
+ }
+
+ private void initIfNeeded() {
+ if (!initialized) {
+ synchronized (this) {
+ if (!initialized) {
+ initAll();
+ }
+ }
+ }
+ }
+}
diff --git a/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java
new file mode 100644
index 0000000000..59f637b5a1
--- /dev/null
+++ b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.lance.common.ops.gravitino;
+
+import static org.apache.gravitino.lance.common.config.LanceConfig.METALAKE_NAME;
+import static org.apache.gravitino.lance.common.config.LanceConfig.NAMESPACE_URI;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.lancedb.lance.namespace.LanceNamespaceException;
+import com.lancedb.lance.namespace.ObjectIdentifier;
+import com.lancedb.lance.namespace.model.CreateNamespaceRequest;
+import com.lancedb.lance.namespace.model.CreateNamespaceResponse;
+import com.lancedb.lance.namespace.model.DescribeNamespaceResponse;
+import com.lancedb.lance.namespace.model.DropNamespaceRequest;
+import com.lancedb.lance.namespace.model.DropNamespaceResponse;
+import com.lancedb.lance.namespace.model.ListNamespacesResponse;
+import com.lancedb.lance.namespace.model.ListTablesResponse;
+import com.lancedb.lance.namespace.util.PageUtil;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchCatalogException;
+import org.apache.gravitino.lance.common.config.LanceConfig;
+import org.apache.gravitino.lance.common.ops.LanceNamespaceOperations;
+import org.apache.gravitino.lance.common.ops.LanceTableOperations;
+import org.apache.gravitino.lance.common.ops.NamespaceWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GravitinoLanceNamespaceWrapper extends NamespaceWrapper
+ implements LanceNamespaceOperations, LanceTableOperations {
+
+ private static final Logger LOG = LoggerFactory.getLogger(GravitinoLanceNamespaceWrapper.class);
+ private GravitinoClient client;
+
+ public GravitinoLanceNamespaceWrapper(LanceConfig config) {
+ super(config);
+ }
+
+ @Override
+ protected void initialize() {
+ String uri = config().get(NAMESPACE_URI);
+ String metalakeName = config().get(METALAKE_NAME);
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(metalakeName),
+ "Metalake name must be provided for Gravitino namespace backend");
+
+ this.client = GravitinoClient.builder(uri).withMetalake(metalakeName).build();
+ }
+
+ @Override
+ public LanceNamespaceOperations newNamespaceOps() {
+ return this;
+ }
+
+ @Override
+ protected LanceTableOperations newTableOps() {
+ return this;
+ }
+
+ @Override
+ public void close() {
+ if (client != null) {
+ try {
+ client.close();
+ } catch (Exception e) {
+ LOG.warn("Error closing Gravitino client", e);
+ }
+ }
+ }
+
+ @Override
+ public ListNamespacesResponse listNamespaces(
+ String namespaceId, String delimiter, String pageToken, Integer limit) {
+ ObjectIdentifier nsId = ObjectIdentifier.of(namespaceId, delimiter);
+ Preconditions.checkArgument(
+ nsId.levels() <= 2, "Expected at most 2-level namespace but got: %s", namespaceId);
+
+ List<String> namespaces;
+ switch (nsId.levels()) {
+ case 0:
+ // List catalogs of type relational and provider generic-lakehouse
+ namespaces =
+ Arrays.stream(client.listCatalogsInfo())
+ .filter(this::isLakehouseCatalog)
+ .map(Catalog::name)
+ .collect(Collectors.toList());
+ break;
+
+ case 1:
+ // List schemas under the catalog
+ String catalogName = nsId.levelAtListPos(0);
+ Catalog catalog = client.loadCatalog(catalogName);
+ if (!isLakehouseCatalog(catalog)) {
+ throw new NoSuchCatalogException("Catalog not found: %s", catalogName);
+ }
+
+ namespaces = Lists.newArrayList(catalog.asSchemas().listSchemas());
+ break;
+
+ default:
+ throw new IllegalArgumentException(
+ "Expected at most 2-level namespace but got: " + namespaceId);
+ }
+
+ Collections.sort(namespaces);
+ PageUtil.Page page =
+ PageUtil.splitPage(namespaces, pageToken, PageUtil.normalizePageSize(limit));
+ ListNamespacesResponse response = new ListNamespacesResponse();
+ response.setNamespaces(Sets.newHashSet(page.items()));
+ response.setPageToken(page.nextPageToken());
+ return response;
+ }
+
+ @Override
+ public DescribeNamespaceResponse describeNamespace(String id, String delimiter) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public CreateNamespaceResponse createNamespace(
+ String id,
+ String delimiter,
+ CreateNamespaceRequest.ModeEnum mode,
+ Map<String, String> properties) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public DropNamespaceResponse dropNamespace(
+ String id,
+ String delimiter,
+ DropNamespaceRequest.ModeEnum mode,
+ DropNamespaceRequest.BehaviorEnum behavior) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public void namespaceExists(String id, String delimiter) throws LanceNamespaceException {}
+
+ private boolean isLakehouseCatalog(Catalog catalog) {
+ return catalog.type().equals(Catalog.Type.RELATIONAL)
+ && "generic-lakehouse".equals(catalog.provider());
+ }
+
+ @Override
+ public ListTablesResponse listTables(
+ String id, String delimiter, String pageToken, Integer limit) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+}
diff --git a/lance/lance-common/src/test/java/org/apache/gravitino/lance/common/config/TestLanceConfig.java b/lance/lance-common/src/test/java/org/apache/gravitino/lance/common/config/TestLanceConfig.java
new file mode 100644
index 0000000000..176634f309
--- /dev/null
+++ b/lance/lance-common/src/test/java/org/apache/gravitino/lance/common/config/TestLanceConfig.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.lance.common.config;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import org.apache.gravitino.server.web.JettyServerConfig;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestLanceConfig {
+ @Test
+ public void testLoadLanceConfig() {
+ Map<String, String> properties =
+ ImmutableMap.of("gravitino.lance-rest.catalog-name", "test_catalog");
+
+ LanceConfig lanceConfig = new LanceConfig();
+ lanceConfig.loadFromMap(properties, k -> k.startsWith("gravitino.lance-rest."));
+ Assertions.assertEquals("test_catalog", lanceConfig.getCatalogName());
+
+ LanceConfig lanceConfig2 = new LanceConfig(properties);
+ Assertions.assertEquals("test_catalog", lanceConfig2.getCatalogName());
+ }
+
+ @Test
+ public void testDefaultCatalogName() {
+ // Test default catalog name when not specified
+ Map<String, String> properties = ImmutableMap.of();
+ LanceConfig lanceConfig = new LanceConfig(properties);
+ Assertions.assertEquals("default", lanceConfig.getCatalogName());
+ }
+
+ @Test
+ public void testLanceHttpPort() {
+ Map<String, String> properties = ImmutableMap.of();
+ LanceConfig lanceConfig = new LanceConfig(properties);
+ JettyServerConfig jettyServerConfig = JettyServerConfig.fromConfig(lanceConfig);
+ Assertions.assertEquals(
+ LanceConfig.DEFAULT_LANCE_REST_SERVICE_HTTP_PORT, jettyServerConfig.getHttpPort());
+ Assertions.assertEquals(
+ LanceConfig.DEFAULT_LANCE_REST_SERVICE_HTTPS_PORT, jettyServerConfig.getHttpsPort());
+
+ properties =
+ ImmutableMap.of(
+ JettyServerConfig.WEBSERVER_HTTP_PORT.getKey(),
+ "9101",
+ JettyServerConfig.WEBSERVER_HTTPS_PORT.getKey(),
+ "9533");
+ lanceConfig = new LanceConfig(properties);
+ jettyServerConfig = JettyServerConfig.fromConfig(lanceConfig);
+ Assertions.assertEquals(9101, jettyServerConfig.getHttpPort());
+ Assertions.assertEquals(9533, jettyServerConfig.getHttpsPort());
+ }
+
+ @Test
+ public void testGravitinoUriAndMetalake() {
+ // Test default values
+ Map<String, String> properties = ImmutableMap.of();
+ LanceConfig lanceConfig = new LanceConfig(properties);
+ Assertions.assertEquals("http://localhost:8090", lanceConfig.getNamespaceUri());
+ Assertions.assertNull(lanceConfig.getGravitinoMetalake()); // No default, must be configured
+
+ // Test custom values
+ properties =
+ ImmutableMap.of(
+ LanceConfig.NAMESPACE_URI.getKey(),
+ "http://gravitino-server:8090",
+ LanceConfig.METALAKE_NAME.getKey(),
+ "production");
+ lanceConfig = new LanceConfig(properties);
+ Assertions.assertEquals("http://gravitino-server:8090", lanceConfig.getNamespaceUri());
+ Assertions.assertEquals("production", lanceConfig.getGravitinoMetalake());
+ }
+
+ @Test
+ public void testCompleteConfiguration() {
+ // Test all configurations together for auxiliary mode
+ Map<String, String> properties =
+ ImmutableMap.<String, String>builder()
+ .put(LanceConfig.CATALOG_NAME.getKey(), "lance_catalog")
+ .put(LanceConfig.NAMESPACE_URI.getKey(), "http://gravitino-prod:8090")
+ .put(LanceConfig.METALAKE_NAME.getKey(), "production")
+ .put(LanceConfig.NAMESPACE_BACKEND.getKey(), "gravitino")
+ .put(JettyServerConfig.WEBSERVER_HTTP_PORT.getKey(), "9101")
+ .build();
+
+ LanceConfig lanceConfig = new LanceConfig(properties);
+
+ // Verify all config values
+ Assertions.assertEquals("lance_catalog", lanceConfig.getCatalogName());
+ Assertions.assertEquals("http://gravitino-prod:8090", lanceConfig.getNamespaceUri());
+ Assertions.assertEquals("production", lanceConfig.getGravitinoMetalake());
+
+ JettyServerConfig jettyConfig = JettyServerConfig.fromConfig(lanceConfig);
+ Assertions.assertEquals(9101, jettyConfig.getHttpPort());
+ }
+}
diff --git a/lance/lance-rest-server/build.gradle.kts b/lance/lance-rest-server/build.gradle.kts
new file mode 100644
index 0000000000..6709b51194
--- /dev/null
+++ b/lance/lance-rest-server/build.gradle.kts
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+description = "lance-rest-server"
+
+plugins {
+ `maven-publish`
+ id("java")
+ id("idea")
+}
+
+dependencies {
+ implementation(project(":api"))
+ implementation(project(":catalogs:catalog-common"))
+ implementation(project(":common")) {
+ exclude("*")
+ }
+ implementation(project(":core")) {
+ exclude("*")
+ }
+ implementation(project(":server-common")) {
+ exclude("*")
+ }
+
+ implementation(project(":lance:lance-common"))
+
+ implementation(libs.bundles.jetty)
+ implementation(libs.bundles.jersey)
+ implementation(libs.bundles.log4j)
+ implementation(libs.bundles.metrics)
+ implementation(libs.bundles.prometheus)
+ implementation(libs.commons.lang3)
+ implementation(libs.lance.namespace.core) {
+ exclude(group = "com.lancedb", module = "lance-core")
+ }
+ implementation(libs.metrics.jersey2)
+ implementation(libs.guava)
+ implementation(libs.jackson.annotations)
+ implementation(libs.jackson.databind)
+ implementation(libs.jackson.datatype.jdk8)
+ implementation(libs.jackson.datatype.jsr310)
+
+ testImplementation(libs.junit.jupiter.api)
+ testRuntimeOnly(libs.junit.jupiter.engine)
+}
+
+tasks {
+ val copyDepends by registering(Copy::class) {
+ from(configurations.runtimeClasspath)
+ into("build/libs")
+ }
+
+ jar {
+ finalizedBy(copyDepends)
+ }
+
+ register("copyLibs", Copy::class) {
+ dependsOn(copyDepends, "build")
+ from("build/libs")
+ into("$rootDir/distribution/package/lance-rest-server/libs")
+ }
+
+ register("copyLibsToStandalonePackage", Copy::class) {
+ dependsOn(copyDepends, "build")
+ from("build/libs")
+ into("$rootDir/distribution/gravitino-lance-rest-server/libs")
+ }
+
+ register("copyLibAndConfigs", Copy::class) {
+ dependsOn("copyLibs")
+ }
+
+ register("copyLibAndConfigsToStandalonePackage", Copy::class) {
+ dependsOn("copyLibsToStandalonePackage")
+ }
+
+ named("generateMetadataFileForMavenJavaPublication") {
+ dependsOn(copyDepends)
+ }
+}
diff --git a/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/LanceRESTService.java b/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/LanceRESTService.java
new file mode 100644
index 0000000000..d1409c8e12
--- /dev/null
+++ b/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/LanceRESTService.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.lance;
+
+import static org.apache.gravitino.lance.common.config.LanceConfig.NAMESPACE_BACKEND;
+
+import java.lang.reflect.Constructor;
+import java.util.Map;
+import javax.servlet.Servlet;
+import org.apache.gravitino.GravitinoEnv;
+import org.apache.gravitino.auxiliary.GravitinoAuxiliaryService;
+import org.apache.gravitino.lance.common.config.LanceConfig;
+import org.apache.gravitino.lance.common.ops.LanceNamespaceBackend;
+import org.apache.gravitino.lance.common.ops.NamespaceWrapper;
+import org.apache.gravitino.metrics.MetricsSystem;
+import org.apache.gravitino.metrics.source.MetricsSource;
+import org.apache.gravitino.server.web.HttpServerMetricsSource;
+import org.apache.gravitino.server.web.JettyServer;
+import org.apache.gravitino.server.web.JettyServerConfig;
+import org.glassfish.hk2.utilities.binding.AbstractBinder;
+import org.glassfish.jersey.jackson.JacksonFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.servlet.ServletContainer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Thin REST service shell for Lance metadata. */
+public class LanceRESTService implements GravitinoAuxiliaryService {
+
+ private static final Logger LOG = LoggerFactory.getLogger(LanceRESTService.class);
+
+ public static final String SERVICE_NAME = "lance-rest";
+ public static final String LANCE_SPEC = "/lance/*";
+
+ private JettyServer server;
+ private NamespaceWrapper lanceNamespace;
+
+ @Override
+ public String shortName() {
+ return SERVICE_NAME;
+ }
+
+ @Override
+ public void serviceInit(Map<String, String> properties) {
+ LanceConfig lanceConfig = new LanceConfig(properties);
+ JettyServerConfig serverConfig = JettyServerConfig.fromConfig(lanceConfig);
+
+ server = new JettyServer();
+ // Get MetricsSystem directly from GravitinoEnv for zero-overhead access
+ MetricsSystem metricsSystem = GravitinoEnv.getInstance().metricsSystem();
+ server.initialize(serverConfig, SERVICE_NAME, false);
+
+ this.lanceNamespace = loadNamespaceImpl(lanceConfig);
+
+ ResourceConfig resourceConfig = new ResourceConfig();
+ resourceConfig.register(JacksonFeature.class);
+ resourceConfig.packages("org.apache.gravitino.lance.service.rest");
+ resourceConfig.register(
+ new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(lanceNamespace).to(NamespaceWrapper.class).ranked(1);
+ }
+ });
+
+ // Register metrics with shared MetricsSystem
+ HttpServerMetricsSource httpServerMetricsSource =
+ new HttpServerMetricsSource(
+ MetricsSource.LANCE_REST_SERVER_METRIC_NAME, resourceConfig, server);
+ metricsSystem.register(httpServerMetricsSource);
+
+ Servlet container = new ServletContainer(resourceConfig);
+ server.addServlet(container, LANCE_SPEC);
+ server.addCustomFilters(LANCE_SPEC);
+ server.addSystemFilters(LANCE_SPEC);
+
+ LOG.info("Initialized Lance REST service for catalog {}", lanceConfig.getCatalogName());
+ }
+
+ @Override
+ public void serviceStart() {
+ if (server != null) {
+ server.start();
+ LOG.info("Lance REST service started");
+ }
+ }
+
+ @Override
+ public void serviceStop() throws Exception {
+ if (server != null) {
+ server.stop();
+ LOG.info("Lance REST service stopped");
+ }
+ if (lanceNamespace != null) {
+ lanceNamespace.close();
+ }
+ }
+
+ public void join() {
+ if (server != null) {
+ server.join();
+ }
+ }
+
+ private NamespaceWrapper loadNamespaceImpl(LanceConfig lanceConfig) {
+ String backendType = lanceConfig.get(NAMESPACE_BACKEND);
+ LanceNamespaceBackend lanceNamespaceBackend = LanceNamespaceBackend.fromType(backendType);
+
+ try {
+ Constructor<? extends NamespaceWrapper> constructor =
+ lanceNamespaceBackend.getWrapperClass().getConstructor(LanceConfig.class);
+ return constructor.newInstance(lanceConfig);
+ } catch (Exception e) {
+ LOG.error("Error loading namespace implementation for backend type: {}", backendType, e);
+ throw new RuntimeException("Failed to load namespace implementation", e);
+ }
+ }
+}
diff --git a/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/LanceExceptionMapper.java b/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/LanceExceptionMapper.java
new file mode 100644
index 0000000000..2465e6ed63
--- /dev/null
+++ b/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/LanceExceptionMapper.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.lance.service;
+
+import static org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace;
+
+import com.lancedb.lance.namespace.LanceNamespaceException;
+import com.lancedb.lance.namespace.model.ErrorResponse;
+import java.util.Optional;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+import org.apache.gravitino.exceptions.NotFoundException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Provider
+public class LanceExceptionMapper implements ExceptionMapper<Exception> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(LanceExceptionMapper.class);
+
+ public static Response toRESTResponse(String instance, Exception ex) {
+ LanceNamespaceException lanceException =
+ ex instanceof LanceNamespaceException
+ ? (LanceNamespaceException) ex
+ : toLanceNamespaceException(instance, ex);
+
+ return handleLanceNamespaceException(lanceException);
+ }
+
+ @Override
+ public Response toResponse(Exception ex) {
+ return toRESTResponse("", ex);
+ }
+
+ private static LanceNamespaceException toLanceNamespaceException(String instance, Exception ex) {
+ if (ex instanceof NotFoundException) {
+ return LanceNamespaceException.notFound(
+ ex.getMessage(), ex.getClass().getSimpleName(), instance, getStackTrace(ex));
+
+ } else if (ex instanceof IllegalArgumentException) {
+ return LanceNamespaceException.badRequest(
+ ex.getMessage(), ex.getClass().getSimpleName(), instance, getStackTrace(ex));
+
+ } else if (ex instanceof UnsupportedOperationException) {
+ return LanceNamespaceException.unsupportedOperation(
+ ex.getMessage(), ex.getClass().getSimpleName(), instance, getStackTrace(ex));
+
+ } else {
+ LOG.warn("Lance REST server unexpected exception:", ex);
+ return LanceNamespaceException.serverError(
+ ex.getMessage(), ex.getClass().getSimpleName(), instance, getStackTrace(ex));
+ }
+ }
+
+ // Referred from lance-namespace-adapter's LanceNamespaces exception handling
+ // com.lancedb.lance.namespace.adapter.GlobalExceptionHandler
+ private static Response handleLanceNamespaceException(LanceNamespaceException ex) {
+ ErrorResponse errResp = new ErrorResponse();
+ Optional<ErrorResponse> errorResponse = ex.getErrorResponse();
+ if (errorResponse.isPresent() && errorResponse.get().getCode() != null) {
+ errResp = errorResponse.get();
+
+ } else {
+ // Transform error info into ErrorResponse
+ errResp.setCode(ex.getCode());
+ errResp.setError(ex.getMessage());
+ }
+
+ return Response.status(errResp.getCode()).entity(errResp).build();
+ }
+}
diff --git a/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/rest/LanceNamespaceOperations.java b/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/rest/LanceNamespaceOperations.java
new file mode 100644
index 0000000000..2d07357f30
--- /dev/null
+++ b/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/rest/LanceNamespaceOperations.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.lance.service.rest;
+
+import static org.apache.gravitino.lance.common.ops.NamespaceWrapper.NAMESPACE_DELIMITER_DEFAULT;
+
+import com.codahale.metrics.annotation.ResponseMetered;
+import com.codahale.metrics.annotation.Timed;
+import com.lancedb.lance.namespace.model.ListNamespacesResponse;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.apache.gravitino.lance.common.ops.NamespaceWrapper;
+import org.apache.gravitino.lance.service.LanceExceptionMapper;
+import org.apache.gravitino.metrics.MetricNames;
+
+@Path("/v1/namespace")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class LanceNamespaceOperations {
+
+ private final NamespaceWrapper lanceNamespace;
+
+ @Inject
+ public LanceNamespaceOperations(NamespaceWrapper lanceNamespace) {
+ this.lanceNamespace = lanceNamespace;
+ }
+
+ @GET
+ @Path("/{id}/list")
+ @Timed(name = "list-namespaces." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)
+ @ResponseMetered(name = "list-namespaces", absolute = true)
+ public Response listNamespaces(
+ @Encoded @PathParam("id") String namespaceId,
+ @DefaultValue(NAMESPACE_DELIMITER_DEFAULT) @QueryParam("delimiter") String delimiter,
+ @QueryParam("page_token") String pageToken,
+ @QueryParam("limit") Integer limit) {
+ try {
+ ListNamespacesResponse response =
+ lanceNamespace.asNamespaceOps().listNamespaces(namespaceId, delimiter, pageToken, limit);
+ return Response.ok(response).build();
+ } catch (Exception e) {
+ return LanceExceptionMapper.toRESTResponse(namespaceId, e);
+ }
+ }
+}
diff --git a/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/rest/LanceTableOperations.java b/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/rest/LanceTableOperations.java
new file mode 100644
index 0000000000..1f30d1b326
--- /dev/null
+++ b/lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/rest/LanceTableOperations.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.lance.service.rest;
+
+import static org.apache.gravitino.lance.common.ops.NamespaceWrapper.NAMESPACE_DELIMITER_DEFAULT;
+
+import com.codahale.metrics.annotation.ResponseMetered;
+import com.codahale.metrics.annotation.Timed;
+import com.lancedb.lance.namespace.model.ListTablesResponse;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.apache.gravitino.lance.common.ops.NamespaceWrapper;
+import org.apache.gravitino.lance.service.LanceExceptionMapper;
+import org.apache.gravitino.metrics.MetricNames;
+
+@Path("/v1/namespace/{id}/table")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class LanceTableOperations {
+
+ private final NamespaceWrapper lanceNamespace;
+
+ @Inject
+ public LanceTableOperations(NamespaceWrapper lanceNamespace) {
+ this.lanceNamespace = lanceNamespace;
+ }
+
+ @GET
+ @Path("/list")
+ @Timed(name = "list-tables." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)
+ @ResponseMetered(name = "list-tables", absolute = true)
+ public Response listTables(
+ @Encoded @PathParam("id") String namespaceId,
+ @DefaultValue(NAMESPACE_DELIMITER_DEFAULT) @QueryParam("delimiter") String delimiter,
+ @QueryParam("page_token") String pageToken,
+ @QueryParam("limit") Integer limit) {
+ try {
+ ListTablesResponse response =
+ lanceNamespace.asTableOps().listTables(namespaceId, delimiter, pageToken, limit);
+ return Response.ok(response).build();
+ } catch (Exception e) {
+ return LanceExceptionMapper.toRESTResponse(namespaceId, e);
+ }
+ }
+}
diff --git a/lance/lance-rest-server/src/main/resources/META-INF/services/org.apache.gravitino.auxiliary.GravitinoAuxiliaryService b/lance/lance-rest-server/src/main/resources/META-INF/services/org.apache.gravitino.auxiliary.GravitinoAuxiliaryService
new file mode 100644
index 0000000000..97c3f356df
--- /dev/null
+++ b/lance/lance-rest-server/src/main/resources/META-INF/services/org.apache.gravitino.auxiliary.GravitinoAuxiliaryService
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.gravitino.lance.LanceRESTService
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 5355fe7bc5..4a3a5d468a 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -59,6 +59,8 @@ if (gradle.startParameter.projectProperties["enableFuse"]?.toBoolean() == true)
}
include("iceberg:iceberg-common")
include("iceberg:iceberg-rest-server")
+include("lance:lance-common")
+include("lance:lance-rest-server")
include("authorizations:authorization-ranger", "authorizations:authorization-common", "authorizations:authorization-chain")
include("trino-connector:trino-connector", "trino-connector:integration-test")
include("spark-connector:spark-common")