Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AlterCollectionField #1251

Merged
merged 1 commit into from
Dec 24, 2024
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
26 changes: 17 additions & 9 deletions sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public ListDatabasesResp listDatabases() {
}
/**
* Alter database with key value pair. (Available from Milvus v2.4.4)
* Deprecated, replaced by alterDatabaseProperties from v2.5.3, to keep consistence with other SDKs
* Deprecated, replaced by alterDatabaseProperties from SDK v2.5.3, to keep consistence with other SDKs
* @param request alter database request
*/
@Deprecated
Expand All @@ -318,14 +318,14 @@ public void alterDatabase(AlterDatabaseReq request) {
.build());
}
/**
* Alter a database's properties (Available from Milvus v2.5.3)
* Alter a database's properties.
* @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.3)
* drop a database's properties.
* @param request alter database properties request
*/
public void dropDatabaseProperties(DropDatabasePropertiesReq request) {
Expand Down Expand Up @@ -375,7 +375,7 @@ public void dropCollection(DropCollectionReq request) {
}
/**
* Alter a collection in Milvus.
* Deprecated, replaced by alterCollectionProperties from v2.5.3, to keep consistence with other SDKs
* Deprecated, replaced by alterCollectionProperties from SDK v2.5.3, to keep consistence with other SDKs
*
* @param request alter collection request
*/
Expand All @@ -388,15 +388,23 @@ public void alterCollection(AlterCollectionReq request) {
.build());
}
/**
* Alter a collection's properties (Available from Milvus v2.5.3).
* Alter a collection's properties.
*
* @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.3)
* Alter a field's properties.
*
* @param request alter field properties request
*/
public void alterCollectionField(AlterCollectionFieldReq request) {
retry(()-> collectionService.alterCollectionField(this.getRpcStub(), request));
}
/**
* drop a collection's properties.
* @param request drop collection properties request
*/
public void dropCollectionProperties(DropCollectionPropertiesReq request) {
Expand Down Expand Up @@ -492,7 +500,7 @@ public void dropIndex(DropIndexReq request) {
}
/**
* Alter an index in Milvus.
* Deprecated, replaced by alterIndexProperties from v2.5.3, to keep consistence with other SDKs
* Deprecated, replaced by alterIndexProperties from SDK v2.5.3, to keep consistence with other SDKs
*
* @param request alter index request
*/
Expand All @@ -506,15 +514,15 @@ public void alterIndex(AlterIndexReq request) {
.build());
}
/**
* Alter an index's properties (Available from Milvus v2.5.3)
* Alter an index's properties.
*
* @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.3)
* drop an index's properties.
* @param request drop index properties request
*/
public void dropIndexProperties(DropIndexPropertiesReq request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@ public Void alterCollectionProperties(MilvusServiceGrpc.MilvusServiceBlockingStu
return null;
}

public Void alterCollectionField(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, AlterCollectionFieldReq request) {
String title = String.format("AlterCollectionFieldReq collectionName:%s", request.getCollectionName());
AlterCollectionFieldRequest.Builder builder = AlterCollectionFieldRequest.newBuilder()
.setCollectionName(request.getCollectionName())
.setFieldName(request.getFieldName());
List<KeyValuePair> propertiesList = ParamUtils.AssembleKvPair(request.getProperties());
if (CollectionUtils.isNotEmpty(propertiesList)) {
propertiesList.forEach(builder::addProperties);
}
if (StringUtils.isNotEmpty(request.getDatabaseName())) {
builder.setDbName(request.getDatabaseName());
}

Status response = blockingStub.alterCollectionField(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()
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 AlterCollectionFieldReq {
private String collectionName;
private String fieldName;
private String databaseName;
@Builder.Default
private final Map<String, String> properties = new HashMap<>();

public static abstract class AlterCollectionFieldReqBuilder<C extends AlterCollectionFieldReq, B extends AlterCollectionFieldReq.AlterCollectionFieldReqBuilder<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 @@ -34,6 +34,7 @@
import io.milvus.v2.service.vector.request.*;
import io.milvus.v2.service.vector.response.*;
import io.milvus.v2.utils.DataUtils;
import io.milvus.v2.utils.VectorUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -237,7 +238,7 @@ public DeleteResp delete(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStu
if (request.getFilter() != null && !request.getFilter().isEmpty()) {
Map<String, Object> filterTemplateValues = request.getFilterTemplateValues();
filterTemplateValues.forEach((key, value)->{
builder.putExprTemplateValues(key, vectorUtils.deduceAndCreateTemplateValue(value));
builder.putExprTemplateValues(key, VectorUtils.deduceAndCreateTemplateValue(value));
});
}
MutationResult response = blockingStub.delete(builder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,11 @@ void testIndex() {
.dataType(DataType.FloatVector)
.dimension(DIMENSION)
.build());
collectionSchema.addField(AddFieldReq.builder()
.fieldName("name")
.dataType(DataType.VarChar)
.maxLength(100)
.build());

List<IndexParam> indexes = new ArrayList<>();
Map<String,Object> extra = new HashMap<>();
Expand Down Expand Up @@ -1125,6 +1130,13 @@ void testIndex() {
.collectionName(randomCollectionName)
.build());

// alter field properties
client.alterCollectionField(AlterCollectionFieldReq.builder()
.collectionName(randomCollectionName)
.fieldName("name")
.property("max_length", "9")
.build());

// collection alter properties
Map<String, String> properties = new HashMap<>();
properties.put(Constant.TTL_SECONDS, "10");
Expand All @@ -1145,6 +1157,9 @@ void testIndex() {
Assertions.assertEquals("true", collProps.get(Constant.MMAP_ENABLED));
Assertions.assertEquals("val", collProps.get("prop"));

CreateCollectionReq.FieldSchema fieldScheam = descCollResp.getCollectionSchema().getField("name");
Assertions.assertEquals(9, fieldScheam.getMaxLength());

client.dropCollectionProperties(DropCollectionPropertiesReq.builder()
.collectionName(randomCollectionName)
.propertyKeys(Collections.singletonList("prop"))
Expand Down
Loading