Feature: Java Client Enhance
- Dominant language
- Rust
- Stars
- 11.4k
- Forks
- 1.1k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 140
Description
### SDK
Python
### Description
With the emergence of more and more data lake components, such as paimon and iceberg, if the lake format bottom layer can support the operation of lance format, the user's storage cost will be reduced a lot. At present, the function of java client is not perfect yet. I want to add more JNI extension support to it, so that java client can support the relevant operations of lance format like Python client.
# Java Client Enhancement Plan
## 1. Architecture Design
I recommend adopting a layered architecture similar to the Python client:
```
Java API Layer (User Interface)
↓
JNI Bridge Layer (JNI Bridging)
↓
Rust Core (Underlying Implementation)
```
## 2. Core Class Design
### Enhanced Connection Class
The current Connection class needs to be extended with more configuration options:
```java
public class Connection implements Closeable {
// Add connection configuration
private String uri;
private String apiKey;
private String region;
private Map storageOptions;
// Support multiple connection methods
public static Connection connect(String uri);
public static Connection connect(String uri, ConnectionOptions options);
}
```
### Complete Table Class Implementation
A complete Table class needs to be implemented supporting all data operations:
```java
public class Table {
// Basic operations
public void add(List> data);
public void delete(String condition);
public void update(String condition, Map values);
// Query operations
public QueryBuilder search(float[] vector);
public QueryBuilder search(String text, QueryType type);
// Index operations
public void createIndex(String column, IndexConfig config);
public void createFtsIndex(String[] columns, FtsConfig config);
}
```
### Query Builder
Implement a fluent query API:
```java
public class QueryBuilder {
public QueryBuilder limit(int limit);
public QueryBuilder where(String condition);
public QueryBuilder select(String[] columns);
public QueryBuilder distanceType(String metric);
// Execute queries
public List> toList();
public ArrowTable toArrow();
}
```
## 3. JNI Layer Extensions
Additional function bindings need to be added to the Rust JNI layer:
Extended JNI functions:
```rust
// Table operations
#[no_mangle]
pub extern "C" fn Java_com_lancedb_lancedb_Connection_createTable(
env: JNIEnv,
obj: JObject,
name: JString,
data: JObject,
options: JObject,
) -> jobject {
// Implement table creation logic
}
// Query operations
#[no_mangle]
pub extern "C" fn Java_com_lancedb_lancedb_Table_vectorSearch(
env: JNIEnv,
obj: JObject,
vector: jfloatArray,
options: JObject,
) -> jobject {
// Implement vector search logic
}
```
## 4. Data Type Support
### Arrow Integration
The Java client needs to integrate Apache Arrow for efficient data exchange:
```java
public class ArrowUtils {
public static VectorSchemaRoot fromMaps(List> data);
public static List> toMaps(VectorSchemaRoot root);
}
```
### Type Conversion
Implement conversion between Java objects and Arrow format:
```java
public class DataConverter {
public static ArrowRecordBatch convertToArrow(List> data);
public static List> convertFromArrow(ArrowRecordBatch batch);
}
```
## 5. Search Functionality Implementation
### Vector Search
```java
public class VectorQuery extends QueryBuilder {
private float[] queryVector;
private String distanceMetric = "l2";
private int nprobes = 20;
private Integer refineFactory;
public VectorQuery distanceType(String metric) {
this.distanceMetric = metric;
return this;
}
public VectorQuery nprobes(int nprobes) {
this.nprobes = nprobes;
return this;
}
}
```
### Full-Text Search
```java
public class FtsQuery extends QueryBuilder {
private String queryText;
private String[] searchColumns;
public FtsQuery columns(String... columns) {
this.searchColumns = columns;
return this;
}
}
```
### Hybrid Search
```java
public class HybridQuery extends QueryBuilder {
private float[] queryVector;
private String queryText;
private String vectorColumn;
private String[] ftsColumns;
}
```
## 6. Index Management
Implement complete index creation and management functionality:
```java
public class IndexConfig {
public static class VectorIndex {
public static IndexConfig ivfPq(int numPartitions, int numSubVectors);
public static IndexConfig ivfFlat(int numPartitions);
public static IndexConfig hnsw(int m, int efConstruction);
}
public static class ScalarIndex {
public static IndexConfig btree();
public static IndexConfig bitmap();
public static IndexConfig labelList();
}
}
```
## 7. Asynchronous Support
Consider adding asynchronous API support:
```java
public class AsyncConnection {
public CompletableFuture createTableAsync(String name, List> data);
public CompletableFuture openTableAsync(String name);
}
public class AsyncTable {
public CompletableFuture addAsync(List> data);
public CompletableFuture>> searchAsync(float[] vector);
}
```
## 8. Implementation Priority
I recommend implementing in the following priority order:
1. **Phase 1**: [Basic table operations (create, open, add data)](https://github.com/lancedb/lancedb/issues/2456)
2. **Phase 2**: Vector search functionality
3. **Phase 3**: Index creation and management
4. **Phase 4**: Full-text search and hybrid search
5. **Phase 5**: Asynchronous API support
## 9. Testing Strategy
Create corresponding tests for the Java client based on Python client test cases [1](#9-0) :
```java
@Test
public void testBasicOperations() {
Connection db = Connection.connect("./test.lancedb");
// Create table
List> data = Arrays.asList(
Map.of("vector", new float[]{1.1f, 1.2f}, "item", "foo", "price", 10.0),
Map.of("vector", new float[]{5.9f, 26.5f}, "item", "bar", "price", 20.0)
);
Table table = db.createTable("my_table", data);
// Vector search
List> results = table.search(new float[]{1.0f, 1.0f})
.limit(10)
.toList();
assertThat(results).hasSize(2);
}
```
This implementation plan will enable the Java client to have the same core functionality as the Python client, including complete data operations, multiple search modes, and index management capabilities.
Contributor guide
Research direction
Start by reading the current Java client and Rust JNI layer, then compare their capabilities with the Python client and the Phase 1 issue #2456. The proposed work spans table operations, queries, indexes, Arrow conversion, and asynchronous APIs, so first identify a single approved phase and its existing tests. Done should mean that scoped phase is implemented with corresponding Java client tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, python, rust
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100