Skip to content

Commit 2361050

Browse files
authored
feat: support create, describe and drop table for Hive and refactor Hive2 and Hive3 (#166)
1 parent 53495f7 commit 2361050

42 files changed

Lines changed: 2583 additions & 1127 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/src/spec/concepts.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,45 @@ The identifier of any object must be unique among all other objects that share t
4242

4343
Based on the uniqueness property of an object name within its parent namespace,
4444
an object identifier is the list of object names starting from (not including) the root namespace to (including) the object itself.
45-
This is also called an **list identifier**.
45+
This is also called an **list style identifier**.
4646
For examples:
4747

48-
- the list identifier of `cat5` is `[cat2, cat5]`
49-
- the list identifier of `t1` is `[cat2, cat5, t1]`
48+
- the list style identifier of `cat5` is `[cat2, cat5]`
49+
- the list style identifier of `t1` is `[cat2, cat5, t1]`
5050

51-
The dot (`.`) symbol is typically used as the delimiter to join all the names to form an **string identifier**,
51+
The dot (`.`) symbol is typically used as the delimiter to join all the names to form an **string style identifier**,
5252
but other symbols could also be used if dot is used in the object name.
5353
For examples:
5454

55-
- the string identifier of `cat5` is `cat2.cat5`
56-
- the string identifier of `t1` is `cat2.cat5.t1`
57-
- the string identifier of `t3` is `cat4$t3` when using delimiter `$`
55+
- the string style identifier of `cat5` is `cat2.cat5`
56+
- the string style identifier of `t1` is `cat2.cat5.t1`
57+
- the string style identifier of `t3` is `cat4$t3` when using delimiter `$`
5858

5959
## Name and Identifier for Root Namespace
6060

6161
The root namespace itself has no name or identifier.
62-
When represented in code, its name and string identifier is represented by an empty or null string,
63-
and its list identifier is represented by an empty or null list.
62+
When represented in code, its name and string style identifier is represented by an empty or null string,
63+
and its list style identifier is represented by an empty or null list.
6464

6565
The actual name and identifier of the root namespace is typically
6666
assigned by users through some configuration when used in a tool.
6767
For example, a root namespace can be called `cat1` in Ray, but called `cat2` in Apache Spark,
6868
and they are both configured to connect to the same root namespace.
6969

70-
## Namespace Level
70+
## Object Level
7171

72-
If every table has the same number of namespaces all the way to the root namespace,
73-
the namespace is called **leveled**. The [example above](#namespace-definition) is not leveled
74-
because `t1` has 2 namespaces `ns1` and `ns4` before root, whereas `t2` has 1 namespace `ns2` before root.
72+
The root namespace is always at level 0.
73+
This means if an object has list style identifier with list size `N`,
74+
the object is at the `N`th level in the entire namespace hierarchy.
75+
We also say the object identifier has `N` levels.
76+
For examples, a namespace `[ns1, ns2]` is at level 2, the identifier `ns1.ns2` has 2 levels.
77+
A table `[catalog1, database2, table3]` is at level 3, the identifier `catalog1.database2.table3` has 3 levels.
78+
79+
### Leveled Namespace
7580

76-
For a leveled namespace, the number of namespaces up to and including the root for any table
77-
is referred to as the **number of levels**.
81+
If every table in the root namespace are at the same level `N`, the namespace is called **leveled**,
82+
and we say this namespace is a `N`-level namespace.
7883
For example, a [directory namespace](../impls/dir) is a 1-level namespace,
79-
and a [Hive 2.x namespace](../impls/hive) is a 2-level namespace.
84+
and a [Hive 2.x namespace](../impls/hive) is a 2-level namespace.
85+
The [example above](#namespace-definition) is not leveled
86+
because `t1` has 2 namespaces `ns1` and `ns4` before root, whereas `t2` has 1 namespace `ns2` before root.

java/Makefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ gen-springboot-server: clean-springboot-server
5151
--additional-properties=groupId=com.lancedb,artifactId=lance-namespace-springboot-server,artifactVersion=$(VERSION),parentGroupId=com.lancedb,parentArtifactId=lance-namespace-root,parentVersion=$(VERSION),parentRelativePath=pom.xml,library=spring-boot,interfaceOnly=true,useOptional=true,openApiNullable=false,java8=true,apiPackage=com.lancedb.lance.namespace.server.springboot.api,modelPackage=com.lancedb.lance.namespace.server.springboot.model,useTags=true,skipDefaultInterface=false,hideGenerationTimestamp=true,licenseName=Apache-2.0,licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.txt
5252
rm -rf lance-namespace-springboot-server/.openapi-generator-ignore
5353
rm -rf lance-namespace-springboot-server/.openapi-generator
54+
rm -rf lance-namespace-springboot-server/pom.xml
55+
cp springboot-server-pom.xml lance-namespace-springboot-server/pom.xml
5456

5557
.PHONY: lint-springboot-server
5658
lint-springboot-server: gen-apache-client gen-springboot-server
@@ -70,10 +72,15 @@ build-adapter:
7072
./mvnw spotless:apply -pl lance-namespace-adapter -am
7173
./mvnw install -pl lance-namespace-adapter -am
7274

73-
.PHONY: build-hive
74-
build-hive:
75-
./mvnw spotless:apply -pl lance-namespace-hive -am
76-
./mvnw install -pl lance-namespace-hive -am
75+
.PHONY: build-hive2
76+
build-hive2:
77+
./mvnw spotless:apply -pl lance-namespace-hive2 -am
78+
./mvnw install -pl lance-namespace-hive2 -am
79+
80+
.PHONY: build-hive3
81+
build-hive3:
82+
./mvnw spotless:apply -pl lance-namespace-hive3 -am
83+
./mvnw install -pl lance-namespace-hive3 -am
7784

7885
.PHONY: build-glue
7986
build-glue:
@@ -92,4 +99,4 @@ clean: clean-apache-client clean-springboot-server
9299
gen: gen-apache-client gen-springboot-server lint-apache-client lint-springboot-server
93100

94101
.PHONY: build
95-
build: build-apache-client build-springboot-server build-core build-adapter build-hive build-glue build-lancedb
102+
build: build-apache-client build-springboot-server build-core build-adapter build-hive2 build-hive3 build-glue build-lancedb

java/lance-namespace-adapter/src/main/java/com/lancedb/lance/namespace/adapter/ServerToClientRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static DescribeNamespaceRequest describeNamespace(
7777
public static ListNamespacesRequest listNamespaces(
7878
String id, Optional<String> delimiter, Optional<String> pageToken, Optional<Integer> limit) {
7979
ListNamespacesRequest converted = new ListNamespacesRequest();
80-
converted.setId(ObjectIdentifier.of(id, delimiter.orElse(null)).idListStyle());
80+
converted.setId(ObjectIdentifier.of(id, delimiter.orElse(null)).listStyleId());
8181
converted.setPageToken(pageToken.orElse(null));
8282
converted.setLimit(limit.orElse(null));
8383
return converted;
@@ -86,7 +86,7 @@ public static ListNamespacesRequest listNamespaces(
8686
public static ListTablesRequest listTables(
8787
String id, Optional<String> delimiter, Optional<String> pageToken, Optional<Integer> limit) {
8888
ListTablesRequest converted = new ListTablesRequest();
89-
converted.setId(ObjectIdentifier.of(id, delimiter.orElse(null)).idListStyle());
89+
converted.setId(ObjectIdentifier.of(id, delimiter.orElse(null)).listStyleId());
9090
converted.setPageToken(pageToken.orElse(null));
9191
converted.setLimit(limit.orElse(null));
9292
return converted;

java/lance-namespace-adapter/src/main/java/com/lancedb/lance/namespace/adapter/TableController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public ResponseEntity<CreateTableResponse> createTable(
118118
byte[] data = readAllBytes(body.getInputStream());
119119
com.lancedb.lance.namespace.server.springboot.model.CreateTableRequest request =
120120
new com.lancedb.lance.namespace.server.springboot.model.CreateTableRequest();
121-
request.setId(ObjectIdentifier.of(id, delimiter.orElse(null)).idListStyle());
121+
request.setId(ObjectIdentifier.of(id, delimiter.orElse(null)).listStyleId());
122122
xLanceTableLocation.ifPresent(request::setLocation);
123123
if (xLanceTableProperties.isPresent()) {
124124
// Parse JSON properties
@@ -177,7 +177,7 @@ public ResponseEntity<InsertIntoTableResponse> insertIntoTable(
177177
byte[] data = readAllBytes(body.getInputStream());
178178
com.lancedb.lance.namespace.server.springboot.model.InsertIntoTableRequest request =
179179
new com.lancedb.lance.namespace.server.springboot.model.InsertIntoTableRequest();
180-
request.setId(ObjectIdentifier.of(id, delimiter.orElse(null)).idListStyle());
180+
request.setId(ObjectIdentifier.of(id, delimiter.orElse(null)).listStyleId());
181181
request.setMode(
182182
com.lancedb.lance.namespace.server.springboot.model.InsertIntoTableRequest.ModeEnum
183183
.fromValue(mode.orElse("append")));
@@ -213,7 +213,7 @@ public ResponseEntity<MergeInsertIntoTableResponse> mergeInsertIntoTable(
213213
byte[] data = readAllBytes(body.getInputStream());
214214
com.lancedb.lance.namespace.server.springboot.model.MergeInsertIntoTableRequest request =
215215
new com.lancedb.lance.namespace.server.springboot.model.MergeInsertIntoTableRequest();
216-
request.setId(ObjectIdentifier.of(id, delimiter.orElse(null)).idListStyle());
216+
request.setId(ObjectIdentifier.of(id, delimiter.orElse(null)).listStyleId());
217217
request.setOn(on);
218218
request.setWhenMatchedUpdateAll(whenMatchedUpdateAll.orElse(false));
219219
whenMatchedUpdateAllFilt.ifPresent(request::setWhenMatchedUpdateAllFilt);

java/lance-namespace-core/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@
9090
<artifactId>maven-surefire-plugin</artifactId>
9191
<version>${maven-surefire-plugin.version}</version>
9292
</plugin>
93+
<plugin>
94+
<groupId>org.apache.maven.plugins</groupId>
95+
<artifactId>maven-jar-plugin</artifactId>
96+
<version>3.3.0</version>
97+
<executions>
98+
<execution>
99+
<goals>
100+
<goal>test-jar</goal>
101+
</goals>
102+
</execution>
103+
</executions>
104+
</plugin>
93105
</plugins>
94106
<extensions>
95107
<extension>

java/lance-namespace-core/src/main/java/com/lancedb/lance/namespace/LanceNamespaces.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public class LanceNamespaces {
2626
ImmutableMap.<String, String>builder()
2727
.put("dir", "com.lancedb.lance.namespace.dir.DirectoryNamespace")
2828
.put("rest", "com.lancedb.lance.namespace.rest.RestNamespace")
29-
.put("hive", "com.lancedb.lance.namespace.hive.HiveNamespace")
29+
.put("hive2", "com.lancedb.lance.namespace.hive2.Hive2Namespace")
30+
.put("hive3", "com.lancedb.lance.namespace.hive3.Hive3Namespace")
3031
.put("glue", "com.lancedb.lance.namespace.glue.GlueNamespace")
3132
.build();
3233

java/lance-namespace-core/src/main/java/com/lancedb/lance/namespace/ObjectIdentifier.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static ObjectIdentifier of(List<String> levels) {
3737
.forEach(
3838
level ->
3939
ValidationUtil.checkNotNullOrEmptyString(
40-
level, "Invalid namespace containing empty string %s", levels));
40+
level, "Invalid namespace containing empty string levels %s", levels));
4141
return new ObjectIdentifier(levels.toArray(new String[0]));
4242
}
4343

@@ -54,22 +54,22 @@ public static ObjectIdentifier of(String id, String delimiter) {
5454
return new ObjectIdentifier(id.split(delimiter));
5555
}
5656

57-
public String level(int pos) {
57+
public String levelAtListPos(int pos) {
5858
return levels[pos];
5959
}
6060

61-
public String idStringStyle() {
62-
return idStringStyle(DELIMITER_DEFAULT);
61+
public String stringStyleId() {
62+
return stringStyleId(DELIMITER_DEFAULT);
6363
}
6464

65-
public String idStringStyle(String delimiter) {
65+
public String stringStyleId(String delimiter) {
6666
if (levels.length == 0) {
6767
return delimiter;
6868
}
6969
return String.join(delimiter, levels);
7070
}
7171

72-
public List<String> idListStyle() {
72+
public List<String> listStyleId() {
7373
return ImmutableList.copyOf(levels);
7474
}
7575

@@ -82,7 +82,7 @@ public List<String> parent() {
8282
}
8383

8484
public int levels() {
85-
return levels.length + 1;
85+
return levels.length;
8686
}
8787

8888
public boolean isRoot() {

0 commit comments

Comments
 (0)