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

add testcases with array field (#685) #686

Merged
merged 1 commit into from
Oct 25, 2023
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.zilliz.milvustest.common;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.zilliz.milvustest.entity.FileBody;
import com.zilliz.milvustest.entity.MilvusEntity;
import com.zilliz.milvustest.util.MathUtil;
Expand Down Expand Up @@ -574,10 +575,10 @@ public static String createNewCollectionWithJSONField() {
.withName("json_field")
.withDataType(DataType.JSON)
.build();
FieldType fieldType7 = FieldType.newBuilder()
.withName("array_field")
.withDataType(DataType.Array)
.build();
// FieldType fieldType7 = FieldType.newBuilder()
// .withName("array_field")
// .withDataType(DataType.Array)
// .build();
CreateCollectionParam createCollectionReq =
CreateCollectionParam.newBuilder()
.withCollectionName(collectionName)
Expand All @@ -596,6 +597,61 @@ public static String createNewCollectionWithJSONField() {
return collectionName;
}

public static String createNewCollectionWithArrayField(){
String collectionName = "Collection_" + MathUtil.getRandomString(10);
FieldType fieldType1 =
FieldType.newBuilder()
.withName("int64_field")
.withDataType(DataType.Int64)
.withPrimaryKey(true)
.withAutoID(false)
.build();
FieldType fieldType2 =
FieldType.newBuilder()
.withName("float_vector")
.withDataType(DataType.FloatVector)
.withDimension(128)
.build();
FieldType fieldType3=
FieldType.newBuilder()
.withName("str_array_field")
.withDataType(DataType.Array)
.withElementType(DataType.VarChar)
.withMaxLength(256)
.withMaxCapacity(300)
.build();
FieldType fieldType4=
FieldType.newBuilder()
.withName("int_array_field")
.withDataType(DataType.Array)
.withElementType(DataType.Int64)
.withMaxLength(256)
.withMaxCapacity(300)
.build();
FieldType fieldType5=
FieldType.newBuilder()
.withName("float_array_field")
.withDataType(DataType.Array)
.withElementType(DataType.Float)
.withMaxLength(256)
.withMaxCapacity(300)
.build();
CreateCollectionParam createCollectionReq =
CreateCollectionParam.newBuilder()
.withCollectionName(collectionName)
.withDescription("Test" + collectionName + "search")
.withShardsNum(2)
.addFieldType(fieldType1)
.addFieldType(fieldType2)
.addFieldType(fieldType3)
.addFieldType(fieldType4)
.addFieldType(fieldType5)
.build();
R<RpcStatus> collection = milvusClient.createCollection(createCollectionReq);
logger.info("create collection:" + collectionName);
return collectionName;
}

public static List<JSONObject> generateJsonData(int num){
List<JSONObject> jsonList=new ArrayList<>();
Random ran = new Random();
Expand Down Expand Up @@ -637,6 +693,24 @@ public static List<JSONObject> generateJsonData(int num){
return jsonList;
}

public static List<JSONObject> generateJsonDataWithArrayField(int num){
List<JSONObject> jsonList=new ArrayList<>();
Random ran = new Random();
for (int i = 0; i < num; i++) {
JSONObject row=new JSONObject();
row.put("int64_field",(long)i);
List<Float> vector=new ArrayList<>();
for (int k = 0; k < 128; ++k) {
vector.add(ran.nextFloat());
}
row.put("float_vector",vector);
row.put("str_array_field", Lists.newArrayList("str"+i,"str"+(i+1),"str"+(i+2)));
row.put("int_array_field",Lists.newArrayList((long)i,(long)(i+1),(long)(i+2)));
row.put("float_array_field",Lists.newArrayList((float)(i+0.1),(float)(i+0.2),(float)(i+0.2)));
jsonList.add(row);
}
return jsonList;
}
public static List<InsertParam.Field> generateDataWithDynamicFiledColumn(int num) {
Random ran = new Random();
List<Long> book_id_array = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class CreateCollectionTest extends BaseTest {
public String stringPKCollection;
public String maxFieldCollection;

public String arrayFieldCollection;

@DataProvider(name = "collectionByDataProvider")
public Object[][] provideCollectionName() {
return new String[][] {{"collection_" + MathUtil.getRandomString(10)}};
Expand All @@ -54,6 +56,10 @@ public void deleteTestData() {
milvusClient.dropCollection(
DropCollectionParam.newBuilder().withCollectionName(maxFieldCollection).build());
}
if (arrayFieldCollection != null) {
milvusClient.dropCollection(
DropCollectionParam.newBuilder().withCollectionName(arrayFieldCollection).build());
}
}

@DataProvider(name = "dataTypeProvider")
Expand Down Expand Up @@ -482,4 +488,61 @@ public void createCollectionWithMultiThread() {
});
}

@Severity(SeverityLevel.BLOCKER)
@Test(description = "Create collection with array fields")
public void createCollectionWithArrayField(){
arrayFieldCollection = "Collection_" + MathUtil.getRandomString(10);
FieldType fieldType1 =
FieldType.newBuilder()
.withName("int64_field")
.withDataType(DataType.Int64)
.withPrimaryKey(true)
.withAutoID(false)
.build();
FieldType fieldType2 =
FieldType.newBuilder()
.withName("float_vector")
.withDataType(DataType.FloatVector)
.withDimension(128)
.build();
FieldType fieldType3=
FieldType.newBuilder()
.withName("str_array_field")
.withDataType(DataType.Array)
.withElementType(DataType.VarChar)
.withMaxLength(256)
.withMaxCapacity(300)
.build();
FieldType fieldType4=
FieldType.newBuilder()
.withName("int_array_field")
.withDataType(DataType.Array)
.withElementType(DataType.Int64)
.withMaxLength(256)
.withMaxCapacity(300)
.build();
FieldType fieldType5=
FieldType.newBuilder()
.withName("float_array_field")
.withDataType(DataType.Array)
.withElementType(DataType.Float)
.withMaxLength(256)
.withMaxCapacity(300)
.build();
CreateCollectionParam createCollectionReq =
CreateCollectionParam.newBuilder()
.withCollectionName(arrayFieldCollection)
.withDescription("Test" + arrayFieldCollection + "search")
.withShardsNum(2)
.addFieldType(fieldType1)
.addFieldType(fieldType2)
.addFieldType(fieldType3)
.addFieldType(fieldType4)
.addFieldType(fieldType5)
.build();
R<RpcStatus> collection = milvusClient.createCollection(createCollectionReq);
Assert.assertEquals(collection.getStatus().toString(), "0");
Assert.assertEquals(collection.getData().getMsg(), "Success");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Object[][] providerSegmentId() {
@Test(description = "Get flush state of specified segments.", dataProvider = "providerSegmentIds",groups = {"Smoke"})
public void getFlushStateTest(Long segmentId, String collection) {
R<GetFlushStateResponse> getFlushStateResponseR =
milvusClient.getFlushState(GetFlushStateParam.newBuilder().addSegmentID(segmentId).build());
milvusClient.getFlushState(GetFlushStateParam.newBuilder().withCollectionName(collection).build());
Assert.assertEquals(getFlushStateResponseR.getStatus().intValue(), 0);
Assert.assertTrue(getFlushStateResponseR.getData().getFlushed());
System.out.println("Collection-" + collection + ":" + getFlushStateResponseR.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import io.milvus.param.collection.ReleaseCollectionParam;
import io.milvus.param.index.CreateIndexParam;
import io.milvus.param.index.DropIndexParam;
import io.qameta.allure.Issue;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.*;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
Expand All @@ -23,6 +21,8 @@

import static com.zilliz.milvustest.util.MathUtil.combine;

@Epic("Index")
@Feature("IndexLoad")
public class IndexLoadTest extends BaseTest {
public String collection;
public String binaryCollection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class QueryTest extends BaseTest {
public String collectionWithJsonField;
public String collectionWithDynamicField;

public String collectionWithArrayField;

@BeforeClass(description = "load collection first",alwaysRun = true)
public void loadCollection() {
milvusClient.loadCollection(
Expand All @@ -65,6 +67,7 @@ public void loadCollection() {
.build());
collectionWithJsonField= CommonFunction.createNewCollectionWithJSONField();
collectionWithDynamicField= CommonFunction.createNewCollectionWithDynamicField();
collectionWithArrayField= CommonFunction.createNewCollectionWithArrayField();
}

@DataProvider(name = "providerPartition")
Expand Down Expand Up @@ -94,6 +97,8 @@ public void releaseCollection() {
DropCollectionParam.newBuilder().withCollectionName(collectionWithJsonField).build());
milvusClient.dropCollection(
DropCollectionParam.newBuilder().withCollectionName(collectionWithDynamicField).build());
milvusClient.dropCollection(
DropCollectionParam.newBuilder().withCollectionName(collectionWithArrayField).build());
}

@DataProvider(name = "providerConsistency")
Expand Down Expand Up @@ -1113,6 +1118,31 @@ public void queryCollectionWithJsonField(String expr) {
JSONObject jsonObject = (JSONObject) wrapperQuery.getRowRecords().get(0).get("json_field");
String string_field = jsonObject.getString("string_field");
Assert.assertTrue(string_field.contains("Str"));
}

@Test(description = "query collection with array field",groups = {"Smoke"})
@Severity(SeverityLevel.BLOCKER)
public void queryCollectionWithArrayField() {
List<JSONObject> jsonObjects = CommonFunction.generateJsonDataWithArrayField(1000);
R<MutationResult> insert = milvusClient.insert(InsertParam.newBuilder()
.withRows(jsonObjects)
.withCollectionName(collectionWithArrayField)
.build());
Assert.assertEquals(insert.getStatus().intValue(),0);
CommonFunction.createIndexWithLoad(collectionWithArrayField,IndexType.HNSW,MetricType.L2,"float_vector");
//query
List<String> outFields = Arrays.asList("str_array_field","int_array_field","float_array_field");
QueryParam queryParam =
QueryParam.newBuilder()
.withCollectionName(collectionWithArrayField)
.withOutFields(outFields)
// .withExpr(expr)
.withLimit(100L)
.build();
R<QueryResults> queryResultsR = milvusClient.query(queryParam);
QueryResultsWrapper wrapperQuery = new QueryResultsWrapper(queryResultsR.getData());
Assert.assertEquals(queryResultsR.getStatus().intValue(), 0);
Assert.assertTrue(wrapperQuery.getFieldWrapper("str_array_field").getFieldData().size()>=4);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class SearchTest extends BaseTest {
public String collectionWithJsonField;
public String collectionWithDynamicField;

public String collectionWithArrayField;

@BeforeClass(description = "load collection first",alwaysRun = true)
public void loadCollection() {
milvusClient.loadCollection(
Expand All @@ -63,6 +65,7 @@ public void loadCollection() {
.build());
collectionWithJsonField= CommonFunction.createNewCollectionWithJSONField();
collectionWithDynamicField= CommonFunction.createNewCollectionWithDynamicField();
collectionWithArrayField= CommonFunction.createNewCollectionWithArrayField();
}

@DataProvider(name="dynamicExpressions")
Expand Down Expand Up @@ -106,6 +109,8 @@ public void releaseCollection() {
DropCollectionParam.newBuilder().withCollectionName(collectionWithJsonField).build());
milvusClient.dropCollection(
DropCollectionParam.newBuilder().withCollectionName(collectionWithDynamicField).build());
milvusClient.dropCollection(
DropCollectionParam.newBuilder().withCollectionName(collectionWithArrayField).build());

}

Expand Down Expand Up @@ -1919,4 +1924,38 @@ public void searchReturnVector(IndexType indexType, MetricType metricType) {
milvusClient.dropCollection(
DropCollectionParam.newBuilder().withCollectionName(newCollection).build());
}

@Severity(SeverityLevel.BLOCKER)
@Test(description = "Search with array field",groups = {"Smoke"})
public void searchWithArrayField(){
List<JSONObject> jsonObjects = CommonFunction.generateJsonDataWithArrayField(1000);
R<MutationResult> insert = milvusClient.insert(InsertParam.newBuilder()
.withRows(jsonObjects)
.withCollectionName(collectionWithArrayField)
.build());
Assert.assertEquals(insert.getStatus().intValue(), 0);
CommonFunction.createIndexWithLoad(collectionWithArrayField, IndexType.HNSW, MetricType.L2, "float_vector");
// search
Integer SEARCH_K = 10; // TopK
String SEARCH_PARAM = "{\"nprobe\":10}";
List<String> search_output_fields = Arrays.asList("str_array_field","int_array_field","float_array_field");
List<List<Float>> search_vectors = Arrays.asList(Arrays.asList(MathUtil.generateFloat(128)));
SearchParam searchParam =
SearchParam.newBuilder()
.withCollectionName(collectionWithArrayField)
.withMetricType(MetricType.L2)
.withOutFields(search_output_fields)
.withTopK(SEARCH_K)
.withVectors(search_vectors)
.withVectorFieldName("float_vector")
.withParams(SEARCH_PARAM)
// .withExpr(expr)
.withConsistencyLevel(ConsistencyLevelEnum.STRONG)
.build();
R<SearchResults> searchResultsR = milvusClient.search(searchParam);
Assert.assertEquals(searchResultsR.getStatus().intValue(), 0);
SearchResultsWrapper searchResultsWrapper =
new SearchResultsWrapper(searchResultsR.getData().getResults());
Assert.assertTrue(searchResultsWrapper.getFieldData("str_array_field", 0).size()>=4);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,13 @@ public void listVarcharPKCollectionTest() {

@Severity(SeverityLevel.BLOCKER)
@Test(description = "insert data into varchar PK Collection", groups = {"Smoke"}, dependsOnMethods = "listVarcharPKCollectionTest")
public void insertIntoVarcharPKCollectionTest() {
public void insertIntoVarcharPKCollectionTest() throws InterruptedException {
List<JSONObject> jsonObjects = CommonFunction.generateVarcharPKDataWithDynamicFiledRow(10000);
R<InsertResponse> insert = milvusClient.insert(InsertRowsParam.newBuilder()
.withCollectionName(varcharPKCollection)
.withRows(jsonObjects)
.build());
Thread.sleep(2000);
Assert.assertEquals(insert.getStatus().intValue(), R.Status.Success.getCode());
Assert.assertEquals(insert.getData().getInsertCount().intValue(), 10000);
}
Expand Down