Skip to content

Commit 7368bf1

Browse files
committed
Delete equals() and hashCode() methods, rename builder
Signed-off-by: yhmo <yihua.mo@zilliz.com>
1 parent c76cf5b commit 7368bf1

300 files changed

Lines changed: 3092 additions & 6803 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/src/main/java/io/milvus/v1/ArrayFieldExample.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
import io.milvus.param.index.CreateIndexParam;
3535
import io.milvus.response.QueryResultsWrapper;
3636

37-
import java.util.*;
37+
import java.util.ArrayList;
38+
import java.util.Arrays;
39+
import java.util.List;
40+
import java.util.Random;
3841

3942
public class ArrayFieldExample {
4043
private static final String COLLECTION_NAME = "java_sdk_example_array_v1";
@@ -141,7 +144,7 @@ public static void main(String[] args) {
141144
List<String> strArray = new ArrayList<>();
142145
int capacity = random.nextInt(5) + 5;
143146
for (int k = 0; k < capacity; k++) {
144-
intArray.add((i+k)%100);
147+
intArray.add((i + k) % 100);
145148
strArray.add(String.format("string-%d-%d", i, k));
146149
}
147150
intArrArray.add(intArray);
@@ -186,7 +189,7 @@ public static void main(String[] args) {
186189
.withConsistencyLevel(ConsistencyLevelEnum.STRONG)
187190
.build());
188191
QueryResultsWrapper queryWrapper = new QueryResultsWrapper(queryRet.getData());
189-
System.out.printf("%d rows in collection\n", (long)queryWrapper.getFieldWrapper("count(*)").getFieldData().get(0));
192+
System.out.printf("%d rows in collection\n", (long) queryWrapper.getFieldWrapper("count(*)").getFieldData().get(0));
190193

191194
// Query by filtering expression
192195
queryWithExpr(client, "array_int32[0] == 99");

examples/src/main/java/io/milvus/v1/BinaryVectorExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class BinaryVectorExample {
4242
private static final String VECTOR_FIELD = "vector";
4343

4444
private static final Integer VECTOR_DIM = 128;
45-
45+
4646

4747
public static void main(String[] args) {
4848
// Connect to Milvus server. Replace the "localhost" and port with your Milvus server address.
@@ -172,7 +172,7 @@ public static void main(String[] args) {
172172
System.out.printf("The result of No.%d target vector:\n", i);
173173
for (SearchResultsWrapper.IDScore score : scores) {
174174
System.out.println(score);
175-
ByteBuffer vector = (ByteBuffer)score.get(VECTOR_FIELD);
175+
ByteBuffer vector = (ByteBuffer) score.get(VECTOR_FIELD);
176176
CommonUtils.printBinaryVector(vector);
177177
}
178178
if (scores.get(0).getLongID() != k) {

examples/src/main/java/io/milvus/v1/BulkWriterExample.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
import com.google.gson.Gson;
2525
import com.google.gson.JsonElement;
2626
import com.google.gson.JsonObject;
27-
import io.milvus.bulkwriter.BulkWriter;
28-
import io.milvus.bulkwriter.LocalBulkWriter;
29-
import io.milvus.bulkwriter.LocalBulkWriterParam;
30-
import io.milvus.bulkwriter.RemoteBulkWriter;
31-
import io.milvus.bulkwriter.RemoteBulkWriterParam;
27+
import io.milvus.bulkwriter.*;
3228
import io.milvus.bulkwriter.common.clientenum.BulkFileType;
3329
import io.milvus.bulkwriter.common.clientenum.CloudStorage;
3430
import io.milvus.bulkwriter.common.utils.GeneratorUtils;
@@ -50,19 +46,8 @@
5046
import io.milvus.grpc.DataType;
5147
import io.milvus.grpc.GetCollectionStatisticsResponse;
5248
import io.milvus.grpc.QueryResults;
53-
import io.milvus.param.ConnectParam;
54-
import io.milvus.param.IndexType;
55-
import io.milvus.param.MetricType;
56-
import io.milvus.param.R;
57-
import io.milvus.param.RpcStatus;
58-
import io.milvus.param.collection.CollectionSchemaParam;
59-
import io.milvus.param.collection.CreateCollectionParam;
60-
import io.milvus.param.collection.DropCollectionParam;
61-
import io.milvus.param.collection.FieldType;
62-
import io.milvus.param.collection.FlushParam;
63-
import io.milvus.param.collection.GetCollectionStatisticsParam;
64-
import io.milvus.param.collection.HasCollectionParam;
65-
import io.milvus.param.collection.LoadCollectionParam;
49+
import io.milvus.param.*;
50+
import io.milvus.param.collection.*;
6651
import io.milvus.param.dml.QueryParam;
6752
import io.milvus.param.index.CreateIndexParam;
6853
import io.milvus.response.GetCollStatResponseWrapper;
@@ -74,11 +59,7 @@
7459
import java.io.File;
7560
import java.io.IOException;
7661
import java.net.URL;
77-
import java.util.ArrayList;
78-
import java.util.Collections;
79-
import java.util.Iterator;
80-
import java.util.List;
81-
import java.util.Map;
62+
import java.util.*;
8263
import java.util.concurrent.TimeUnit;
8364

8465

@@ -596,7 +577,7 @@ private void callCloudImport(List<List<String>> batchFiles, String collectionNam
596577

597578
/**
598579
* @param collectionSchema collection info
599-
* @param dropIfExist if collection already exist, will drop firstly and then create again
580+
* @param dropIfExist if collection already exist, will drop firstly and then create again
600581
*/
601582
private void createCollection(String collectionName, CollectionSchemaParam collectionSchema, boolean dropIfExist) {
602583
System.out.println("\n===================== create collection ====================");

examples/src/main/java/io/milvus/v1/ClientPoolExample.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
import io.milvus.response.QueryResultsWrapper;
3939

4040
import java.time.Duration;
41-
import java.util.*;
41+
import java.util.ArrayList;
42+
import java.util.Arrays;
43+
import java.util.Collections;
44+
import java.util.List;
4245

4346
public class ClientPoolExample {
4447
public static String serverUri = "http://localhost:19530";
@@ -51,6 +54,7 @@ private static void printKeyClientNumber(MilvusClientV1Pool pool, String key) {
5154
System.out.printf("Key '%s': %d idle clients and %d active clients%n",
5255
key, pool.getIdleClientNumber(key), pool.getActiveClientNumber(key));
5356
}
57+
5458
private static void printClientNumber(MilvusClientV1Pool pool) {
5559
System.out.println("======================================================================");
5660
System.out.printf("Total %d idle clients and %d active clients%n",
@@ -158,7 +162,7 @@ public static Thread runInsertThread(MilvusClientV1Pool pool, String dbName, int
158162
Gson gson = new Gson();
159163
for (int i = 0; i < repeatRequests; i++) {
160164
MilvusClient client = null;
161-
while(client == null) {
165+
while (client == null) {
162166
try {
163167
// getClient() might exceeds the borrowMaxWaitMillis and throw exception
164168
// retry to call until it return a client
@@ -201,7 +205,7 @@ public static Thread runSearchThread(MilvusClientV1Pool pool, String dbName, int
201205
Thread t = new Thread(() -> {
202206
for (int i = 0; i < repeatRequests; i++) {
203207
MilvusClient client = null;
204-
while(client == null) {
208+
while (client == null) {
205209
try {
206210
// getClient() might exceeds the borrowMaxWaitMillis and throw exception
207211
// retry to call until it return a client
@@ -253,7 +257,7 @@ public static void verifyRowCount(MilvusClientV1Pool pool, long expectedCount) {
253257
.withConsistencyLevel(ConsistencyLevelEnum.STRONG)
254258
.build());
255259
QueryResultsWrapper queryWrapper = new QueryResultsWrapper(queryRet.getData());
256-
long rowCount = (long)queryWrapper.getFieldWrapper("count(*)").getFieldData().get(0);
260+
long rowCount = (long) queryWrapper.getFieldWrapper("count(*)").getFieldData().get(0);
257261
System.out.printf("%d rows persisted in collection '%s' of database '%s'%n",
258262
rowCount, CollectionName, dbName);
259263
if (rowCount != expectedCount) {
@@ -359,15 +363,15 @@ public static void main(String[] args) throws InterruptedException {
359363
printClientNumber(pool);
360364

361365
// check row count of each collection, there are threadCount*repeatRequests rows were inserted by multiple threads
362-
verifyRowCount(pool, threadCount*repeatRequests);
366+
verifyRowCount(pool, threadCount * repeatRequests);
363367
// drop collections
364368
dropCollections(pool);
365369
// drop databases, only after database is empty, it is able to be dropped
366370
dropDatabases(pool);
367371

368372
long end = System.currentTimeMillis();
369373
System.out.printf("%d insert requests and %d search requests finished in %.3f seconds%n",
370-
threadCount*repeatRequests*3, threadCount*repeatRequests*3, (end-start)*0.001);
374+
threadCount * repeatRequests * 3, threadCount * repeatRequests * 3, (end - start) * 0.001);
371375

372376
printClientNumber(pool);
373377
pool.clear(); // clear idle clients

examples/src/main/java/io/milvus/v1/CommonUtils.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import io.milvus.common.utils.Float16Utils;
2222
import io.milvus.param.R;
23-
2423
import org.tensorflow.Tensor;
2524
import org.tensorflow.ndarray.Shape;
2625
import org.tensorflow.ndarray.buffer.ByteDataBuffer;
@@ -69,7 +68,7 @@ public static List<List<Float>> generateFloatVectors(int dimension, int count) {
6968
public static List<List<Float>> generateFixFloatVectors(int dimension, int count) {
7069
List<List<Float>> vectors = new ArrayList<>();
7170
for (int n = 0; n < count; ++n) {
72-
List<Float> vector = generateFloatVector(dimension, (float)n);
71+
List<Float> vector = generateFloatVector(dimension, (float) n);
7372
vectors.add(vector);
7473
}
7574
return vectors;
@@ -87,7 +86,7 @@ public static void compareFloatVectors(List<Float> vec1, List<Float> vec2) {
8786
}
8887
}
8988

90-
/////////////////////////////////////////////////////////////////////////////////////////////////////
89+
/// //////////////////////////////////////////////////////////////////////////////////////////////////
9190
public static ByteBuffer generateBinaryVector(int dimension) {
9291
Random ran = new Random();
9392
int byteCount = dimension / 8;
@@ -117,7 +116,7 @@ public static void printBinaryVector(ByteBuffer vector) {
117116
System.out.println();
118117
}
119118

120-
/////////////////////////////////////////////////////////////////////////////////////////////////////
119+
/// //////////////////////////////////////////////////////////////////////////////////////////////////
121120
public static TBfloat16 genTensorflowBF16Vector(int dimension) {
122121
Random ran = new Random();
123122
float[] array = new float[dimension];
@@ -131,7 +130,7 @@ public static TBfloat16 genTensorflowBF16Vector(int dimension) {
131130
public static List<TBfloat16> genTensorflowBF16Vectors(int dimension, int count) {
132131
List<TBfloat16> vectors = new ArrayList<>();
133132
for (int n = 0; n < count; ++n) {
134-
TBfloat16 vector = genTensorflowBF16Vector(dimension);
133+
TBfloat16 vector = genTensorflowBF16Vector(dimension);
135134
vectors.add(vector);
136135
}
137136

@@ -140,7 +139,7 @@ public static List<TBfloat16> genTensorflowBF16Vectors(int dimension, int count)
140139

141140
public static ByteBuffer encodeTensorBF16Vector(TBfloat16 vector) {
142141
ByteDataBuffer tensorBuf = vector.asRawTensor().data();
143-
ByteBuffer buf = ByteBuffer.allocate((int)tensorBuf.size());
142+
ByteBuffer buf = ByteBuffer.allocate((int) tensorBuf.size());
144143
for (long i = 0; i < tensorBuf.size(); i++) {
145144
buf.put(tensorBuf.getByte(i));
146145
}
@@ -157,10 +156,10 @@ public static List<ByteBuffer> encodeTensorBF16Vectors(List<TBfloat16> vectors)
157156
}
158157

159158
public static TBfloat16 decodeBF16VectorToTensor(ByteBuffer buf) {
160-
if (buf.limit()%2 != 0) {
159+
if (buf.limit() % 2 != 0) {
161160
return null;
162161
}
163-
int dim = buf.limit()/2;
162+
int dim = buf.limit() / 2;
164163
ByteDataBuffer bf = DataBuffers.of(buf.array());
165164
return Tensor.of(TBfloat16.class, Shape.of(dim), bf);
166165
}
@@ -197,7 +196,7 @@ public static List<TFloat16> genTensorflowFP16Vectors(int dimension, int count)
197196

198197
public static ByteBuffer encodeTensorFP16Vector(TFloat16 vector) {
199198
ByteDataBuffer tensorBuf = vector.asRawTensor().data();
200-
ByteBuffer buf = ByteBuffer.allocate((int)tensorBuf.size());
199+
ByteBuffer buf = ByteBuffer.allocate((int) tensorBuf.size());
201200
for (long i = 0; i < tensorBuf.size(); i++) {
202201
buf.put(tensorBuf.getByte(i));
203202
}
@@ -214,10 +213,10 @@ public static List<ByteBuffer> encodeTensorFP16Vectors(List<TFloat16> vectors) {
214213
}
215214

216215
public static TFloat16 decodeFP16VectorToTensor(ByteBuffer buf) {
217-
if (buf.limit()%2 != 0) {
216+
if (buf.limit() % 2 != 0) {
218217
return null;
219218
}
220-
int dim = buf.limit()/2;
219+
int dim = buf.limit() / 2;
221220
ByteDataBuffer bf = DataBuffers.of(buf.array());
222221
return Tensor.of(TFloat16.class, Shape.of(dim), bf);
223222
}
@@ -231,7 +230,7 @@ public static List<Float> decodeFP16VectorToFloat(ByteBuffer buf) {
231230
return vector;
232231
}
233232

234-
/////////////////////////////////////////////////////////////////////////////////////////////////////
233+
/// //////////////////////////////////////////////////////////////////////////////////////////////////
235234
public static ByteBuffer encodeFloat16Vector(List<Float> originVector, boolean bfloat16) {
236235
if (bfloat16) {
237236
return Float16Utils.f32VectorToBf16Buffer(originVector);
@@ -274,7 +273,7 @@ public static List<ByteBuffer> generateFloat16Vectors(int dimension, int count,
274273
return vectors;
275274
}
276275

277-
/////////////////////////////////////////////////////////////////////////////////////////////////////
276+
/// //////////////////////////////////////////////////////////////////////////////////////////////////
278277
public static ByteBuffer generateInt8Vector(int dimension) {
279278
Random ran = new Random();
280279
int byteCount = dimension;
@@ -295,13 +294,13 @@ public static List<ByteBuffer> generateInt8Vectors(int dimension, int count) {
295294
return vectors;
296295
}
297296

298-
/////////////////////////////////////////////////////////////////////////////////////////////////////
297+
/// //////////////////////////////////////////////////////////////////////////////////////////////////
299298
public static SortedMap<Long, Float> generateSparseVector() {
300299
Random ran = new Random();
301300
SortedMap<Long, Float> sparse = new TreeMap<>();
302301
int dim = ran.nextInt(10) + 10;
303302
while (sparse.size() < dim) {
304-
sparse.put((long)ran.nextInt(1000000), ran.nextFloat());
303+
sparse.put((long) ran.nextInt(1000000), ran.nextFloat());
305304
}
306305
return sparse;
307306
}

examples/src/main/java/io/milvus/v1/ConsistencyLevelExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private static List<SearchResultsWrapper.IDScore> search(String collectionName,
137137
.withCollectionName(collectionName)
138138
.withVectorFieldName("vector")
139139
.withFloatVectors(Collections.singletonList(CommonUtils.generateFloatVector(VECTOR_DIM)))
140-
.withLimit((long)topK)
140+
.withLimit((long) topK)
141141
.withMetricType(MetricType.L2)
142142
.build());
143143
CommonUtils.handleResponseStatus(searchR);
@@ -187,7 +187,7 @@ private static void testSessionLevel() throws ClassNotFoundException, NoSuchMeth
187187
row.add("vector", gson.toJsonTree(vector));
188188

189189
// insert by a MilvusClient
190-
String clientName1 = String.format("client_%d", i%10);
190+
String clientName1 = String.format("client_%d", i % 10);
191191
MilvusClient client1 = pool.getClient(clientName1);
192192
client1.insert(InsertParam.newBuilder()
193193
.withCollectionName(collectionName)
@@ -198,7 +198,7 @@ private static void testSessionLevel() throws ClassNotFoundException, NoSuchMeth
198198

199199
// search by another MilvusClient, use the just inserted vector to search
200200
// the returned item is expected to be the just inserted item
201-
String clientName2 = String.format("client_%d", i%10+1);
201+
String clientName2 = String.format("client_%d", i % 10 + 1);
202202
MilvusClient client2 = pool.getClient(clientName2);
203203
R<SearchResults> searchR = client2.search(SearchParam.newBuilder()
204204
.withCollectionName(collectionName)

examples/src/main/java/io/milvus/v1/Float16VectorExample.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@
2222
import com.google.gson.JsonObject;
2323
import io.milvus.client.MilvusServiceClient;
2424
import io.milvus.common.clientenum.ConsistencyLevelEnum;
25-
import io.milvus.grpc.*;
25+
import io.milvus.grpc.DataType;
26+
import io.milvus.grpc.MutationResult;
27+
import io.milvus.grpc.QueryResults;
28+
import io.milvus.grpc.SearchResults;
2629
import io.milvus.param.*;
2730
import io.milvus.param.collection.*;
28-
import io.milvus.param.dml.*;
29-
import io.milvus.param.index.*;
30-
import io.milvus.response.*;
31+
import io.milvus.param.dml.InsertParam;
32+
import io.milvus.param.dml.QueryParam;
33+
import io.milvus.param.dml.SearchParam;
34+
import io.milvus.param.index.CreateIndexParam;
35+
import io.milvus.response.FieldDataWrapper;
36+
import io.milvus.response.QueryResultsWrapper;
37+
import io.milvus.response.SearchResultsWrapper;
3138
import org.tensorflow.types.TBfloat16;
3239
import org.tensorflow.types.TFloat16;
3340

@@ -42,6 +49,7 @@ public class Float16VectorExample {
4249
private static final Integer VECTOR_DIM = 128;
4350

4451
private static final MilvusServiceClient milvusClient;
52+
4553
static {
4654
// Connect to Milvus server. Replace the "localhost" and port with your Milvus server address.
4755
milvusClient = new MilvusServiceClient(ConnectParam.newBuilder()
@@ -179,7 +187,7 @@ private static void testFloat16(boolean bfloat16) {
179187
// Ensure the returned top1 item's ID should be equal to target vector's ID
180188
for (int i = 0; i < 10; i++) {
181189
Random ran = new Random();
182-
int k = ran.nextInt(batchRowCount*2);
190+
int k = ran.nextInt(batchRowCount * 2);
183191
ByteBuffer targetVector = encodedVectors.get(k);
184192
SearchParam.Builder builder = SearchParam.newBuilder()
185193
.withCollectionName(COLLECTION_NAME)
@@ -208,7 +216,7 @@ private static void testFloat16(boolean bfloat16) {
208216
firstScore.getLongID(), k));
209217
}
210218

211-
ByteBuffer outputBuf = (ByteBuffer)firstScore.get(VECTOR_FIELD);
219+
ByteBuffer outputBuf = (ByteBuffer) firstScore.get(VECTOR_FIELD);
212220
if (!outputBuf.equals(targetVector)) {
213221
throw new RuntimeException(String.format("The output vector is not equal to target vector: ID %d", k));
214222
}
@@ -229,7 +237,7 @@ private static void testFloat16(boolean bfloat16) {
229237
// Retrieve some data and verify the output
230238
for (int i = 0; i < 10; i++) {
231239
Random ran = new Random();
232-
int k = ran.nextInt(batchRowCount*2);
240+
int k = ran.nextInt(batchRowCount * 2);
233241
R<QueryResults> queryR = milvusClient.query(QueryParam.newBuilder()
234242
.withCollectionName(COLLECTION_NAME)
235243
.withExpr(String.format("id == %d", k))

examples/src/main/java/io/milvus/v1/GeneralExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class GeneralExample {
4646
ConnectParam connectParam = ConnectParam.newBuilder()
4747
.withHost("localhost")
4848
.withPort(19530)
49-
.withAuthorization("root","Milvus")
49+
.withAuthorization("root", "Milvus")
5050
.build();
5151
RetryParam retryParam = RetryParam.newBuilder()
5252
.withMaxRetryTimes(3)

0 commit comments

Comments
 (0)