Skip to content

Commit

Permalink
Support dropIndexProperties/dropDatabaseProperties/dropCollectionProp…
Browse files Browse the repository at this point in the history
…erties (#1240)

Signed-off-by: yhmo <[email protected]>
  • Loading branch information
yhmo authored Dec 18, 2024
1 parent d580cca commit 7972369
Show file tree
Hide file tree
Showing 14 changed files with 420 additions and 34 deletions.
81 changes: 68 additions & 13 deletions sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,31 +290,46 @@ public void useDatabase(@NonNull String dbName) throws InterruptedException {
public void createDatabase(CreateDatabaseReq request) {
retry(()-> databaseService.createDatabase(this.getRpcStub(), request));
}

/**
* Drops a database. Note that this method drops all data in the database.
* @param request drop database request
*/
public void dropDatabase(DropDatabaseReq request) {
retry(()-> databaseService.dropDatabase(this.getRpcStub(), request));
}

/**
* List all databases.
* @return List of String database names
*/
public ListDatabasesResp listDatabases() {
return retry(()-> databaseService.listDatabases(this.getRpcStub()));
}

/**
* Alter database with key value pair. (Available from Milvus v2.4.4)
* Deprecated, replaced by alterDatabaseProperties from v2.5.2, to keep consistence with other SDKs
* @param request alter database request
*/
@Deprecated
public void alterDatabase(AlterDatabaseReq request) {
retry(()-> databaseService.alterDatabase(this.getRpcStub(), request));
alterDatabaseProperties(AlterDatabasePropertiesReq.builder()
.databaseName(request.getDatabaseName())
.properties(request.getProperties())
.build());
}
/**
* Alter a database's properties (Available from Milvus v2.5.2)
* @param request alter database properties request
*/
public void alterDatabaseProperties(AlterDatabasePropertiesReq request) {
retry(()-> databaseService.alterDatabaseProperties(this.getRpcStub(), request));
}
/**
* drop a database's properties (Available from Milvus v2.5.2)
* @param request alter database properties request
*/
public void dropDatabaseProperties(DropDatabasePropertiesReq request) {
retry(()-> databaseService.dropDatabaseProperties(this.getRpcStub(), request));
}

/**
* Show detail of database base, such as replica number and resource groups. (Available from Milvus v2.4.4)
* @param request describe database request
Expand All @@ -341,7 +356,6 @@ public void createCollection(CreateCollectionReq request) {
public CreateCollectionReq.CollectionSchema createSchema() {
return collectionService.createSchema();
}

/**
* list milvus collections
*
Expand All @@ -350,7 +364,6 @@ public CreateCollectionReq.CollectionSchema createSchema() {
public ListCollectionsResp listCollections() {
return retry(()-> collectionService.listCollections(this.getRpcStub()));
}

/**
* Drops a collection in Milvus.
*
Expand All @@ -361,11 +374,32 @@ public void dropCollection(DropCollectionReq request) {
}
/**
* Alter a collection in Milvus.
* Deprecated, replaced by alterCollectionProperties from v2.5.2, to keep consistence with other SDKs
*
* @param request alter collection request
*/
@Deprecated
public void alterCollection(AlterCollectionReq request) {
retry(()-> collectionService.alterCollection(this.getRpcStub(), request));
alterCollectionProperties(AlterCollectionPropertiesReq.builder()
.collectionName(request.getCollectionName())
.databaseName(request.getDatabaseName())
.properties(request.getProperties())
.build());
}
/**
* Alter a collection's properties (Available from Milvus v2.5.2).
*
* @param request alter collection properties request
*/
public void alterCollectionProperties(AlterCollectionPropertiesReq request) {
retry(()-> collectionService.alterCollectionProperties(this.getRpcStub(), request));
}
/**
* drop a collection's properties (Available from Milvus v2.5.2)
* @param request drop collection properties request
*/
public void dropCollectionProperties(DropCollectionPropertiesReq request) {
retry(()-> collectionService.dropCollectionProperties(this.getRpcStub(), request));
}
/**
* Checks whether a collection exists in Milvus.
Expand Down Expand Up @@ -447,11 +481,33 @@ public void dropIndex(DropIndexReq request) {
}
/**
* Alter an index in Milvus.
* Deprecated, replaced by alterIndexProperties from v2.5.2, to keep consistence with other SDKs
*
* @param request alter index request
*/
@Deprecated
public void alterIndex(AlterIndexReq request) {
retry(()->indexService.alterIndex(this.getRpcStub(), request));
alterIndexProperties(AlterIndexPropertiesReq.builder()
.collectionName(request.getCollectionName())
.databaseName(request.getDatabaseName())
.indexName(request.getIndexName())
.properties(request.getProperties())
.build());
}
/**
* Alter an index's properties (Available from Milvus v2.5.2)
*
* @param request alter index request
*/
public void alterIndexProperties(AlterIndexPropertiesReq request) {
retry(()->indexService.alterIndexProperties(this.getRpcStub(), request));
}
/**
* drop an index's properties (Available from Milvus v2.5.2)
* @param request drop index properties request
*/
public void dropIndexProperties(DropIndexPropertiesReq request) {
retry(()-> indexService.dropIndexProperties(this.getRpcStub(), request));
}
/**
* Checks whether an index exists for a specified field in a collection in Milvus.
Expand All @@ -462,7 +518,6 @@ public void alterIndex(AlterIndexReq request) {
public DescribeIndexResp describeIndex(DescribeIndexReq request) {
return retry(()->indexService.describeIndex(this.getRpcStub(), request));
}

/**
* Lists all indexes in a collection in Milvus.
*
Expand All @@ -472,8 +527,8 @@ public DescribeIndexResp describeIndex(DescribeIndexReq request) {
public List<String> listIndexes(ListIndexesReq request) {
return retry(()->indexService.listIndexes(this.getRpcStub(), request));
}
// Vector Operations

// Vector Operations
/**
* Inserts vectors into a collection in Milvus.
*
Expand Down Expand Up @@ -615,8 +670,8 @@ public void loadPartitions(LoadPartitionsReq request) {
public void releasePartitions(ReleasePartitionsReq request) {
retry(()->partitionService.releasePartitions(this.getRpcStub(), request));
}
// rbac operations
// user operations

// RBAC operations
/**
* list users
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ public Void dropCollection(MilvusServiceGrpc.MilvusServiceBlockingStub blockingS
return null;
}

public Void alterCollection(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, AlterCollectionReq request) {
String title = String.format("AlterCollectionRequest collectionName:%s", request.getCollectionName());
AlterCollectionRequest.Builder builder = AlterCollectionRequest.newBuilder();
public Void alterCollectionProperties(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, AlterCollectionPropertiesReq request) {
String title = String.format("AlterCollectionPropertiesReq collectionName:%s", request.getCollectionName());
AlterCollectionRequest.Builder builder = AlterCollectionRequest.newBuilder()
.setCollectionName(request.getCollectionName());
List<KeyValuePair> propertiesList = ParamUtils.AssembleKvPair(request.getProperties());
if (CollectionUtils.isNotEmpty(propertiesList)) {
propertiesList.forEach(builder::addProperties);
Expand All @@ -197,11 +198,22 @@ public Void alterCollection(MilvusServiceGrpc.MilvusServiceBlockingStub blocking
builder.setDbName(request.getDatabaseName());
}

AlterCollectionRequest alterCollectionRequest = builder
Status response = blockingStub.alterCollection(builder.build());
rpcUtils.handleResponse(title, response);

return null;
}

public Void dropCollectionProperties(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DropCollectionPropertiesReq request) {
String title = String.format("DropCollectionPropertiesReq collectionName:%s", request.getCollectionName());
AlterCollectionRequest.Builder builder = AlterCollectionRequest.newBuilder()
.setCollectionName(request.getCollectionName())
.build();
.addAllDeleteKeys(request.getPropertyKeys());
if (StringUtils.isNotEmpty(request.getDatabaseName())) {
builder.setDbName(request.getDatabaseName());
}

Status response = blockingStub.alterCollection(alterCollectionRequest);
Status response = blockingStub.alterCollection(builder.build());
rpcUtils.handleResponse(title, response);

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 io.milvus.v2.service.collection.request;

import lombok.Builder;
import lombok.Data;
import lombok.experimental.SuperBuilder;

import java.util.HashMap;
import java.util.Map;

@Data
@SuperBuilder
public class AlterCollectionPropertiesReq {
private String collectionName;
private String databaseName;
@Builder.Default
private final Map<String, String> properties = new HashMap<>();


public static abstract class AlterCollectionPropertiesReqBuilder<C extends AlterCollectionPropertiesReq, B extends AlterCollectionPropertiesReq.AlterCollectionPropertiesReqBuilder<C, B>> {
public B property(String key, String value) {
if(null == this.properties$value ){
this.properties$value = new HashMap<>();
}
this.properties$value.put(key, value);
this.properties$set = true;
return self();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

@Data
@SuperBuilder
@Deprecated
public class AlterCollectionReq {
private String collectionName;
private String databaseName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 io.milvus.v2.service.collection.request;

import lombok.Builder;
import lombok.Data;
import lombok.experimental.SuperBuilder;

import java.util.ArrayList;
import java.util.List;

@Data
@SuperBuilder
public class DropCollectionPropertiesReq {
private String collectionName;
private String databaseName;

@Builder.Default
private List<String> propertyKeys = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.milvus.grpc.*;
import io.milvus.param.ParamUtils;
import io.milvus.v2.service.BaseService;
import io.milvus.v2.service.collection.response.ListCollectionsResp;
import io.milvus.v2.service.database.request.*;
import io.milvus.v2.service.database.response.*;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -66,8 +65,8 @@ public ListDatabasesResp listDatabases(MilvusServiceGrpc.MilvusServiceBlockingSt
return listDatabasesResp;
}

public Void alterDatabase(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, AlterDatabaseReq request) {
String title = String.format("AlterDatabaseRequest databaseName:%s", request.getDatabaseName());
public Void alterDatabaseProperties(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, AlterDatabasePropertiesReq request) {
String title = String.format("AlterDatabasePropertiesReq databaseName:%s", request.getDatabaseName());
AlterDatabaseRequest.Builder builder = AlterDatabaseRequest.newBuilder()
.setDbName(request.getDatabaseName());
List<KeyValuePair> propertiesList = ParamUtils.AssembleKvPair(request.getProperties());
Expand All @@ -80,6 +79,17 @@ public Void alterDatabase(MilvusServiceGrpc.MilvusServiceBlockingStub blockingSt
return null;
}

public Void dropDatabaseProperties(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DropDatabasePropertiesReq request) {
String title = String.format("DropDatabasePropertiesReq databaseName:%s", request.getDatabaseName());
AlterDatabaseRequest.Builder builder = AlterDatabaseRequest.newBuilder()
.setDbName(request.getDatabaseName())
.addAllDeleteKeys(request.getPropertyKeys());

Status response = blockingStub.alterDatabase(builder.build());
rpcUtils.handleResponse(title, response);
return null;
}

public DescribeDatabaseResp describeDatabase(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DescribeDatabaseReq request) {
String title = String.format("DescribeDatabaseRequest databaseName:%s", request.getDatabaseName());
DescribeDatabaseRequest rpcRequest = DescribeDatabaseRequest.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 io.milvus.v2.service.database.request;

import lombok.Builder;
import lombok.Data;
import lombok.experimental.SuperBuilder;

import java.util.HashMap;
import java.util.Map;

@Data
@SuperBuilder
public class AlterDatabasePropertiesReq {
private String databaseName;
@Builder.Default
private Map<String, String> properties = new HashMap<>();

public static abstract class AlterDatabasePropertiesReqBuilder<C extends AlterDatabasePropertiesReq, B extends AlterDatabasePropertiesReq.AlterDatabasePropertiesReqBuilder<C, B>> {
public B property(String key, String value) {
if(null == this.properties$value ){
this.properties$value = new HashMap<>();
}
this.properties$value.put(key, value);
this.properties$set = true;
return self();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

@Data
@SuperBuilder
@Deprecated
public class AlterDatabaseReq {
private String databaseName;
@Builder.Default
Expand Down
Loading

0 comments on commit 7972369

Please sign in to comment.