|
@@ -2,16 +2,20 @@ package com.zilliz.milvustestv2.collection;
|
|
|
|
|
|
import com.zilliz.milvustestv2.common.BaseTest;
|
|
|
import com.zilliz.milvustestv2.common.CommonData;
|
|
|
-import io.milvus.v2.client.ConnectConfig;
|
|
|
-import io.milvus.v2.client.MilvusClientV2;
|
|
|
+import com.zilliz.milvustestv2.common.CommonFunction;
|
|
|
+import io.milvus.v2.common.DataType;
|
|
|
+import io.milvus.v2.common.IndexParam;
|
|
|
import io.milvus.v2.service.collection.request.*;
|
|
|
-import io.milvus.v2.service.collection.response.DescribeCollectionResp;
|
|
|
-import io.milvus.v2.service.collection.response.GetCollectionStatsResp;
|
|
|
import io.milvus.v2.service.collection.response.ListCollectionsResp;
|
|
|
+import io.milvus.v2.service.vector.response.SearchResp;
|
|
|
import org.testng.Assert;
|
|
|
import org.testng.annotations.AfterClass;
|
|
|
import org.testng.annotations.Test;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* @Author yongpeng.li
|
|
|
* @Date 2024/1/31 15:24
|
|
@@ -20,11 +24,12 @@ import org.testng.annotations.Test;
|
|
|
public class CreateCollectionTest extends BaseTest {
|
|
|
String simpleCollection="simpleCollection";
|
|
|
String repeatCollection="repeatCollection";
|
|
|
-
|
|
|
+ String collectionNameWithIndex="collectionNameWithIndex";
|
|
|
@AfterClass(alwaysRun = true)
|
|
|
public void cleanTestData(){
|
|
|
milvusClientV2.dropCollection(DropCollectionReq.builder().collectionName(simpleCollection).build());
|
|
|
milvusClientV2.dropCollection(DropCollectionReq.builder().collectionName(repeatCollection).build());
|
|
|
+ milvusClientV2.dropCollection(DropCollectionReq.builder().collectionName(collectionNameWithIndex).build());
|
|
|
|
|
|
}
|
|
|
|
|
@@ -57,4 +62,106 @@ public class CreateCollectionTest extends BaseTest {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test(description = "Create collection with index params,will auto load", groups = {"Smoke"})
|
|
|
+ public void createCollectionWithIndexParams(){
|
|
|
+ CreateCollectionReq.FieldSchema fieldInt64=CreateCollectionReq.FieldSchema.builder()
|
|
|
+ .autoID(false)
|
|
|
+ .dataType(io.milvus.v2.common.DataType.Int64)
|
|
|
+ .isPrimaryKey(true)
|
|
|
+ .name(CommonData.fieldInt64)
|
|
|
+ .build();
|
|
|
+ CreateCollectionReq.FieldSchema fieldInt32=CreateCollectionReq.FieldSchema.builder()
|
|
|
+ .dataType(DataType.Int32)
|
|
|
+ .name(CommonData.fieldInt32)
|
|
|
+ .isPrimaryKey(false)
|
|
|
+ .build();
|
|
|
+ CreateCollectionReq.FieldSchema fieldInt16=CreateCollectionReq.FieldSchema.builder()
|
|
|
+ .dataType(DataType.Int16)
|
|
|
+ .name(CommonData.fieldInt16)
|
|
|
+ .isPrimaryKey(false)
|
|
|
+ .build();
|
|
|
+ CreateCollectionReq.FieldSchema fieldInt8=CreateCollectionReq.FieldSchema.builder()
|
|
|
+ .dataType(DataType.Int8)
|
|
|
+ .name(CommonData.fieldInt8)
|
|
|
+ .isPrimaryKey(false)
|
|
|
+ .build();
|
|
|
+ CreateCollectionReq.FieldSchema fieldDouble=CreateCollectionReq.FieldSchema.builder()
|
|
|
+ .dataType(DataType.Double)
|
|
|
+ .name(CommonData.fieldDouble)
|
|
|
+ .isPrimaryKey(false)
|
|
|
+ .build();
|
|
|
+ CreateCollectionReq.FieldSchema fieldArray=CreateCollectionReq.FieldSchema.builder()
|
|
|
+ .dataType(DataType.Array)
|
|
|
+ .name(CommonData.fieldArray)
|
|
|
+ .elementType(DataType.Int64)
|
|
|
+ .maxCapacity(1000)
|
|
|
+ .isPrimaryKey(false)
|
|
|
+ .build();
|
|
|
+ CreateCollectionReq.FieldSchema fieldBool=CreateCollectionReq.FieldSchema.builder()
|
|
|
+ .dataType(DataType.Bool)
|
|
|
+ .name(CommonData.fieldBool)
|
|
|
+ .isPrimaryKey(false)
|
|
|
+ .build();
|
|
|
+ CreateCollectionReq.FieldSchema fieldVarchar=CreateCollectionReq.FieldSchema.builder()
|
|
|
+ .dataType(DataType.VarChar)
|
|
|
+ .name(CommonData.fieldVarchar)
|
|
|
+ .isPrimaryKey(false)
|
|
|
+ .maxLength(1000)
|
|
|
+ .build();
|
|
|
+ CreateCollectionReq.FieldSchema fieldFloat=CreateCollectionReq.FieldSchema.builder()
|
|
|
+ .dataType(DataType.Float)
|
|
|
+ .name(CommonData.fieldFloat)
|
|
|
+ .isPrimaryKey(false)
|
|
|
+ .build();
|
|
|
+ CreateCollectionReq.FieldSchema fieldJson=CreateCollectionReq.FieldSchema.builder()
|
|
|
+ .dataType(DataType.JSON)
|
|
|
+ .name(CommonData.fieldJson)
|
|
|
+ .isPrimaryKey(false)
|
|
|
+ .build();
|
|
|
+ CreateCollectionReq.FieldSchema fieldFloatVector=CreateCollectionReq.FieldSchema.builder()
|
|
|
+ .dataType(DataType.FloatVector)
|
|
|
+ .name(CommonData.fieldFloatVector)
|
|
|
+ .isPrimaryKey(false)
|
|
|
+ .dimension(CommonData.dim)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ List<CreateCollectionReq.FieldSchema> fieldSchemaList=new ArrayList<>();
|
|
|
+ fieldSchemaList.add(fieldInt64);
|
|
|
+ fieldSchemaList.add(fieldInt32);
|
|
|
+ fieldSchemaList.add(fieldInt16);
|
|
|
+ fieldSchemaList.add(fieldInt8);
|
|
|
+ fieldSchemaList.add(fieldFloat);
|
|
|
+ fieldSchemaList.add(fieldDouble);
|
|
|
+ fieldSchemaList.add(fieldArray);
|
|
|
+ fieldSchemaList.add(fieldBool);
|
|
|
+ fieldSchemaList.add(fieldJson);
|
|
|
+ fieldSchemaList.add(fieldVarchar);
|
|
|
+ fieldSchemaList.add(fieldFloatVector);
|
|
|
+ CreateCollectionReq.CollectionSchema collectionSchema= CreateCollectionReq.CollectionSchema.builder()
|
|
|
+ .fieldSchemaList(fieldSchemaList)
|
|
|
+ .build();
|
|
|
+ IndexParam indexParam = IndexParam.builder()
|
|
|
+ .fieldName(CommonData.fieldFloatVector)
|
|
|
+ .indexType(IndexParam.IndexType.AUTOINDEX)
|
|
|
+ .extraParams(CommonFunction.provideExtraParam(IndexParam.IndexType.AUTOINDEX))
|
|
|
+ .metricType(IndexParam.MetricType.L2)
|
|
|
+ .build();
|
|
|
+ CreateCollectionReq createCollectionReq = CreateCollectionReq.builder()
|
|
|
+ .collectionSchema(collectionSchema)
|
|
|
+ .collectionName(collectionNameWithIndex)
|
|
|
+ .enableDynamicField(false)
|
|
|
+ .indexParams(Collections.singletonList(indexParam))
|
|
|
+ .numShards(1)
|
|
|
+ .build();
|
|
|
+ BaseTest.milvusClientV2.createCollection(createCollectionReq);
|
|
|
+
|
|
|
+ ListCollectionsResp listCollectionsResp = milvusClientV2.listCollections();
|
|
|
+ Assert.assertTrue(listCollectionsResp.getCollectionNames().contains(collectionNameWithIndex));
|
|
|
+ //insert
|
|
|
+ CommonFunction.generateDefaultData(100,CommonData.dim);
|
|
|
+ // search
|
|
|
+ SearchResp searchResp = CommonFunction.defaultSearch(collectionNameWithIndex);
|
|
|
+ Assert.assertEquals(searchResp.getSearchResults().size(),10);
|
|
|
+ }
|
|
|
+
|
|
|
}
|