diff --git a/sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java b/sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java index 8350ba127..dd201a928 100644 --- a/sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java +++ b/sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java @@ -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 @@ -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) { @@ -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 */ @@ -388,7 +388,7 @@ 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 */ @@ -396,7 +396,15 @@ 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) { @@ -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 */ @@ -506,7 +514,7 @@ 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 */ @@ -514,7 +522,7 @@ 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) { diff --git a/sdk-core/src/main/java/io/milvus/v2/service/collection/CollectionService.java b/sdk-core/src/main/java/io/milvus/v2/service/collection/CollectionService.java index 42d6be500..19441e01d 100644 --- a/sdk-core/src/main/java/io/milvus/v2/service/collection/CollectionService.java +++ b/sdk-core/src/main/java/io/milvus/v2/service/collection/CollectionService.java @@ -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 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() diff --git a/sdk-core/src/main/java/io/milvus/v2/service/collection/request/AlterCollectionFieldReq.java b/sdk-core/src/main/java/io/milvus/v2/service/collection/request/AlterCollectionFieldReq.java new file mode 100644 index 000000000..9be10e5e4 --- /dev/null +++ b/sdk-core/src/main/java/io/milvus/v2/service/collection/request/AlterCollectionFieldReq.java @@ -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 properties = new HashMap<>(); + + public static abstract class AlterCollectionFieldReqBuilder> { + 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(); + } + } +} diff --git a/sdk-core/src/main/java/io/milvus/v2/service/vector/VectorService.java b/sdk-core/src/main/java/io/milvus/v2/service/vector/VectorService.java index 2024011af..a0778fec1 100644 --- a/sdk-core/src/main/java/io/milvus/v2/service/vector/VectorService.java +++ b/sdk-core/src/main/java/io/milvus/v2/service/vector/VectorService.java @@ -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; @@ -237,7 +238,7 @@ public DeleteResp delete(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStu if (request.getFilter() != null && !request.getFilter().isEmpty()) { Map 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()); diff --git a/sdk-core/src/test/java/io/milvus/v2/client/MilvusClientV2DockerTest.java b/sdk-core/src/test/java/io/milvus/v2/client/MilvusClientV2DockerTest.java index 3caecafff..c484dd76b 100644 --- a/sdk-core/src/test/java/io/milvus/v2/client/MilvusClientV2DockerTest.java +++ b/sdk-core/src/test/java/io/milvus/v2/client/MilvusClientV2DockerTest.java @@ -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 indexes = new ArrayList<>(); Map extra = new HashMap<>(); @@ -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 properties = new HashMap<>(); properties.put(Constant.TTL_SECONDS, "10"); @@ -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"))