Browse Source

Query failed when collection is empty or improper expression (#319)

Signed-off-by: yhmo <yihua.mo@zilliz.com>
groot 2 years ago
parent
commit
1410e04c71

+ 1 - 1
docker-compose.yml

@@ -31,7 +31,7 @@ services:
 
   standalone:
     container_name: milvus-javasdk-test-standalone
-    image: milvusdb/milvus-dev:2.1.0-20220701-1e8e164a
+    image: milvusdb/milvus-dev:2.1.0-20220704-f6ce0559
     command: ["milvus", "run", "standalone"]
     environment:
       ETCD_ENDPOINTS: etcd:2379

+ 7 - 1
src/main/java/io/milvus/client/AbstractMilvusGrpcClient.java

@@ -1482,11 +1482,17 @@ public abstract class AbstractMilvusGrpcClient implements MilvusClient {
         try {
             QueryRequest queryRequest = ParamUtils.ConvertQueryParam(requestParam);
             QueryResults response = this.blockingStub().query(queryRequest);
-
             if (response.getStatus().getErrorCode() == ErrorCode.Success) {
                 logInfo("QueryRequest successfully!");
                 return R.success(response);
             } else {
+                // Server side behavior: if a query expression could not filter out any result,
+                // or collection is empty, the server return ErrorCode.EmptyCollection.
+                // Here we give a general message for this case.
+                if (response.getStatus().getErrorCode() == ErrorCode.EmptyCollection) {
+                    logError("QueryRequest returns nothing: empty collection or improper expression");
+                    return R.failed(ErrorCode.EmptyCollection, "empty collection or improper expression");
+                }
                 return failedStatus("QueryRequest", response.getStatus());
             }
         } catch (StatusRuntimeException e) {

+ 1 - 1
src/test/java/io/milvus/client/MilvusClientDockerTest.java

@@ -372,7 +372,7 @@ class MilvusClientDockerTest {
             compareWeights.add(weights.get(i));
         }
         String expr = field1Name + " in " + queryIDs.toString();
-        List<String> outputFields = Arrays.asList(field1Name, field2Name, field3Name, field4Name, field4Name);
+        List<String> outputFields = Arrays.asList(field1Name, field2Name, field3Name, field4Name, field5Name);
         QueryParam queryParam = QueryParam.newBuilder()
                 .withCollectionName(randomCollectionName)
                 .withExpr(expr)