Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,20 @@
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.

--------------------------------------------------------------------------------

This product includes code from Apache Iceberg. The following files are copied from iceberg, and some of them have been slightly modified.

* DynMethods.java
* DynConstructors.java
* Configurable.java
* ClientPool.java
* ClientPoolImpl.java
* HiveClientPool.java
* RuntimeMetaException.java
* TestHiveMetastore.java

Copyright: 2004-2025 The Apache Software Foundation.
Home page: https://iceberg.apache.org/
License: https://www.apache.org/licenses/LICENSE-2.0
13 changes: 9 additions & 4 deletions java/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,15 @@
<property name="illegalPkgs" value="org.apache.log4j" />
<property name="illegalPkgs" value="org.apache.commons.lang" />
</module>
<!-- support structured logging -->
<module name="RegexpSinglelineJava">
<property name="format" value="org\.slf4j\.(Logger|LoggerFactory)" />
<property name="message" value="Please use org.apache.spark.internal.(SparkLogger|SparkLoggerFactory) instead." />
<module name="IllegalImport">
<property name="illegalPkgs" value="org.apache.hadoop.hbase.shaded" />
<message key="import.illegal"
value="Do not use HBase shaded classes."/>
</module>
<module name="IllegalImport">
<property name="illegalPkgs" value="org.apache.parquet" />
<message key="import.illegal"
value="Do not use Parquet classes directly."/>
</module>
</module>
</module>
5 changes: 5 additions & 0 deletions java/lance-namespace-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>lance-namespace-apache-client</artifactId>
<version>${lance-namespace.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.4.0-jre</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed 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 com.lancedb.lance.namespace;

// Copied from apache iceberg.
// https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/hadoop/Configurable.java
public interface Configurable<C> {
void setConf(C conf);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,41 @@
import com.lancedb.lance.namespace.model.TableExistsResponse;
import com.lancedb.lance.namespace.model.UpdateTableRequest;
import com.lancedb.lance.namespace.model.UpdateTableResponse;
import com.lancedb.lance.namespace.util.DynConstructors;

import java.util.Map;

/** TODO: add documentation */
public interface LanceNamespace {
static LanceNamespace create(String name, Map<String, String> properties, Object conf) {
String impl =
properties.getOrDefault(NamespaceProperties.NS_IMPL, NamespaceProperties.NS_IMPL_DEFAULT);

LanceNamespace ns;
try {
ns =
(LanceNamespace)
DynConstructors.builder(LanceNamespace.class).impl(impl).buildChecked().newInstance();
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException(
String.format("Failed to construct namespace, impl: %s", impl), e);
}

if (ns instanceof Configurable && conf != null) {
((Configurable) ns).setConf(conf);
}

ns.initialize(name, properties);
return ns;
}

/**
* Initialize namespace with custom name and conf properties.
*
* @param name a custom name for the namespace
* @param properties namespace conf properties
*/
default void initialize(String name, Map<String, String> properties) {}

ListNamespacesResponse listNamespaces(ListNamespacesRequest request);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed 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 com.lancedb.lance.namespace;

public class NamespaceProperties {
public static final String NS_IMPL = "lance.namespace.impl";
public static final String NS_IMPL_DEFAULT =
"com.lancedb.lance.namespace.hive.LanceHiveNamespace";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed 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 com.lancedb.lance.namespace;

import com.lancedb.lance.namespace.util.ValidationUtil;

import com.google.common.collect.ImmutableList;

import java.util.Arrays;
import java.util.List;

public class ObjectIdentifier {
private String[] levels;

private ObjectIdentifier(String[] levels) {
this.levels = levels;
}

public static ObjectIdentifier of(List<String> levels) {
levels.stream()
.forEach(
level ->
ValidationUtil.checkNotNullOrEmptyString(
level, "Invalid namespace containing empty string %s", levels));
return new ObjectIdentifier(levels.toArray(new String[0]));
}

public String level(int pos) {
return levels[pos];
}
Comment thread
wojiaodoubao marked this conversation as resolved.

public String name() {
return empty() ? "" : levels[levels.length - 1];
}

public List<String> parent() {
return size() < 2
? ImmutableList.of()
: ImmutableList.copyOf(Arrays.copyOfRange(levels, 0, levels.length - 1));
}

public int size() {
return levels == null ? 0 : levels.length;
}

public boolean empty() {
return size() == 0;
}
}
Loading