Browse Source

Merge pull request #111 from sahuang/master

Use google-java-format
Xiaohai Xu 4 years ago
parent
commit
3c758fae5a

+ 2 - 5
examples/src/main/java/MilvusClientExample.java

@@ -20,7 +20,6 @@
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.gson.JsonObject;
 import io.milvus.client.*;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.SplittableRandom;
@@ -98,8 +97,7 @@ public class MilvusClientExample {
     HasCollectionResponse hasCollectionResponse = client.hasCollection(collectionName);
 
     // Get collection info
-    GetCollectionInfoResponse getCollectionInfoResponse =
-        client.getCollectionInfo(collectionName);
+    GetCollectionInfoResponse getCollectionInfoResponse = client.getCollectionInfo(collectionName);
 
     // Insert randomly generated vectors to collection
     final int vectorCount = 100000;
@@ -117,8 +115,7 @@ public class MilvusClientExample {
     Response flushResponse = client.flush(collectionName);
 
     // Get current entity count of collection
-    CountEntitiesResponse ountEntitiesResponse =
-        client.countEntities(collectionName);
+    CountEntitiesResponse ountEntitiesResponse = client.countEntities(collectionName);
 
     // Create index for the collection
     // We choose IVF_SQ8 as our index type here. Refer to IndexType javadoc for a

+ 7 - 8
src/main/java/io/milvus/client/GetEntityByIDResponse.java

@@ -4,16 +4,18 @@ import java.nio.ByteBuffer;
 import java.util.List;
 
 /**
- * Contains the returned <code>response</code> and either a <code>List</code> of <code>floatVectors</code> or <code>
- * binaryVectors</code> for <code>getEntityByID</code>. If the id does not exist, both float and binary
- * vectors corresponding to the id will be empty.
+ * Contains the returned <code>response</code> and either a <code>List</code> of <code>floatVectors
+ * </code> or <code>
+ * binaryVectors</code> for <code>getEntityByID</code>. If the id does not exist, both float and
+ * binary vectors corresponding to the id will be empty.
  */
 public class GetEntityByIDResponse {
   private final Response response;
   private final List<List<Float>> floatVectors;
   private final List<ByteBuffer> binaryVectors;
 
-  GetEntityByIDResponse(Response response, List<List<Float>> floatVectors, List<ByteBuffer> binaryVectors) {
+  GetEntityByIDResponse(
+      Response response, List<List<Float>> floatVectors, List<ByteBuffer> binaryVectors) {
     this.response = response;
     this.floatVectors = floatVectors;
     this.binaryVectors = binaryVectors;
@@ -23,9 +25,7 @@ public class GetEntityByIDResponse {
     return floatVectors;
   }
 
-  /**
-   * @return a <code>List</code> of <code>ByteBuffer</code> object
-   */
+  /** @return a <code>List</code> of <code>ByteBuffer</code> object */
   public List<ByteBuffer> getBinaryVectors() {
     return binaryVectors;
   }
@@ -38,5 +38,4 @@ public class GetEntityByIDResponse {
   public boolean ok() {
     return response.ok();
   }
-
 }

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

@@ -20,7 +20,6 @@
 package io.milvus.client;
 
 import com.google.common.util.concurrent.ListenableFuture;
-
 import java.util.List;
 
 /** The Milvus Client Interface */
@@ -373,8 +372,8 @@ public interface MilvusClient {
   /**
    * Shows collection information. A collection consists of one or multiple partitions (including
    * the default partition), and a partitions consists of one or more segments. Each partition or
-   * segment can be uniquely identified by its partition tag or segment name respectively.
-   * The result will be returned as JSON string.
+   * segment can be uniquely identified by its partition tag or segment name respectively. The
+   * result will be returned as JSON string.
    *
    * @param collectionName collection to show info from
    * @return <code>Response</code>

+ 60 - 42
src/main/java/io/milvus/client/MilvusGrpcClient.java

@@ -29,14 +29,13 @@ import io.grpc.ManagedChannel;
 import io.grpc.ManagedChannelBuilder;
 import io.grpc.StatusRuntimeException;
 import io.milvus.grpc.*;
-
-import javax.annotation.Nonnull;
 import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
+import javax.annotation.Nonnull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -96,7 +95,8 @@ public class MilvusGrpcClient implements MilvusClient {
       // check server version
       String serverVersion = getServerVersion().getMessage();
       if (!serverVersion.contains("0.10.")) {
-        logError("Connect failed! Server version {} does not match SDK version 0.8.2", serverVersion);
+        logError(
+            "Connect failed! Server version {} does not match SDK version 0.8.2", serverVersion);
         throw new ConnectFailedException("Failed to connect to Milvus server.");
       }
 
@@ -109,7 +109,8 @@ public class MilvusGrpcClient implements MilvusClient {
 
     logInfo(
         "Connection established successfully to host={}, port={}",
-        connectParam.getHost(), String.valueOf(connectParam.getPort()));
+        connectParam.getHost(),
+        String.valueOf(connectParam.getPort()));
     return new Response(Response.Status.SUCCESS);
   }
 
@@ -173,8 +174,7 @@ public class MilvusGrpcClient implements MilvusClient {
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       } else {
         logError(
-            "Create collection failed\n{}\n{}",
-            collectionMapping.toString(), response.toString());
+            "Create collection failed\n{}\n{}", collectionMapping.toString(), response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
@@ -347,7 +347,9 @@ public class MilvusGrpcClient implements MilvusClient {
       } else {
         logError(
             "Create partition `{}` in collection `{}` failed: {}",
-            tag, collectionName, response.toString());
+            tag,
+            collectionName,
+            response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
@@ -373,21 +375,28 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.hasPartition(request);
 
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("hasPartition with tag `{}` in `{}` = {}", tag, collectionName, response.getBoolReply());
+        logInfo(
+            "hasPartition with tag `{}` in `{}` = {}",
+            tag,
+            collectionName,
+            response.getBoolReply());
         return new HasPartitionResponse(
-                new Response(Response.Status.SUCCESS), response.getBoolReply());
+            new Response(Response.Status.SUCCESS), response.getBoolReply());
       } else {
-        logError("hasPartition with tag `{}` in `{}` failed:\n{}", tag, collectionName, response.toString());
+        logError(
+            "hasPartition with tag `{}` in `{}` failed:\n{}",
+            tag,
+            collectionName,
+            response.toString());
         return new HasPartitionResponse(
-                new Response(
-                        Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
-                        response.getStatus().getReason()),
-                false);
+            new Response(
+                Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
+                response.getStatus().getReason()),
+            false);
       }
     } catch (StatusRuntimeException e) {
       logError("hasPartition RPC failed:\n{}", e.getStatus().toString());
-      return new HasPartitionResponse(
-              new Response(Response.Status.RPC_ERROR, e.toString()), false);
+      return new HasPartitionResponse(new Response(Response.Status.RPC_ERROR, e.toString()), false);
     }
   }
 
@@ -409,7 +418,8 @@ public class MilvusGrpcClient implements MilvusClient {
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
         logInfo(
             "Current partitions of collection {}: {}",
-            collectionName, response.getPartitionTagArrayList());
+            collectionName,
+            response.getPartitionTagArrayList());
         return new ListPartitionsResponse(
             new Response(Response.Status.SUCCESS), response.getPartitionTagArrayList());
       } else {
@@ -448,7 +458,9 @@ public class MilvusGrpcClient implements MilvusClient {
       } else {
         logError(
             "Drop partition `{}` in collection `{}` failed:\n{}",
-            tag, collectionName, response.toString());
+            tag,
+            collectionName,
+            response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
@@ -485,7 +497,8 @@ public class MilvusGrpcClient implements MilvusClient {
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
         logInfo(
             "Inserted {} vectors to collection `{}` successfully!",
-            response.getVectorIdArrayCount(), insertParam.getCollectionName());
+            response.getVectorIdArrayCount(),
+            insertParam.getCollectionName());
         return new InsertResponse(
             new Response(Response.Status.SUCCESS), response.getVectorIdArrayList());
       } else {
@@ -536,7 +549,8 @@ public class MilvusGrpcClient implements MilvusClient {
             if (result.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
               logInfo(
                   "Inserted {} vectors to collection `{}` successfully!",
-                  result.getVectorIdArrayCount(), insertParam.getCollectionName());
+                  result.getVectorIdArrayCount(),
+                  insertParam.getCollectionName());
             } else {
               logError("InsertAsync failed:\n{}", result.getStatus().toString());
             }
@@ -722,7 +736,8 @@ public class MilvusGrpcClient implements MilvusClient {
       } else {
         logError(
             "Get Collection Info `{}` failed:\n{}",
-            collectionName, response.getStatus().toString());
+            collectionName,
+            response.getStatus().toString());
         return new GetCollectionInfoResponse(
             new Response(
                 Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
@@ -775,8 +790,7 @@ public class MilvusGrpcClient implements MilvusClient {
 
     if (!channelIsReadyOrIdle()) {
       logWarning("You are not connected to Milvus server");
-      return new CountEntitiesResponse(
-          new Response(Response.Status.CLIENT_NOT_CONNECTED), 0);
+      return new CountEntitiesResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), 0);
     }
 
     CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
@@ -788,12 +802,12 @@ public class MilvusGrpcClient implements MilvusClient {
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
         long collectionRowCount = response.getCollectionRowCount();
         logInfo("Collection `{}` has {} entities", collectionName, collectionRowCount);
-        return new CountEntitiesResponse(
-            new Response(Response.Status.SUCCESS), collectionRowCount);
+        return new CountEntitiesResponse(new Response(Response.Status.SUCCESS), collectionRowCount);
       } else {
         logError(
             "Get collection `{}` entity count failed:\n{}",
-            collectionName, response.getStatus().toString());
+            collectionName,
+            response.getStatus().toString());
         return new CountEntitiesResponse(
             new Response(
                 Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
@@ -802,8 +816,7 @@ public class MilvusGrpcClient implements MilvusClient {
       }
     } catch (StatusRuntimeException e) {
       logError("countEntities RPC failed:\n{}", e.getStatus().toString());
-      return new CountEntitiesResponse(
-          new Response(Response.Status.RPC_ERROR, e.toString()), 0);
+      return new CountEntitiesResponse(new Response(Response.Status.RPC_ERROR, e.toString()), 0);
     }
   }
 
@@ -895,7 +908,8 @@ public class MilvusGrpcClient implements MilvusClient {
           }
         }
         Index index =
-            new Index.Builder(response.getCollectionName(), IndexType.valueOf(response.getIndexType()))
+            new Index.Builder(
+                    response.getCollectionName(), IndexType.valueOf(response.getIndexType()))
                 .withParamsInJson(extraParam)
                 .build();
         logInfo(
@@ -904,7 +918,8 @@ public class MilvusGrpcClient implements MilvusClient {
       } else {
         logError(
             "Get index info for collection `{}` failed:\n{}",
-            collectionName, response.getStatus().toString());
+            collectionName,
+            response.getStatus().toString());
         return new GetIndexInfoResponse(
             new Response(
                 Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
@@ -935,8 +950,7 @@ public class MilvusGrpcClient implements MilvusClient {
         logInfo("Dropped index for collection `{}` successfully!", collectionName);
         return new Response(Response.Status.SUCCESS);
       } else {
-        logError(
-            "Drop index for collection `{}` failed:\n{}", collectionName, response.toString());
+        logError("Drop index for collection `{}` failed:\n{}", collectionName, response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
@@ -965,10 +979,11 @@ public class MilvusGrpcClient implements MilvusClient {
       } else {
         logError(
             "getCollectionStats for `{}` failed:\n{}",
-            collectionName, response.getStatus().toString());
+            collectionName,
+            response.getStatus().toString());
         return new Response(
-                Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
-                response.getStatus().getReason());
+            Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
+            response.getStatus().getReason());
       }
     } catch (StatusRuntimeException e) {
       logError("getCollectionStats RPC failed:\n{}", e.getStatus().toString());
@@ -981,7 +996,7 @@ public class MilvusGrpcClient implements MilvusClient {
     if (!channelIsReadyOrIdle()) {
       logWarning("You are not connected to Milvus server");
       return new GetEntityByIDResponse(
-              new Response(Response.Status.CLIENT_NOT_CONNECTED), new ArrayList<>(), null);
+          new Response(Response.Status.CLIENT_NOT_CONNECTED), new ArrayList<>(), null);
     }
 
     VectorsIdentity request =
@@ -993,8 +1008,7 @@ public class MilvusGrpcClient implements MilvusClient {
 
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
 
-        logInfo(
-            "getEntityByID in collection `{}` returned successfully!", collectionName);
+        logInfo("getEntityByID in collection `{}` returned successfully!", collectionName);
 
         List<List<Float>> floatVectors = new ArrayList<>();
         List<ByteBuffer> binaryVectors = new ArrayList<>();
@@ -1003,12 +1017,13 @@ public class MilvusGrpcClient implements MilvusClient {
           binaryVectors.add(response.getVectorsData(i).getBinaryData().asReadOnlyByteBuffer());
         }
         return new GetEntityByIDResponse(
-                new Response(Response.Status.SUCCESS), floatVectors, binaryVectors);
+            new Response(Response.Status.SUCCESS), floatVectors, binaryVectors);
 
       } else {
         logError(
             "getEntityByID in collection `{}` failed:\n{}",
-            collectionName, response.getStatus().toString());
+            collectionName,
+            response.getStatus().toString());
         return new GetEntityByIDResponse(
             new Response(
                 Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
@@ -1045,13 +1060,16 @@ public class MilvusGrpcClient implements MilvusClient {
 
         logInfo(
             "listIDInSegment in collection `{}`, segment `{}` returned successfully!",
-            collectionName, segmentName);
+            collectionName,
+            segmentName);
         return new ListIDInSegmentResponse(
             new Response(Response.Status.SUCCESS), response.getVectorIdArrayList());
       } else {
         logError(
             "listIDInSegment in collection `{}`, segment `{}` failed:\n{}",
-            collectionName, segmentName, response.getStatus().toString());
+            collectionName,
+            segmentName,
+            response.getStatus().toString());
         return new ListIDInSegmentResponse(
             new Response(
                 Response.Status.valueOf(response.getStatus().getErrorCodeValue()),

+ 1 - 1
src/main/java/io/milvus/client/SearchParam.java

@@ -19,10 +19,10 @@
 
 package io.milvus.client;
 
-import javax.annotation.Nonnull;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
+import javax.annotation.Nonnull;
 
 /** Contains parameters for <code>search</code> */
 public class SearchParam {

+ 28 - 27
src/test/java/io/milvus/client/MilvusGrpcClientTest.java

@@ -229,8 +229,7 @@ class MilvusClientTest {
 
     assertTrue(client.flush(randomCollectionName).ok());
 
-    assertEquals(
-        size * 2, client.countEntities(randomCollectionName).getCollectionEntityCount());
+    assertEquals(size * 2, client.countEntities(randomCollectionName).getCollectionEntityCount());
 
     final int searchSize = 1;
     final long topK = 10;
@@ -530,8 +529,7 @@ class MilvusClientTest {
     insert();
     assertTrue(client.flush(randomCollectionName).ok());
 
-    CountEntitiesResponse countEntitiesResponse =
-        client.countEntities(randomCollectionName);
+    CountEntitiesResponse countEntitiesResponse = client.countEntities(randomCollectionName);
     assertTrue(countEntitiesResponse.ok());
     assertEquals(size, countEntitiesResponse.getCollectionEntityCount());
   }
@@ -568,8 +566,7 @@ class MilvusClientTest {
 
     assertTrue(client.flush(randomCollectionName).ok());
 
-    Response getCollectionStatsResponse =
-        client.getCollectionStats(randomCollectionName);
+    Response getCollectionStatsResponse = client.getCollectionStats(randomCollectionName);
     assertTrue(getCollectionStatsResponse.ok());
 
     String jsonString = getCollectionStatsResponse.getMessage();
@@ -605,7 +602,8 @@ class MilvusClientTest {
     ByteBuffer bb = getEntityByIDResponse.getBinaryVectors().get(0);
     assertTrue(bb == null || bb.remaining() == 0);
 
-    assertArrayEquals(getEntityByIDResponse.getFloatVectors().get(0).toArray(), vectors.get(0).toArray());
+    assertArrayEquals(
+        getEntityByIDResponse.getFloatVectors().get(0).toArray(), vectors.get(0).toArray());
   }
 
   @org.junit.jupiter.api.Test
@@ -614,19 +612,19 @@ class MilvusClientTest {
 
     assertTrue(client.flush(randomCollectionName).ok());
 
-    Response getCollectionStatsResponse =
-        client.getCollectionStats(randomCollectionName);
+    Response getCollectionStatsResponse = client.getCollectionStats(randomCollectionName);
     assertTrue(getCollectionStatsResponse.ok());
 
     JSONObject jsonInfo = new JSONObject(getCollectionStatsResponse.getMessage());
-    JSONObject segmentInfo = jsonInfo
-                                 .getJSONArray("partitions")
-                                 .getJSONObject(0)
-                                 .getJSONArray("segments")
-                                 .getJSONObject(0);
+    JSONObject segmentInfo =
+        jsonInfo
+            .getJSONArray("partitions")
+            .getJSONObject(0)
+            .getJSONArray("segments")
+            .getJSONObject(0);
 
     ListIDInSegmentResponse listIDInSegmentResponse =
-        client.listIDInSegment(randomCollectionName,segmentInfo.getString("name"));
+        client.listIDInSegment(randomCollectionName, segmentInfo.getString("name"));
     assertTrue(listIDInSegmentResponse.ok());
     assertFalse(listIDInSegmentResponse.getIds().isEmpty());
   }
@@ -645,8 +643,7 @@ class MilvusClientTest {
 
     assertTrue(client.deleteEntityByID(randomCollectionName, vectorIds.subList(0, 100)).ok());
     assertTrue(client.flush(randomCollectionName).ok());
-    assertEquals(
-        client.countEntities(randomCollectionName).getCollectionEntityCount(), size - 100);
+    assertEquals(client.countEntities(randomCollectionName).getCollectionEntityCount(), size - 100);
   }
 
   @org.junit.jupiter.api.Test
@@ -671,12 +668,12 @@ class MilvusClientTest {
 
     assertTrue(client.flush(randomCollectionName).ok());
 
-    Response getCollectionStatsResponse =
-        client.getCollectionStats(randomCollectionName);
+    Response getCollectionStatsResponse = client.getCollectionStats(randomCollectionName);
     assertTrue(getCollectionStatsResponse.ok());
 
     JSONObject jsonInfo = new JSONObject(getCollectionStatsResponse.getMessage());
-    JSONObject segmentInfo = jsonInfo
+    JSONObject segmentInfo =
+        jsonInfo
             .getJSONArray("partitions")
             .getJSONObject(0)
             .getJSONArray("segments")
@@ -684,14 +681,16 @@ class MilvusClientTest {
 
     long previousSegmentSize = segmentInfo.getLong("data_size");
 
-    assertTrue(client.deleteEntityByID(randomCollectionName, vectorIds.subList(0, (int) size / 2)).ok());
+    assertTrue(
+        client.deleteEntityByID(randomCollectionName, vectorIds.subList(0, (int) size / 2)).ok());
     assertTrue(client.flush(randomCollectionName).ok());
     assertTrue(client.compact(randomCollectionName).ok());
 
     getCollectionStatsResponse = client.getCollectionStats(randomCollectionName);
     assertTrue(getCollectionStatsResponse.ok());
     jsonInfo = new JSONObject(getCollectionStatsResponse.getMessage());
-    segmentInfo = jsonInfo
+    segmentInfo =
+        jsonInfo
             .getJSONArray("partitions")
             .getJSONObject(0)
             .getJSONArray("segments")
@@ -713,12 +712,12 @@ class MilvusClientTest {
 
     assertTrue(client.flush(randomCollectionName).ok());
 
-    Response getCollectionStatsResponse =
-            client.getCollectionStats(randomCollectionName);
+    Response getCollectionStatsResponse = client.getCollectionStats(randomCollectionName);
     assertTrue(getCollectionStatsResponse.ok());
 
     JSONObject jsonInfo = new JSONObject(getCollectionStatsResponse.getMessage());
-    JSONObject segmentInfo = jsonInfo
+    JSONObject segmentInfo =
+        jsonInfo
             .getJSONArray("partitions")
             .getJSONObject(0)
             .getJSONArray("segments")
@@ -726,14 +725,16 @@ class MilvusClientTest {
 
     long previousSegmentSize = segmentInfo.getLong("data_size");
 
-    assertTrue(client.deleteEntityByID(randomCollectionName, vectorIds.subList(0, (int) size / 2)).ok());
+    assertTrue(
+        client.deleteEntityByID(randomCollectionName, vectorIds.subList(0, (int) size / 2)).ok());
     assertTrue(client.flush(randomCollectionName).ok());
     assertTrue(client.compactAsync(randomCollectionName).get().ok());
 
     getCollectionStatsResponse = client.getCollectionStats(randomCollectionName);
     assertTrue(getCollectionStatsResponse.ok());
     jsonInfo = new JSONObject(getCollectionStatsResponse.getMessage());
-    segmentInfo = jsonInfo
+    segmentInfo =
+        jsonInfo
             .getJSONArray("partitions")
             .getJSONObject(0)
             .getJSONArray("segments")