Browse Source

Simplify `listPartitions`

jianghua 4 years ago
parent
commit
7c8da75c85

+ 2 - 4
src/main/java/io/milvus/client/MilvusClient.java

@@ -167,11 +167,9 @@ public interface MilvusClient {
    * Lists current partitions of a collection
    * Lists current partitions of a collection
    *
    *
    * @param collectionName collection name
    * @param collectionName collection name
-   * @return <code>ListPartitionsResponse</code>
-   * @see ListPartitionsResponse
-   * @see Response
+   * @return a list of partition names
    */
    */
-  ListPartitionsResponse listPartitions(String collectionName);
+  List<String> listPartitions(String collectionName);
 
 
   /**
   /**
    * Drops partition specified by <code>collectionName</code> and <code>tag</code>
    * Drops partition specified by <code>collectionName</code> and <code>tag</code>

+ 7 - 34
src/main/java/io/milvus/client/MilvusGrpcClient.java

@@ -305,40 +305,13 @@ abstract class AbstractMilvusGrpcClient implements MilvusClient {
   }
   }
 
 
   @Override
   @Override
-  public ListPartitionsResponse listPartitions(String collectionName) {
-
-    if (!maybeAvailable()) {
-      logWarning("You are not connected to Milvus server");
-      return new ListPartitionsResponse(
-          new Response(Response.Status.CLIENT_NOT_CONNECTED), Collections.emptyList());
-    }
-
-    CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
-    PartitionList response;
-
-    try {
-      response = blockingStub().showPartitions(request);
-
-      if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo(
-            "Current partitions of collection {}: {}",
-            collectionName,
-            response.getPartitionTagArrayList());
-        return new ListPartitionsResponse(
-            new Response(Response.Status.SUCCESS), response.getPartitionTagArrayList());
-      } else {
-        logError("List partitions failed:\n{}", response.toString());
-        return new ListPartitionsResponse(
-            new Response(
-                Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
-                response.getStatus().getReason()),
-            Collections.emptyList());
-      }
-    } catch (StatusRuntimeException e) {
-      logError("listPartitions RPC failed:\n{}", e.getStatus().toString());
-      return new ListPartitionsResponse(
-          new Response(Response.Status.RPC_ERROR, e.toString()), Collections.emptyList());
-    }
+  public List<String> listPartitions(String collectionName) {
+    return translateExceptions(() -> {
+      CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
+      PartitionList response = blockingStub().showPartitions(request);
+      checkResponseStatus(response.getStatus());
+      return response.getPartitionTagArrayList();
+    });
   }
   }
 
 
   @Override
   @Override

+ 2 - 3
src/test/java/io/milvus/client/MilvusGrpcClientTest.java

@@ -361,9 +361,8 @@ class MilvusClientTest {
     final String tag2 = "tag2";
     final String tag2 = "tag2";
     client.createPartition(randomCollectionName, tag2);
     client.createPartition(randomCollectionName, tag2);
 
 
-    ListPartitionsResponse listPartitionsResponse = client.listPartitions(randomCollectionName);
-    assertTrue(listPartitionsResponse.ok());
-    assertEquals(3, listPartitionsResponse.getPartitionList().size()); // two tags plus _default
+    List<String> partitionList = client.listPartitions(randomCollectionName);
+    assertEquals(3, partitionList.size()); // two tags plus _default
 
 
     List<Long> intValues = new ArrayList<>(size);
     List<Long> intValues = new ArrayList<>(size);
     List<Float> floatValues = new ArrayList<>(size);
     List<Float> floatValues = new ArrayList<>(size);