|
@@ -1,18 +1,20 @@
|
|
|
/*
|
|
|
- * Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
- * contributor license agreements. See the NOTICE file distributed with
|
|
|
- * this work for additional information regarding copyright ownership.
|
|
|
- * The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
- * (the "License"); you may not use this file except in compliance with
|
|
|
- * the License. You may obtain a copy of the License at
|
|
|
+ * Licensed to the Apache Software Foundation (ASF) under one
|
|
|
+ * or more contributor license agreements. See the NOTICE file
|
|
|
+ * distributed with this work for additional information
|
|
|
+ * regarding copyright ownership. The ASF licenses this file
|
|
|
+ * to you under the Apache License, Version 2.0 (the
|
|
|
+ * "License"); you may not use this file except in compliance
|
|
|
+ * with the License. You may obtain a copy of the License at
|
|
|
*
|
|
|
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
*
|
|
|
- * Unless required by applicable law or agreed to in writing, software
|
|
|
- * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
- * See the License for the specific language governing permissions and
|
|
|
- * limitations under the License.
|
|
|
+ * Unless required by applicable law or agreed to in writing,
|
|
|
+ * software distributed under the License is distributed on an
|
|
|
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
+ * KIND, either express or implied. See the License for the
|
|
|
+ * specific language governing permissions and limitations
|
|
|
+ * under the License.
|
|
|
*/
|
|
|
|
|
|
package io.milvus.client;
|
|
@@ -41,7 +43,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
private static final String ANSI_BRIGHT_PURPLE = "\u001B[95m";
|
|
|
|
|
|
private ManagedChannel channel = null;
|
|
|
- private io.milvus.grpc.MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub;
|
|
|
+ private io.milvus.grpc.MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub = null;
|
|
|
|
|
|
/////////////////////// Client Calls///////////////////////
|
|
|
|
|
@@ -82,7 +84,9 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
blockingStub = io.milvus.grpc.MilvusServiceGrpc.newBlockingStub(channel);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- logSevere("Connect failed! {0}\n{1}", connectParam.toString(), e.toString());
|
|
|
+ if (!(e instanceof ConnectFailedException)) {
|
|
|
+ logSevere("Connect failed! {0}\n{1}", connectParam.toString(), e.toString());
|
|
|
+ }
|
|
|
throw new ConnectFailedException("Exception occurred: " + e.toString());
|
|
|
}
|
|
|
|
|
@@ -121,14 +125,13 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Response createTable(@Nonnull TableSchemaParam tableSchemaParam) {
|
|
|
+ public Response createTable(@Nonnull TableSchema tableSchema) {
|
|
|
|
|
|
if (!isConnected()) {
|
|
|
logWarning("You are not connected to Milvus server");
|
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
|
}
|
|
|
|
|
|
- TableSchema tableSchema = tableSchemaParam.getTableSchema();
|
|
|
io.milvus.grpc.TableSchema request =
|
|
|
io.milvus.grpc.TableSchema.newBuilder()
|
|
|
.setTableName(tableSchema.getTableName())
|
|
@@ -140,10 +143,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
io.milvus.grpc.Status response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(tableSchemaParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .createTable(request);
|
|
|
+ response = blockingStub.createTable(request);
|
|
|
|
|
|
if (response.getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
logInfo("Created table successfully!\n{0}", tableSchema.toString());
|
|
@@ -164,23 +164,19 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HasTableResponse hasTable(@Nonnull TableParam tableParam) {
|
|
|
+ public HasTableResponse hasTable(@Nonnull String tableName) {
|
|
|
|
|
|
if (!isConnected()) {
|
|
|
logWarning("You are not connected to Milvus server");
|
|
|
return new HasTableResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), false);
|
|
|
}
|
|
|
|
|
|
- String tableName = tableParam.getTableName();
|
|
|
io.milvus.grpc.TableName request =
|
|
|
io.milvus.grpc.TableName.newBuilder().setTableName(tableName).build();
|
|
|
io.milvus.grpc.BoolReply response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(tableParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .hasTable(request);
|
|
|
+ response = blockingStub.hasTable(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
logInfo("hasTable `{0}` = {1}", tableName, response.getBoolReply());
|
|
@@ -200,23 +196,19 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Response dropTable(@Nonnull TableParam tableParam) {
|
|
|
+ public Response dropTable(@Nonnull String tableName) {
|
|
|
|
|
|
if (!isConnected()) {
|
|
|
logWarning("You are not connected to Milvus server");
|
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
|
}
|
|
|
|
|
|
- String tableName = tableParam.getTableName();
|
|
|
io.milvus.grpc.TableName request =
|
|
|
io.milvus.grpc.TableName.newBuilder().setTableName(tableName).build();
|
|
|
io.milvus.grpc.Status response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(tableParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .dropTable(request);
|
|
|
+ response = blockingStub.dropTable(request);
|
|
|
|
|
|
if (response.getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
logInfo("Dropped table `{0}` successfully!", tableName);
|
|
@@ -254,10 +246,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
io.milvus.grpc.Status response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(createIndexParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .createIndex(request);
|
|
|
+ response = blockingStub.createIndex(request);
|
|
|
|
|
|
if (response.getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
logInfo("Created index successfully!\n{0}", createIndexParam.toString());
|
|
@@ -299,10 +288,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
io.milvus.grpc.VectorIds response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(insertParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .insert(request);
|
|
|
+ response = blockingStub.insert(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
Optional<List<Long>> resultVectorIds = Optional.ofNullable(response.getVectorIdArrayList());
|
|
@@ -351,10 +337,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
io.milvus.grpc.TopKQueryResultList response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(searchParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .search(request);
|
|
|
+ response = blockingStub.search(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
List<List<SearchResponse.QueryResult>> queryResultsList = getQueryResultsList(response);
|
|
@@ -410,10 +393,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
io.milvus.grpc.TopKQueryResultList response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(searchInFilesParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .searchInFiles(request);
|
|
|
+ response = blockingStub.searchInFiles(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
logInfo("Search in files {0} completed successfully!", searchInFilesParam.getFileIds());
|
|
@@ -438,23 +418,19 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public DescribeTableResponse describeTable(@Nonnull TableParam tableParam) {
|
|
|
+ public DescribeTableResponse describeTable(@Nonnull String tableName) {
|
|
|
|
|
|
if (!isConnected()) {
|
|
|
logWarning("You are not connected to Milvus server");
|
|
|
return new DescribeTableResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), null);
|
|
|
}
|
|
|
|
|
|
- String tableName = tableParam.getTableName();
|
|
|
io.milvus.grpc.TableName request =
|
|
|
io.milvus.grpc.TableName.newBuilder().setTableName(tableName).build();
|
|
|
io.milvus.grpc.TableSchema response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(tableParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .describeTable(request);
|
|
|
+ response = blockingStub.describeTable(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
TableSchema tableSchema =
|
|
@@ -513,23 +489,19 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public GetTableRowCountResponse getTableRowCount(@Nonnull TableParam tableParam) {
|
|
|
+ public GetTableRowCountResponse getTableRowCount(@Nonnull String tableName) {
|
|
|
|
|
|
if (!isConnected()) {
|
|
|
logWarning("You are not connected to Milvus server");
|
|
|
return new GetTableRowCountResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), 0);
|
|
|
}
|
|
|
|
|
|
- String tableName = tableParam.getTableName();
|
|
|
io.milvus.grpc.TableName request =
|
|
|
io.milvus.grpc.TableName.newBuilder().setTableName(tableName).build();
|
|
|
io.milvus.grpc.TableRowCount response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(tableParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .countTable(request);
|
|
|
+ response = blockingStub.countTable(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
long tableRowCount = response.getTableRowCount();
|
|
@@ -551,30 +523,26 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
@Override
|
|
|
public Response getServerStatus() {
|
|
|
- CommandParam commandParam = new CommandParam.Builder("OK").build();
|
|
|
- return command(commandParam);
|
|
|
+ return command("OK");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Response getServerVersion() {
|
|
|
- CommandParam commandParam = new CommandParam.Builder("version").build();
|
|
|
- return command(commandParam);
|
|
|
+ return command("version");
|
|
|
}
|
|
|
|
|
|
- private Response command(@Nonnull CommandParam commandParam) {
|
|
|
+ private Response command(@Nonnull String command) {
|
|
|
|
|
|
if (!isConnected()) {
|
|
|
logWarning("You are not connected to Milvus server");
|
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
|
}
|
|
|
|
|
|
- String command = commandParam.getCommand();
|
|
|
io.milvus.grpc.Command request = io.milvus.grpc.Command.newBuilder().setCmd(command).build();
|
|
|
io.milvus.grpc.StringReply response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub.withDeadlineAfter(commandParam.getTimeout(), TimeUnit.SECONDS).cmd(request);
|
|
|
+ response = blockingStub.cmd(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
logInfo("Command `{0}`: {1}", command, response.getStringReply());
|
|
@@ -591,7 +559,8 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public Response deleteByRange(@Nonnull DeleteByRangeParam deleteByRangeParam) {
|
|
|
+ // TODO: make deleteByRange private for now
|
|
|
+ private Response deleteByRange(@Nonnull String tableName, @Nonnull DateRange dateRange) {
|
|
|
|
|
|
if (!isConnected()) {
|
|
|
logWarning("You are not connected to Milvus server");
|
|
@@ -600,28 +569,22 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
io.milvus.grpc.DeleteByRangeParam request =
|
|
|
io.milvus.grpc.DeleteByRangeParam.newBuilder()
|
|
|
- .setRange(getRange(deleteByRangeParam.getDateRange()))
|
|
|
- .setTableName(deleteByRangeParam.getTableName())
|
|
|
+ .setRange(getRange(dateRange))
|
|
|
+ .setTableName(tableName)
|
|
|
.build();
|
|
|
io.milvus.grpc.Status response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(deleteByRangeParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .deleteByRange(request);
|
|
|
+ response = blockingStub.deleteByRange(request);
|
|
|
|
|
|
if (response.getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
logInfo(
|
|
|
- "Deleted vectors from table `{0}` in range {1} successfully!",
|
|
|
- deleteByRangeParam.getTableName(), deleteByRangeParam.getDateRange().toString());
|
|
|
+ "Deleted vectors from table `{0}` in range {1} successfully!", tableName, dateRange);
|
|
|
return new Response(Response.Status.SUCCESS);
|
|
|
} else {
|
|
|
logSevere(
|
|
|
"Deleted vectors from table `{0}` in range {1} failed:\n{2}",
|
|
|
- deleteByRangeParam.getTableName(),
|
|
|
- deleteByRangeParam.getDateRange().toString(),
|
|
|
- response.toString());
|
|
|
+ tableName, dateRange, response.toString());
|
|
|
return new Response(
|
|
|
Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
|
|
|
}
|
|
@@ -632,23 +595,19 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Response preloadTable(@Nonnull TableParam tableParam) {
|
|
|
+ public Response preloadTable(@Nonnull String tableName) {
|
|
|
|
|
|
if (!isConnected()) {
|
|
|
logWarning("You are not connected to Milvus server");
|
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
|
}
|
|
|
|
|
|
- String tableName = tableParam.getTableName();
|
|
|
io.milvus.grpc.TableName request =
|
|
|
io.milvus.grpc.TableName.newBuilder().setTableName(tableName).build();
|
|
|
io.milvus.grpc.Status response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(tableParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .preloadTable(request);
|
|
|
+ response = blockingStub.preloadTable(request);
|
|
|
|
|
|
if (response.getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
logInfo("Preloaded table `{0}` successfully!", tableName);
|
|
@@ -665,23 +624,19 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public DescribeIndexResponse describeIndex(@Nonnull TableParam tableParam) {
|
|
|
+ public DescribeIndexResponse describeIndex(@Nonnull String tableName) {
|
|
|
|
|
|
if (!isConnected()) {
|
|
|
logWarning("You are not connected to Milvus server");
|
|
|
return new DescribeIndexResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), null);
|
|
|
}
|
|
|
|
|
|
- String tableName = tableParam.getTableName();
|
|
|
io.milvus.grpc.TableName request =
|
|
|
io.milvus.grpc.TableName.newBuilder().setTableName(tableName).build();
|
|
|
io.milvus.grpc.IndexParam response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(tableParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .describeIndex(request);
|
|
|
+ response = blockingStub.describeIndex(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
Index index =
|
|
@@ -706,23 +661,19 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Response dropIndex(@Nonnull TableParam tableParam) {
|
|
|
+ public Response dropIndex(@Nonnull String tableName) {
|
|
|
|
|
|
if (!isConnected()) {
|
|
|
logWarning("You are not connected to Milvus server");
|
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
|
}
|
|
|
|
|
|
- String tableName = tableParam.getTableName();
|
|
|
io.milvus.grpc.TableName request =
|
|
|
io.milvus.grpc.TableName.newBuilder().setTableName(tableName).build();
|
|
|
io.milvus.grpc.Status response;
|
|
|
|
|
|
try {
|
|
|
- response =
|
|
|
- blockingStub
|
|
|
- .withDeadlineAfter(tableParam.getTimeout(), TimeUnit.SECONDS)
|
|
|
- .dropIndex(request);
|
|
|
+ response = blockingStub.dropIndex(request);
|
|
|
|
|
|
if (response.getErrorCode() == io.milvus.grpc.ErrorCode.SUCCESS) {
|
|
|
logInfo("Dropped index for table `{0}` successfully!", tableName);
|
|
@@ -753,7 +704,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
List<io.milvus.grpc.Range> queryRangeList = new ArrayList<>();
|
|
|
String datePattern = "yyyy-MM-dd";
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern);
|
|
|
- for (DateRange queryRange : searchParam.getdateRanges()) {
|
|
|
+ for (DateRange queryRange : searchParam.getDateRanges()) {
|
|
|
io.milvus.grpc.Range dateRange =
|
|
|
io.milvus.grpc.Range.newBuilder()
|
|
|
.setStartValue(simpleDateFormat.format(queryRange.getStartDate()))
|