Browse Source

Make CreateSchema() to be static (#1398)

Signed-off-by: yhmo <yihua.mo@zilliz.com>
groot 1 month ago
parent
commit
98775b9029

+ 1 - 1
docker-compose.yml

@@ -32,7 +32,7 @@ services:
 
   standalone:
     container_name: milvus-javasdk-test-standalone
-    image: milvusdb/milvus:v2.5.8
+    image: milvusdb/milvus:v2.5.11
     command: ["milvus", "run", "standalone"]
     environment:
       ETCD_ENDPOINTS: etcd:2379

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

@@ -249,12 +249,22 @@ public class MilvusClientV2 {
     }
 
     /**
-     * Creates a collection schema.
+     * Creates a collection schema. This method is deprecated from v2.5.9, replaced by CreateSchema()
      * @return CreateCollectionReq.CollectionSchema
      */
+    @Deprecated
     public CreateCollectionReq.CollectionSchema createSchema() {
-        return collectionService.createSchema();
+        return CollectionService.createSchema();
     }
+
+    /**
+     * Creates a collection schema.
+     * @return CreateCollectionReq.CollectionSchema
+     */
+    public static CreateCollectionReq.CollectionSchema CreateSchema() {
+        return CollectionService.createSchema();
+    }
+
     /**
      * list milvus collections
      *

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

@@ -357,7 +357,7 @@ public class CollectionService extends BaseService {
         return getCollectionStatsResp;
     }
 
-    public CreateCollectionReq.CollectionSchema createSchema() {
+    public static CreateCollectionReq.CollectionSchema createSchema() {
         return CreateCollectionReq.CollectionSchema.builder()
                 .build();
     }

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

@@ -91,11 +91,22 @@ public class ConvertUtils {
             Map<String, String> properties = new HashMap<>();
             for(KeyValuePair param : params) {
                 if (param.getKey().equals(Constant.INDEX_TYPE)) {
-                    // may throw IllegalArgumentException
-                    indexType = IndexParam.IndexType.valueOf(param.getValue().toUpperCase());
+                    try {
+                        indexType = IndexParam.IndexType.valueOf(param.getValue().toUpperCase());
+                    } catch (IllegalArgumentException e) {
+                        // if the server has new index type but sdk version is old
+                        e.printStackTrace();
+                    }
                 } else if (param.getKey().equals(Constant.METRIC_TYPE)) {
-                    // may throw IllegalArgumentException
-                    metricType = IndexParam.MetricType.valueOf(param.getValue());
+                    // for scalar index such as Trie/STL_SORT, the param.getValue() is empty, no need to parse it
+                    if (!param.getValue().isEmpty()) {
+                        try {
+                            metricType = IndexParam.MetricType.valueOf(param.getValue());
+                        } catch (IllegalArgumentException e) {
+                            // if the server has new metric type but sdk version is old
+                            e.printStackTrace();
+                        }
+                    }
                 } else if (param.getKey().equals(Constant.MMAP_ENABLED)) {
                     properties.put(param.getKey(), param.getValue()); // just for compatible with old versions
                     extraParams.put(param.getKey(), param.getValue());

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

@@ -1156,6 +1156,10 @@ class MilvusClientV2DockerTest {
                 .metricType(IndexParam.MetricType.COSINE)
                 .extraParams(extra)
                 .build());
+        indexes.add(IndexParam.builder()
+                .fieldName("name")
+                .indexType(IndexParam.IndexType.TRIE)
+                .build());
         client.createCollection(CreateCollectionReq.builder()
                 .collectionName(randomCollectionName)
                 .collectionSchema(collectionSchema)
@@ -1217,12 +1221,20 @@ class MilvusClientV2DockerTest {
         collProps = descCollResp.getProperties();
         Assertions.assertFalse(collProps.containsKey("prop"));
 
-        // index alter properties
+        // describe scalar index
         DescribeIndexResp descResp = client.describeIndex(DescribeIndexReq.builder()
+                .collectionName(randomCollectionName)
+                .fieldName("name")
+                .build());
+        DescribeIndexResp.IndexDesc desc = descResp.getIndexDescByFieldName("name");
+        Assertions.assertEquals(IndexParam.IndexType.TRIE, desc.getIndexType());
+
+        // index alter properties
+        descResp = client.describeIndex(DescribeIndexReq.builder()
                 .collectionName(randomCollectionName)
                 .fieldName("vector")
                 .build());
-        DescribeIndexResp.IndexDesc desc = descResp.getIndexDescByFieldName("vector");
+        desc = descResp.getIndexDescByFieldName("vector");
         Assertions.assertEquals("vector", desc.getFieldName());
         Assertions.assertFalse(desc.getIndexName().isEmpty());
         Assertions.assertEquals(IndexParam.IndexType.HNSW, desc.getIndexType());
@@ -1270,7 +1282,7 @@ class MilvusClientV2DockerTest {
         // drop index
         client.dropIndex(DropIndexReq.builder()
                 .collectionName(randomCollectionName)
-                .fieldName("vector")
+                .indexName("vector")
                 .build());
 
         IndexParam param = IndexParam.builder()

+ 1 - 1
tests/milvustest/pom.xml

@@ -89,7 +89,7 @@
         <dependency>
             <groupId>com.google.protobuf</groupId>
             <artifactId>protobuf-java</artifactId>
-            <version>3.24.0</version>
+            <version>3.25.5</version>
         </dependency>
         <!--Allure-->
         <dependency>