Skip to content

Commit 1222ac6

Browse files
committed
Make CreateSchema() to be static
Signed-off-by: yhmo <yihua.mo@zilliz.com>
1 parent a6d1561 commit 1222ac6

5 files changed

Lines changed: 44 additions & 11 deletions

File tree

sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,22 @@ public void createCollection(CreateCollectionReq request) {
249249
}
250250

251251
/**
252-
* Creates a collection schema.
252+
* Creates a collection schema. This method is deprecated from v2.5.9, replaced by CreateSchema()
253253
* @return CreateCollectionReq.CollectionSchema
254254
*/
255+
@Deprecated
255256
public CreateCollectionReq.CollectionSchema createSchema() {
256-
return collectionService.createSchema();
257+
return CollectionService.createSchema();
257258
}
259+
260+
/**
261+
* Creates a collection schema.
262+
* @return CreateCollectionReq.CollectionSchema
263+
*/
264+
public static CreateCollectionReq.CollectionSchema CreateSchema() {
265+
return CollectionService.createSchema();
266+
}
267+
258268
/**
259269
* list milvus collections
260270
*

sdk-core/src/main/java/io/milvus/v2/service/collection/CollectionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public GetCollectionStatsResp getCollectionStats(MilvusServiceGrpc.MilvusService
357357
return getCollectionStatsResp;
358358
}
359359

360-
public CreateCollectionReq.CollectionSchema createSchema() {
360+
public static CreateCollectionReq.CollectionSchema createSchema() {
361361
return CreateCollectionReq.CollectionSchema.builder()
362362
.build();
363363
}

sdk-core/src/main/java/io/milvus/v2/utils/ConvertUtils.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,22 @@ public DescribeIndexResp convertToDescribeIndexResp(List<IndexDescription> respo
9191
Map<String, String> properties = new HashMap<>();
9292
for(KeyValuePair param : params) {
9393
if (param.getKey().equals(Constant.INDEX_TYPE)) {
94-
// may throw IllegalArgumentException
95-
indexType = IndexParam.IndexType.valueOf(param.getValue().toUpperCase());
94+
try {
95+
indexType = IndexParam.IndexType.valueOf(param.getValue().toUpperCase());
96+
} catch (IllegalArgumentException e) {
97+
// if the server has new index type but sdk version is old
98+
e.printStackTrace();
99+
}
96100
} else if (param.getKey().equals(Constant.METRIC_TYPE)) {
97-
// may throw IllegalArgumentException
98-
metricType = IndexParam.MetricType.valueOf(param.getValue());
101+
// for scalar index such as Trie/STL_SORT, the param.getValue() is empty, no need to parse it
102+
if (!param.getValue().isEmpty()) {
103+
try {
104+
metricType = IndexParam.MetricType.valueOf(param.getValue());
105+
} catch (IllegalArgumentException e) {
106+
// if the server has new metric type but sdk version is old
107+
e.printStackTrace();
108+
}
109+
}
99110
} else if (param.getKey().equals(Constant.MMAP_ENABLED)) {
100111
properties.put(param.getKey(), param.getValue()); // just for compatible with old versions
101112
extraParams.put(param.getKey(), param.getValue());

sdk-core/src/test/java/io/milvus/v2/client/MilvusClientV2DockerTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,10 @@ void testIndex() {
11561156
.metricType(IndexParam.MetricType.COSINE)
11571157
.extraParams(extra)
11581158
.build());
1159+
indexes.add(IndexParam.builder()
1160+
.fieldName("name")
1161+
.indexType(IndexParam.IndexType.TRIE)
1162+
.build());
11591163
client.createCollection(CreateCollectionReq.builder()
11601164
.collectionName(randomCollectionName)
11611165
.collectionSchema(collectionSchema)
@@ -1217,12 +1221,20 @@ void testIndex() {
12171221
collProps = descCollResp.getProperties();
12181222
Assertions.assertFalse(collProps.containsKey("prop"));
12191223

1220-
// index alter properties
1224+
// describe scalar index
12211225
DescribeIndexResp descResp = client.describeIndex(DescribeIndexReq.builder()
1226+
.collectionName(randomCollectionName)
1227+
.fieldName("name")
1228+
.build());
1229+
DescribeIndexResp.IndexDesc desc = descResp.getIndexDescByFieldName("name");
1230+
Assertions.assertEquals(IndexParam.IndexType.TRIE, desc.getIndexType());
1231+
1232+
// index alter properties
1233+
descResp = client.describeIndex(DescribeIndexReq.builder()
12221234
.collectionName(randomCollectionName)
12231235
.fieldName("vector")
12241236
.build());
1225-
DescribeIndexResp.IndexDesc desc = descResp.getIndexDescByFieldName("vector");
1237+
desc = descResp.getIndexDescByFieldName("vector");
12261238
Assertions.assertEquals("vector", desc.getFieldName());
12271239
Assertions.assertFalse(desc.getIndexName().isEmpty());
12281240
Assertions.assertEquals(IndexParam.IndexType.HNSW, desc.getIndexType());
@@ -1270,7 +1282,7 @@ void testIndex() {
12701282
// drop index
12711283
client.dropIndex(DropIndexReq.builder()
12721284
.collectionName(randomCollectionName)
1273-
.fieldName("vector")
1285+
.indexName("vector")
12741286
.build());
12751287

12761288
IndexParam param = IndexParam.builder()

tests/milvustest/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<dependency>
9090
<groupId>com.google.protobuf</groupId>
9191
<artifactId>protobuf-java</artifactId>
92-
<version>3.24.0</version>
92+
<version>3.25.5</version>
9393
</dependency>
9494
<!--Allure-->
9595
<dependency>

0 commit comments

Comments
 (0)