Skip to content

Commit

Permalink
Fix unitest failure (#424)
Browse files Browse the repository at this point in the history
Signed-off-by: groot <[email protected]>
  • Loading branch information
yhmo authored Jan 4, 2023
1 parent 3cfb3be commit 917ba1c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/main/java/io/milvus/param/ParamUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.milvus.param;

import com.google.protobuf.ByteString;
import io.grpc.StatusRuntimeException;
import io.milvus.common.clientenum.ConsistencyLevelEnum;
import io.milvus.common.utils.JacksonUtils;
import io.milvus.exception.IllegalResponseException;
Expand Down Expand Up @@ -293,6 +294,7 @@ public static SearchRequest convertSearchParam(@NonNull SearchParam requestParam
.build());

if (null != requestParam.getParams() && !requestParam.getParams().isEmpty()) {
try {
Map<String, Object> paramMap = JacksonUtils.fromJson(requestParam.getParams(),Map.class);
String offset = paramMap.getOrDefault(Constant.OFFSET, 0).toString();
builder.addSearchParams(
Expand All @@ -305,6 +307,9 @@ public static SearchRequest convertSearchParam(@NonNull SearchParam requestParam
.setKey(Constant.PARAMS)
.setValue(requestParam.getParams())
.build());
} catch (IllegalArgumentException e) {
throw new ParamException(e.getMessage() + e.getCause().getMessage());
}
}

if (!requestParam.getOutFields().isEmpty()) {
Expand Down
48 changes: 31 additions & 17 deletions src/test/java/io/milvus/client/MilvusServiceClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,7 @@ void searchParam() {
.withCollectionName("collection1")
.withPartitionNames(partitions)
.addPartitionName("p2")
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.IP)
Expand All @@ -1777,7 +1777,7 @@ void searchParam() {
.withCollectionName("collection1")
.withPartitionNames(partitions)
.addPartitionName("p2")
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.IP)
Expand All @@ -1793,7 +1793,7 @@ void searchParam() {
.withCollectionName("collection1")
.withPartitionNames(partitions)
.addPartitionName("p2")
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.IP)
Expand All @@ -1810,7 +1810,7 @@ void searchParam() {
assertThrows(ParamException.class, () -> SearchParam.newBuilder()
.withCollectionName("")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.IP)
Expand All @@ -1824,7 +1824,7 @@ void searchParam() {
assertThrows(ParamException.class, () -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("")
.withMetricType(MetricType.IP)
Expand All @@ -1838,7 +1838,7 @@ void searchParam() {
assertThrows(ParamException.class, () -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.INVALID)
Expand All @@ -1852,7 +1852,7 @@ void searchParam() {
assertThrows(ParamException.class, () -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.IP)
Expand All @@ -1867,7 +1867,7 @@ void searchParam() {
assertThrows(ParamException.class, () -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.IP)
Expand All @@ -1882,7 +1882,7 @@ void searchParam() {
assertThrows(ParamException.class, () -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.IP)
Expand All @@ -1898,7 +1898,7 @@ void searchParam() {
assertThrows(ParamException.class, () -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.IP)
Expand All @@ -1918,7 +1918,7 @@ void searchParam() {
assertThrows(ParamException.class, () -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.HAMMING)
Expand All @@ -1933,7 +1933,7 @@ void searchParam() {
assertThrows(ParamException.class, () -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.JACCARD)
Expand All @@ -1948,7 +1948,7 @@ void searchParam() {
assertThrows(ParamException.class, () -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.IP)
Expand All @@ -1962,7 +1962,7 @@ void searchParam() {
assertDoesNotThrow(() -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.L2)
Expand All @@ -1976,7 +1976,7 @@ void searchParam() {
assertDoesNotThrow(() -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.HAMMING)
Expand All @@ -1985,6 +1985,20 @@ void searchParam() {
.withExpr("dummy")
.build()
);

// param is not json format
assertDoesNotThrow(() -> SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.L2)
.withTopK(5)
.withVectors(vectors2)
.withExpr("dummy")
.build()
);
}

@Test
Expand All @@ -1998,7 +2012,7 @@ void search() {
SearchParam param = SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.addOutField("f2")
.withVectorFieldName("field1")
Expand All @@ -2020,7 +2034,7 @@ void search() {
param = SearchParam.newBuilder()
.withCollectionName("collection1")
.withPartitionNames(partitions)
.withParams("dummy")
.withParams("{}")
.withOutFields(outputFields)
.withVectorFieldName("field1")
.withMetricType(MetricType.HAMMING)
Expand Down

0 comments on commit 917ba1c

Please sign in to comment.