diff --git a/face-search-util/pom.xml b/face-search-util/pom.xml index 70175da..386b1d6 100644 --- a/face-search-util/pom.xml +++ b/face-search-util/pom.xml @@ -9,7 +9,6 @@ 4.0.0 face-search-util - pom UTF-8 diff --git a/milvus-java-sdk/pom.xml b/milvus-java-sdk/pom.xml deleted file mode 100644 index d498629..0000000 --- a/milvus-java-sdk/pom.xml +++ /dev/null @@ -1,215 +0,0 @@ - - - 4.0.0 - io.milvus - milvus-java-sdk - 2.0.0 - - - UTF-8 - 1.36.0 - 3.12.0 - 3.12.0 - 4.3 - 1.8 - 1.8 - - - - - - io.grpc - grpc-bom - ${grpc.version} - pom - import - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - io.grpc - grpc-netty-shaded - ${grpc.version} - runtime - - - io.grpc - grpc-protobuf - ${grpc.version} - - - io.grpc - grpc-stub - ${grpc.version} - - - javax.annotation - javax.annotation-api - 1.2 - provided - - - io.grpc - grpc-testing - test - - - com.google.protobuf - protobuf-java-util - ${protobuf.version} - - - org.apache.commons - commons-text - 1.6 - - - org.apache.commons - commons-collections4 - ${commons-collections4.version} - - - org.json - json - 20190722 - - - org.slf4j - slf4j-api - 1.7.30 - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.12.1 - - - junit - junit - 4.13.1 - test - - - org.junit.jupiter - junit-jupiter-api - 5.7.0 - test - - - org.projectlombok - lombok - 1.18.22 - provided - - - - - - - - src/main/resources - true - - - - - kr.motd.maven - os-maven-plugin - 1.6.2 - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.8 - true - - ossrh - https://oss.sonatype.org/ - true - - - - org.apache.maven.plugins - maven-release-plugin - 2.5.3 - - true - false - release - deploy - - - - org.xolstice.maven.plugins - protobuf-maven-plugin - 0.6.1 - - com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier} - grpc-java - io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} - - - - - compile - compile-custom - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M2 - - - enforce - - - - - - - enforce - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.19.1 - - false - - - - org.junit.platform - junit-platform-surefire-provider - 1.1.0 - - - org.junit.jupiter - junit-jupiter-engine - 5.1.0 - - - - - - - \ No newline at end of file diff --git a/milvus-java-sdk/src/main/java/io/milvus/Response/FieldDataWrapper.java b/milvus-java-sdk/src/main/java/io/milvus/Response/FieldDataWrapper.java deleted file mode 100644 index d09dc59..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/Response/FieldDataWrapper.java +++ /dev/null @@ -1,152 +0,0 @@ -package io.milvus.Response; - -import io.milvus.grpc.DataType; -import io.milvus.grpc.FieldData; -import io.milvus.exception.IllegalResponseException; - -import lombok.NonNull; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; - -import com.google.protobuf.ByteString; - -/** - * Util class to wrap response of query/search interface. - */ -public class FieldDataWrapper { - private final FieldData fieldData; - - public FieldDataWrapper(@NonNull FieldData fieldData) { - this.fieldData = fieldData; - } - - public boolean isVectorField() { - return fieldData.getType() == DataType.FloatVector || fieldData.getType() == DataType.BinaryVector; - } - - /** - * Get dimension of a vector field. - * Throw {@link IllegalResponseException} if the field is not a vector filed. - * - * @return int dimension of the vector field - */ - public int getDim() throws IllegalResponseException { - if (!isVectorField()) { - throw new IllegalResponseException("Not a vector field"); - } - return (int) fieldData.getVectors().getDim(); - } - - /** - * Get row count of a field. - * * Throws {@link IllegalResponseException} if the field type is illegal. - * - * @return long row count of the field - */ - public long getRowCount() throws IllegalResponseException { - DataType dt = fieldData.getType(); - switch (dt) { - case FloatVector: { - int dim = getDim(); - System.out.println(fieldData.getVectors().getFloatVector().getDataCount()); - List data = fieldData.getVectors().getFloatVector().getDataList(); - if (data.size() % dim != 0) { - throw new IllegalResponseException("Returned float vector field data array size doesn't match dimension"); - } - - return data.size()/dim; - } - case BinaryVector: { - int dim = getDim(); - ByteString data = fieldData.getVectors().getBinaryVector(); - if (data.size() % dim != 0) { - throw new IllegalResponseException("Returned binary vector field data array size doesn't match dimension"); - } - - return data.size()/dim; - } - case Int64: - return fieldData.getScalars().getLongData().getDataList().size(); - case Int32: - case Int16: - case Int8: - return fieldData.getScalars().getIntData().getDataList().size(); - case Bool: - return fieldData.getScalars().getBoolData().getDataList().size(); - case Float: - return fieldData.getScalars().getFloatData().getDataList().size(); - case Double: - return fieldData.getScalars().getDoubleData().getDataList().size(); - case String: - return fieldData.getScalars().getStringData().getDataList().size(); - default: - throw new IllegalResponseException("Unsupported data type returned by FieldData"); - } - } - - /** - * Return field data according to its type: - * float vector field return List> - * binary vector field return List - * int64 field return List - * boolean field return List - * - * Throws {@link IllegalResponseException} if the field type is illegal. - * - * @return List - */ - public List getFieldData() throws IllegalResponseException { - DataType dt = fieldData.getType(); - switch (dt) { - case FloatVector: { - int dim = getDim(); - System.out.println(fieldData.getVectors().getFloatVector().getDataCount()); - List data = fieldData.getVectors().getFloatVector().getDataList(); - if (data.size() % dim != 0) { - throw new IllegalResponseException("Returned float vector field data array size doesn't match dimension"); - } - - List> packData = new ArrayList<>(); - int count = data.size() / dim; - for (int i = 0; i < count; ++i) { - packData.add(data.subList(i * dim, (i + 1) * dim)); - } - return packData; - } - case BinaryVector: { - int dim = getDim(); - ByteString data = fieldData.getVectors().getBinaryVector(); - if (data.size() % dim != 0) { - throw new IllegalResponseException("Returned binary vector field data array size doesn't match dimension"); - } - - List packData = new ArrayList<>(); - int count = data.size() / dim; - for (int i = 0; i < count; ++i) { - ByteBuffer bf = ByteBuffer.allocate(dim); - bf.put(data.substring(i * dim, (i + 1) * dim).toByteArray()); - packData.add(bf); - } - return packData; - } - case Int64: - return fieldData.getScalars().getLongData().getDataList(); - case Int32: - case Int16: - case Int8: - return fieldData.getScalars().getIntData().getDataList(); - case Bool: - return fieldData.getScalars().getBoolData().getDataList(); - case Float: - return fieldData.getScalars().getFloatData().getDataList(); - case Double: - return fieldData.getScalars().getDoubleData().getDataList(); - case String: - return fieldData.getScalars().getStringData().getDataList(); - default: - throw new IllegalResponseException("Unsupported data type returned by FieldData"); - } - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/Response/GetCollStatResponseWrapper.java b/milvus-java-sdk/src/main/java/io/milvus/Response/GetCollStatResponseWrapper.java deleted file mode 100644 index 69b97ef..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/Response/GetCollStatResponseWrapper.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.milvus.Response; - -import io.milvus.grpc.GetCollectionStatisticsResponse; -import io.milvus.grpc.KeyValuePair; -import lombok.NonNull; - -import java.util.List; - -/** - * Util class to wrap response of getCollectionStatistics interface. - */ -public class GetCollStatResponseWrapper { - private final GetCollectionStatisticsResponse stat; - - public GetCollStatResponseWrapper(@NonNull GetCollectionStatisticsResponse stat) { - this.stat = stat; - } - - /** - * Get row count of this field. - * Throw {@link NumberFormatException} if the row count is not a number. - * - * @return int dimension of the vector field - */ - public long GetRowCount() throws NumberFormatException { - List stats = stat.getStatsList(); - for (KeyValuePair kv : stats) { - if (kv.getKey().compareTo("row_count") == 0) { - return Long.parseLong(kv.getValue()); - } - } - - return 0; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/Response/InsertResultWrapper.java b/milvus-java-sdk/src/main/java/io/milvus/Response/InsertResultWrapper.java deleted file mode 100644 index 11af53a..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/Response/InsertResultWrapper.java +++ /dev/null @@ -1,57 +0,0 @@ -package io.milvus.Response; - -import io.milvus.exception.ParamException; -import io.milvus.grpc.MutationResult; - -import java.util.List; - -import lombok.NonNull; - -/** - * Util class to wrap response of insert interface. - */ -public class InsertResultWrapper { - private final MutationResult result; - - public InsertResultWrapper(@NonNull MutationResult result) { - this.result = result; - } - - /** - * Get inserted count. - * - * @return int inserted count - */ - public long getInsertCount() { - return result.getInsertCnt(); - } - - /** - * Get long id array returned by insert interface. - * Throw {@link ParamException} if the primary key type is not int64 type. - * - * @return List id array returned by insert interface - */ - public List getLongIDs() throws ParamException { - if (result.getIDs().hasIntId()) { - return result.getIDs().getIntId().getDataList(); - } else { - throw new ParamException("The primary key is not long type, please try getStringIDs()"); - } - } - - /** - * Get string id array returned by insert interface. - * Throw {@link ParamException} if the primary key type is not string type. - * Note that currently Milvus doesn't support string type field, this method is reserved. - * - * @return List id array returned by insert interface - */ - public List getStringIDs() throws ParamException { - if (result.getIDs().hasStrId()) { - return result.getIDs().getStrId().getDataList(); - } else { - throw new ParamException("The primary key is not string type, please try getLongIDs()"); - } - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/Response/QueryResultsWrapper.java b/milvus-java-sdk/src/main/java/io/milvus/Response/QueryResultsWrapper.java deleted file mode 100644 index 01e0711..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/Response/QueryResultsWrapper.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.milvus.Response; - -import io.milvus.exception.ParamException; -import io.milvus.grpc.*; - -import lombok.NonNull; - -import java.util.List; - -/** - * Util class to wrap response of query interface. - */ -public class QueryResultsWrapper { - private final QueryResults results; - - public QueryResultsWrapper(@NonNull QueryResults results) { - this.results = results; - } - - /** - * Get {@link FieldDataWrapper} for a field. - * Throws {@link ParamException} if the field doesn't exist. - * - * @return FieldDataWrapper - */ - public FieldDataWrapper getFieldWrapper(@NonNull String fieldName) throws ParamException { - List fields = results.getFieldsDataList(); - for (FieldData field : fields) { - if (fieldName.compareTo(field.getFieldName()) == 0) { - return new FieldDataWrapper(field); - } - } - - throw new ParamException("The field name doesn't exist"); - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/Response/SearchResultsWrapper.java b/milvus-java-sdk/src/main/java/io/milvus/Response/SearchResultsWrapper.java deleted file mode 100644 index 7feff79..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/Response/SearchResultsWrapper.java +++ /dev/null @@ -1,123 +0,0 @@ -package io.milvus.Response; - -import io.milvus.exception.IllegalResponseException; -import io.milvus.exception.ParamException; -import io.milvus.grpc.*; -import lombok.Getter; -import lombok.NonNull; - -import java.util.ArrayList; -import java.util.List; - -/** - * Util class to wrap response of search interface. - */ -public class SearchResultsWrapper { - private final SearchResultData results; - - public SearchResultsWrapper(@NonNull SearchResultData results) { - this.results = results; - } - - /** - * Get {@link FieldDataWrapper} for a field. - * Throws {@link ParamException} if the field doesn't exist. - * - * @return FieldDataWrapper - */ - public FieldDataWrapper GetFieldData(@NonNull String fieldName) { - for (int i = 0; i < results.getFieldsDataCount(); ++i) { - FieldData data = results.getFieldsData(i); - if (fieldName.compareTo(data.getFieldName()) == 0) { - return new FieldDataWrapper(data); - } - } - - return null; - } - - /** - * Get id-score pairs returned by search interface. - * Throw {@link ParamException} if the indexOfTarget is illegal. - * Throw {@link IllegalResponseException} if the returned results is illegal. - * - * @return List id-score pairs returned by search interface - */ - public List GetIDScore(int indexOfTarget) throws ParamException, IllegalResponseException { - List kList = results.getTopksList(); - - // if the server didn't return separate topK, use same topK value - if (kList.isEmpty()) { - kList = new ArrayList<>(); - for (long i = 0; i < results.getNumQueries(); ++i) { - kList.add(results.getTopK()); - } - } - - if (indexOfTarget < 0 || indexOfTarget >= kList.size()) { - throw new ParamException("Illegal index of target: " + indexOfTarget); - } - - int offset = 0; - for (int i = 0; i < indexOfTarget; ++i) { - offset += kList.get(i); - } - - long k = kList.get(indexOfTarget); - if (offset + k > results.getScoresCount()) { - throw new IllegalResponseException("Result scores count is wrong"); - } - - List idScore = new ArrayList<>(); - - IDs ids = results.getIds(); - if (ids.hasIntId()) { - LongArray longIDs = ids.getIntId(); - if (offset + k > longIDs.getDataCount()) { - throw new IllegalResponseException("Result ids count is wrong"); - } - - for (int n = 0; n < k; ++n) { - idScore.add(new IDScore("", longIDs.getData(offset + n), results.getScores(offset + n))); - } - } else if (ids.hasStrId()) { - StringArray strIDs = ids.getStrId(); - if (offset + k >= strIDs.getDataCount()) { - throw new IllegalResponseException("Result ids count is wrong"); - } - - for (int n = 0; n < k; ++n) { - idScore.add(new IDScore(strIDs.getData(offset + n), 0, results.getScores(offset + n))); - } - } else { - throw new IllegalResponseException("Result ids is illegal"); - } - - return idScore; - } - - /** - * Internal use class to wrap response of search interface. - */ - @Getter - public static final class IDScore { - private final String strID; - private final long longID; - private final float score; - - public IDScore(String strID, long longID, float score) { - this.strID = strID; - this.longID = longID; - this.score = score; - } - - @Override - public String toString() { - if (strID.isEmpty()) { - return "(ID: " + longID + " Score: " + score + ")"; - } else { - return "(ID: '" + strID + "' Score: " + score + ")"; - } - } - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/client/AbstractMilvusGrpcClient.java b/milvus-java-sdk/src/main/java/io/milvus/client/AbstractMilvusGrpcClient.java deleted file mode 100644 index 23d8f0c..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/client/AbstractMilvusGrpcClient.java +++ /dev/null @@ -1,1831 +0,0 @@ -/* - * 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 - * - * 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; - -import com.google.protobuf.ByteString; -import io.grpc.StatusRuntimeException; -import io.milvus.exception.ClientNotConnectedException; -import io.milvus.exception.IllegalResponseException; -import io.milvus.exception.ParamException; -import io.milvus.grpc.*; -import io.milvus.param.Constant; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; -import io.milvus.param.alias.AlterAliasParam; -import io.milvus.param.alias.CreateAliasParam; -import io.milvus.param.alias.DropAliasParam; -import io.milvus.param.collection.*; -import io.milvus.param.control.*; -import io.milvus.param.dml.*; -import io.milvus.param.index.*; -import io.milvus.param.partition.*; -import lombok.NonNull; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -public abstract class AbstractMilvusGrpcClient implements MilvusClient { - - private static final Logger logger = LoggerFactory.getLogger(AbstractMilvusGrpcClient.class); - - protected abstract MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub(); - - protected abstract MilvusServiceGrpc.MilvusServiceFutureStub futureStub(); - - protected abstract boolean clientIsReady(); - - ///////////////////// Internal Functions////////////////////// - private List assembleKvPair(Map sourceMap) { - List result = new ArrayList<>(); - if (MapUtils.isNotEmpty(sourceMap)) { - sourceMap.forEach((key, value) -> { - KeyValuePair kv = KeyValuePair.newBuilder() - .setKey(key) - .setValue(value).build(); - result.add(kv); - }); - } - return result; - } - - @SuppressWarnings("unchecked") - private FieldData genFieldData(String fieldName, DataType dataType, List objects) { - if (objects == null) { - throw new ParamException("Cannot generate FieldData from null object"); - } - FieldData.Builder builder = FieldData.newBuilder(); - if (vectorDataType.contains(dataType)) { - if (dataType == DataType.FloatVector) { - List floats = new ArrayList<>(); - // each object is List - for (Object object : objects) { - if (object instanceof List) { - List list = (List) object; - floats.addAll(list); - } else { - throw new ParamException("The type of FloatVector must be List"); - } - } - - int dim = floats.size() / objects.size(); - FloatArray floatArray = FloatArray.newBuilder().addAllData(floats).build(); - VectorField vectorField = VectorField.newBuilder().setDim(dim).setFloatVector(floatArray).build(); - return builder.setFieldName(fieldName).setType(DataType.FloatVector).setVectors(vectorField).build(); - } else if (dataType == DataType.BinaryVector) { - ByteBuffer totalBuf = null; - int dim = 0; - // each object is ByteBuffer - for (Object object : objects) { - ByteBuffer buf = (ByteBuffer) object; - if (totalBuf == null){ - totalBuf = ByteBuffer.allocate(buf.position() * objects.size()); - totalBuf.put(buf.array()); - dim = buf.position() * 8; - } else { - totalBuf.put(buf.array()); - } - } - - assert totalBuf != null; - ByteString byteString = ByteString.copyFrom(totalBuf.array()); - VectorField vectorField = VectorField.newBuilder().setDim(dim).setBinaryVector(byteString).build(); - return builder.setFieldName(fieldName).setType(DataType.BinaryVector).setVectors(vectorField).build(); - } - } else { - switch (dataType) { - case None: - case UNRECOGNIZED: - throw new ParamException("Cannot support this dataType:" + dataType); - case Int64: - List longs = objects.stream().map(p -> (Long) p).collect(Collectors.toList()); - LongArray longArray = LongArray.newBuilder().addAllData(longs).build(); - ScalarField scalarField1 = ScalarField.newBuilder().setLongData(longArray).build(); - return builder.setFieldName(fieldName).setType(dataType).setScalars(scalarField1).build(); - case Int32: - case Int16: - case Int8: - List integers = objects.stream().map(p -> p instanceof Short ? ((Short)p).intValue() :(Integer) p).collect(Collectors.toList()); - IntArray intArray = IntArray.newBuilder().addAllData(integers).build(); - ScalarField scalarField2 = ScalarField.newBuilder().setIntData(intArray).build(); - return builder.setFieldName(fieldName).setType(dataType).setScalars(scalarField2).build(); - case Bool: - List booleans = objects.stream().map(p -> (Boolean) p).collect(Collectors.toList()); - BoolArray boolArray = BoolArray.newBuilder().addAllData(booleans).build(); - ScalarField scalarField3 = ScalarField.newBuilder().setBoolData(boolArray).build(); - return builder.setFieldName(fieldName).setType(dataType).setScalars(scalarField3).build(); - case Float: - List floats = objects.stream().map(p -> (Float) p).collect(Collectors.toList()); - FloatArray floatArray = FloatArray.newBuilder().addAllData(floats).build(); - ScalarField scalarField4 = ScalarField.newBuilder().setFloatData(floatArray).build(); - return builder.setFieldName(fieldName).setType(dataType).setScalars(scalarField4).build(); - case Double: - List doubles = objects.stream().map(p -> (Double) p).collect(Collectors.toList()); - DoubleArray doubleArray = DoubleArray.newBuilder().addAllData(doubles).build(); - ScalarField scalarField5 = ScalarField.newBuilder().setDoubleData(doubleArray).build(); - return builder.setFieldName(fieldName).setType(dataType).setScalars(scalarField5).build(); - case String: - List strings = objects.stream().map(p -> (String) p).collect(Collectors.toList()); - StringArray stringArray = StringArray.newBuilder().addAllData(strings).build(); - ScalarField scalarField6 = ScalarField.newBuilder().setStringData(stringArray).build(); - return builder.setFieldName(fieldName).setType(dataType).setScalars(scalarField6).build(); - } - } - - return null; - } - - private static final Set vectorDataType = new HashSet() {{ - add(DataType.FloatVector); - add(DataType.BinaryVector); - }}; - - private void waitForLoadingCollection(String collectionName, List partitionNames, - long waitingInterval, long timeout) throws IllegalResponseException { - long tsBegin = System.currentTimeMillis(); - if (partitionNames == null || partitionNames.isEmpty()) { - ShowCollectionsRequest showCollectionRequest = ShowCollectionsRequest.newBuilder() - .addCollectionNames(collectionName) - .setType(ShowType.InMemory) - .build(); - - // Use showCollection() to check loading percentages of the collection. - // If the inMemory percentage is 100, that means the collection has finished loading. - // Otherwise, this thread will sleep a small interval and check again. - // If waiting time exceed timeout, exist the circle - while (true) { - long tsNow = System.currentTimeMillis(); - if ((tsNow - tsBegin) >= timeout*1000) { - logWarning("Waiting load thread is timeout, loading process may not be finished"); - break; - } - - ShowCollectionsResponse response = blockingStub().showCollections(showCollectionRequest); - int namesCount = response.getCollectionNamesCount(); - int percentagesCount = response.getInMemoryPercentagesCount(); - if (namesCount != 1) { - throw new IllegalResponseException("ShowCollectionsResponse is illegal. Collection count: " - + namesCount); - } - - if (namesCount != percentagesCount) { - String msg = "ShowCollectionsResponse is illegal. Collection count: " + namesCount - + " memory percentages count: " + percentagesCount; - throw new IllegalResponseException(msg); - } - - long percentage = response.getInMemoryPercentages(0); - String responseCollection = response.getCollectionNames(0); - if (responseCollection.compareTo(collectionName) == 0 && percentage >= 100) { - break; - } - - try { - logInfo("Waiting load, interval: {} ms, percentage: {}%", waitingInterval, percentage); - TimeUnit.MILLISECONDS.sleep(waitingInterval); - } catch (InterruptedException e) { - logWarning("Waiting load thread is interrupted, loading process may not be finished"); - break; - } - } - - } else { - ShowPartitionsRequest showPartitionsRequest = ShowPartitionsRequest.newBuilder() - .setCollectionName(collectionName) - .addAllPartitionNames(partitionNames) - .setType(ShowType.InMemory).build(); - - // Use showPartitions() to check loading percentages of all the partitions. - // If each partition's inMemory percentage is 100, that means all the partitions have finished loading. - // Otherwise, this thread will sleep a small interval and check again. - // If waiting time exceed timeout, exist the circle - while(true) { - long tsNow = System.currentTimeMillis(); - if ((tsNow - tsBegin) >= timeout*1000) { - logWarning("Waiting load thread is timeout, loading process may not be finished"); - break; - } - - ShowPartitionsResponse response = blockingStub().showPartitions(showPartitionsRequest); - int namesCount = response.getPartitionNamesCount(); - int percentagesCount = response.getInMemoryPercentagesCount(); - if (namesCount != percentagesCount) { - String msg = "ShowPartitionsResponse is illegal. Partition count: " + namesCount - + " memory percentages count: " + percentagesCount; - throw new IllegalResponseException(msg); - } - - // construct a hash map to check each partition's inMemory percentage by name - Map percentages = new HashMap<>(); - for (int i = 0; i < response.getInMemoryPercentagesCount(); ++i) { - percentages.put(response.getPartitionNames(i), response.getInMemoryPercentages(i)); - } - - String partitionNoMemState = ""; - String partitionNotFullyLoad = ""; - boolean allLoaded = true; - for (String name : partitionNames) { - if (!percentages.containsKey(name)) { - allLoaded = false; - partitionNoMemState = name; - break; - } - if (percentages.get(name) < 100L) { - allLoaded = false; - partitionNotFullyLoad = name; - break; - } - } - - if (allLoaded) { - break; - } - - try { - String msg = "Waiting load, interval: " + waitingInterval + "ms."; - if (!partitionNoMemState.isEmpty()) { - msg += ("Partition " + partitionNoMemState + " has no memory state."); - } - if (!partitionNotFullyLoad.isEmpty()) { - msg += ("Partition " + partitionNotFullyLoad + " has not fully loaded."); - } - logInfo(msg); - TimeUnit.MILLISECONDS.sleep(waitingInterval); - } catch (InterruptedException e) { - logWarning("Waiting load thread is interrupted, load process may not be finished"); - break; - } - } - } - } - - private void waitForFlush(FlushResponse flushResponse, long waitingInterval, long timeout) { - // The rpc api flush() return FlushResponse, but the returned segment ids maybe not yet persisted. - // This method use getPersistentSegmentInfo() to check segment state. - // If all segments state become Flushed, then we say the sync flush action is finished. - // If waiting time exceed timeout, exist the circle - long tsBegin = System.currentTimeMillis(); - Map collectionSegIDs = flushResponse.getCollSegIDsMap(); - collectionSegIDs.forEach((collectionName, segmentIDs) -> { - while (segmentIDs.getDataCount() > 0) { - long tsNow = System.currentTimeMillis(); - if ((tsNow - tsBegin) >= timeout*1000) { - logWarning("Waiting flush thread is timeout, flush process may not be finished"); - break; - } - - GetPersistentSegmentInfoRequest getSegInfoRequest = GetPersistentSegmentInfoRequest.newBuilder() - .setCollectionName(collectionName) - .build(); - GetPersistentSegmentInfoResponse response = blockingStub().getPersistentSegmentInfo(getSegInfoRequest); - List segmentInfoArray = response.getInfosList(); - int flushedCount = 0; - for (int i = 0; i < segmentIDs.getDataCount(); ++i) { - for (PersistentSegmentInfo info : segmentInfoArray) { - if (info.getSegmentID() == segmentIDs.getData(i) && info.getState() == SegmentState.Flushed) { - flushedCount++; - break; - } - } - } - - // if all segment of this collection has been flushed, break this circle and check next collection - if (flushedCount == segmentIDs.getDataCount()) { - break; - } - - try { - String msg = "Waiting flush, interval: " + waitingInterval + "ms. " + flushedCount + - " of " + segmentIDs.getDataCount() + " segments flushed."; - logInfo(msg); - TimeUnit.MILLISECONDS.sleep(waitingInterval); - } catch (InterruptedException e) { - logWarning("Waiting flush thread is interrupted, flush process may not be finished"); - break; - } - } - }); - } - - private R waitForIndex(String collectionName, String fieldName, long waitingInterval, long timeout) { - // This method use getIndexState() to check index state. - // If all index state become Finished, then we say the sync index action is finished. - // If waiting time exceed timeout, exist the circle - long tsBegin = System.currentTimeMillis(); - while (true) { - long tsNow = System.currentTimeMillis(); - if ((tsNow - tsBegin) >= timeout*1000) { - String msg = "Waiting index thread is timeout, index process may not be finished"; - logWarning(msg); - return R.failed(R.Status.Success, msg); - } - - GetIndexStateRequest request = GetIndexStateRequest.newBuilder() - .setCollectionName(collectionName) - .setFieldName(fieldName) - .build(); - - GetIndexStateResponse response = blockingStub().getIndexState(request); - if (response.getState() == IndexState.Finished) { - break; - } else if (response.getState() == IndexState.Failed) { - String msg = "Index failed: " + response.getFailReason(); - logError(msg); - return R.failed(R.Status.UnexpectedError, msg); - } - - try { - String msg = "Waiting index, interval: " + waitingInterval + "ms. "; - logInfo(msg); - TimeUnit.MILLISECONDS.sleep(waitingInterval); - } catch (InterruptedException e) { - String msg = "Waiting index thread is interrupted, index process may not be finished"; - logWarning(msg); - return R.failed(R.Status.Success, msg); - } - } - - return R.failed(R.Status.Success, "Waiting index thread exist"); - } - - ///////////////////// API implementation ////////////////////// - @Override - public R hasCollection(@NonNull HasCollectionParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - HasCollectionRequest hasCollectionRequest = HasCollectionRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .build(); - - BoolResponse response = blockingStub().hasCollection(hasCollectionRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("HasCollectionRequest successfully!"); - Boolean value = Optional.of(response) - .map(BoolResponse::getValue) - .orElse(false); - return R.success(value); - } else { - logError("HasCollectionRequest failed!\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("HasCollectionRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("HasCollectionRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R createCollection(@NonNull CreateCollectionParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - // Construct CollectionSchema Params - CollectionSchema.Builder collectionSchemaBuilder = CollectionSchema.newBuilder(); - collectionSchemaBuilder.setName(requestParam.getCollectionName()) - .setDescription(requestParam.getDescription()); - - long fieldID = 0; - for (FieldType fieldType : requestParam.getFieldTypes()) { - FieldSchema.Builder fieldSchemaBuilder = FieldSchema.newBuilder() - .setFieldID(fieldID) - .setName(fieldType.getName()) - .setIsPrimaryKey(fieldType.isPrimaryKey()) - .setDescription(fieldType.getDescription()) - .setDataType(fieldType.getDataType()) - .setAutoID(fieldType.isAutoID()); - - // assemble typeParams for CollectionSchema - List typeParamsList = assembleKvPair(fieldType.getTypeParams()); - if (CollectionUtils.isNotEmpty(typeParamsList)) { - typeParamsList.forEach(fieldSchemaBuilder::addTypeParams); - } - - collectionSchemaBuilder.addFields(fieldSchemaBuilder.build()); - fieldID++; - } - - // Construct CreateCollectionRequest - CreateCollectionRequest createCollectionRequest = CreateCollectionRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .setShardsNum(requestParam.getShardsNum()) - .setSchema(collectionSchemaBuilder.build().toByteString()) - .build(); - - Status response = blockingStub().createCollection(createCollectionRequest); - - if (response.getErrorCode() == ErrorCode.Success) { - logInfo("CreateCollectionRequest successfully! Collection name:{}", - requestParam.getCollectionName()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } else { - logError("CreateCollectionRequest failed!\n{}", response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - } catch (StatusRuntimeException e) { - logError("CreateCollectionRequest RPC failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("CreateCollectionRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R dropCollection(@NonNull DropCollectionParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - DropCollectionRequest dropCollectionRequest = DropCollectionRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .build(); - - Status response = blockingStub().dropCollection(dropCollectionRequest); - - if (response.getErrorCode() == ErrorCode.Success) { - logInfo("DropCollectionRequest successfully! Collection name:{}", - requestParam.getCollectionName()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } else { - logError("DropCollectionRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - } catch (StatusRuntimeException e) { - logError("DropCollectionRequest RPC failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("DropCollectionRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R loadCollection(@NonNull LoadCollectionParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - LoadCollectionRequest loadCollectionRequest = LoadCollectionRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .build(); - - Status response = blockingStub().loadCollection(loadCollectionRequest); - - if (response.getErrorCode() != ErrorCode.Success) { - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - - // sync load, wait until collection finish loading - if (requestParam.isSyncLoad()) { - waitForLoadingCollection(requestParam.getCollectionName(), null, - requestParam.getSyncLoadWaitingInterval(), requestParam.getSyncLoadWaitingTimeout()); - } - - logInfo("LoadCollectionRequest successfully! Collection name:{}", - requestParam.getCollectionName()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } catch (StatusRuntimeException e) { // gRPC could throw this exception - logError("LoadCollectionRequest RPC failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getStatus().toString()); - return R.failed(e); - } catch (IllegalResponseException e) { // milvus exception for illegal response - logError("LoadCollectionRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("LoadCollectionRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R releaseCollection(@NonNull ReleaseCollectionParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - ReleaseCollectionRequest releaseCollectionRequest = ReleaseCollectionRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .build(); - - Status response = blockingStub().releaseCollection(releaseCollectionRequest); - - if (response.getErrorCode() == ErrorCode.Success) { - logInfo("ReleaseCollectionRequest successfully! Collection name:{}", - requestParam.getCollectionName()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } else { - logError("ReleaseCollectionRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - } catch (StatusRuntimeException e) { - logError("ReleaseCollectionRequest RPC failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("ReleaseCollectionRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R describeCollection(@NonNull DescribeCollectionParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - DescribeCollectionRequest describeCollectionRequest = DescribeCollectionRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .build(); - - DescribeCollectionResponse response = blockingStub().describeCollection(describeCollectionRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("DescribeCollectionRequest successfully!"); - return R.success(response); - } else { - logError("DescribeCollectionRequest failed!\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("DescribeCollectionRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("DescribeCollectionRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R getCollectionStatistics(@NonNull GetCollectionStatisticsParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - // flush collection if client command to do it(some times user may want to know the newest row count) - if (requestParam.isFlushCollection()) { - R response = flush(FlushParam.newBuilder() - .addCollectionName(requestParam.getCollectionName()) - .withSyncFlush(Boolean.TRUE) - .build()); - if (response.getStatus() != R.Status.Success.getCode()) { - return R.failed(R.Status.valueOf(response.getStatus()), response.getMessage()); - } - } - - GetCollectionStatisticsRequest getCollectionStatisticsRequest = GetCollectionStatisticsRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .build(); - - GetCollectionStatisticsResponse response = blockingStub().getCollectionStatistics(getCollectionStatisticsRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("GetCollectionStatisticsRequest successfully!"); - return R.success(response); - } else { - logError("GetCollectionStatisticsRequest failed!\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("GetCollectionStatisticsRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("GetCollectionStatisticsRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R showCollections(@NonNull ShowCollectionsParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - ShowCollectionsRequest showCollectionsRequest = ShowCollectionsRequest.newBuilder() - .addAllCollectionNames(requestParam.getCollectionNames()) - .setType(requestParam.getShowType()).build(); - - ShowCollectionsResponse response = blockingStub().showCollections(showCollectionsRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("ShowCollectionsRequest successfully!"); - return R.success(response); - } else { - logError("ShowCollectionsRequest failed!\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("ShowCollectionsRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("ShowCollectionsRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - /** - * Currently we don't allow client call this method since server side has no compaction function - * Now this method is only internally used by getCollectionStatistics() - */ -// @Override - private R flush(@NonNull FlushParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - MsgBase msgBase = MsgBase.newBuilder().setMsgType(MsgType.Flush).build(); - FlushRequest flushRequest = FlushRequest.newBuilder() - .setBase(msgBase) - .addAllCollectionNames(requestParam.getCollectionNames()) - .build(); - FlushResponse response = blockingStub().flush(flushRequest); - - if (requestParam.getSyncFlush() == Boolean.TRUE) { - waitForFlush(response, requestParam.getSyncFlushWaitingInterval(), - requestParam.getSyncFlushWaitingTimeout()); - } - - logInfo("FlushRequest successfully! Collection names:{}", requestParam.getCollectionNames()); - return R.success(response); - } catch (StatusRuntimeException e) { - logError("FlushRequest RPC failed! Collection names:{}\n{}", - requestParam.getCollectionNames(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("FlushRequest failed! Collection names:{}\n{}", - requestParam.getCollectionNames(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R createPartition(@NonNull CreatePartitionParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - CreatePartitionRequest createPartitionRequest = CreatePartitionRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .setPartitionName(requestParam.getPartitionName()) - .build(); - - Status response = blockingStub().createPartition(createPartitionRequest); - - if (response.getErrorCode() == ErrorCode.Success) { - logInfo("CreatePartitionRequest successfully! Collection name:{}, partition name:{}", - requestParam.getCollectionName(), requestParam.getPartitionName()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } else { - logError("CreatePartitionRequest failed! Collection name:{}, partition name:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionName(), response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - } catch (StatusRuntimeException e) { - logError("CreatePartitionRequest RPC failed! Collection name:{}, partition name:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionName(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("CreatePartitionRequest failed! Collection name:{}, partition name:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionName(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R dropPartition(@NonNull DropPartitionParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - DropPartitionRequest dropPartitionRequest = DropPartitionRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .setPartitionName(requestParam.getPartitionName()) - .build(); - - Status response = blockingStub().dropPartition(dropPartitionRequest); - - if (response.getErrorCode() == ErrorCode.Success) { - logInfo("DropPartitionRequest successfully! Collection name:{}, partition name:{}", - requestParam.getCollectionName(), requestParam.getPartitionName()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } else { - logError("DropPartitionRequest failed! Collection name:{}, partition name:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionName(), response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - } catch (StatusRuntimeException e) { - logError("DropPartitionRequest RPC failed! Collection name:{}, partition name:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionName(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("DropPartitionRequest failed! Collection name:{}, partition name:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionName(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R hasPartition(@NonNull HasPartitionParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - HasPartitionRequest hasPartitionRequest = HasPartitionRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .setPartitionName(requestParam.getPartitionName()) - .build(); - - BoolResponse response = blockingStub().hasPartition(hasPartitionRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("HasPartitionRequest successfully!"); - Boolean result = response.getValue(); - return R.success(result); - } else { - logError("HasPartitionRequest failed!\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("HasPartitionRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("HasPartitionRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R loadPartitions(@NonNull LoadPartitionsParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - LoadPartitionsRequest loadPartitionsRequest = LoadPartitionsRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .addAllPartitionNames(requestParam.getPartitionNames()) - .build(); - - Status response = blockingStub().loadPartitions(loadPartitionsRequest); - - if (response.getErrorCode() != ErrorCode.Success) { - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - - // sync load, wait until all partitions finish loading - if (requestParam.isSyncLoad()) { - waitForLoadingCollection(requestParam.getCollectionName(), requestParam.getPartitionNames(), - requestParam.getSyncLoadWaitingInterval(), requestParam.getSyncLoadWaitingTimeout()); - } - - logInfo("LoadPartitionsRequest successfully! Collection name:{}, partition names:{}", - requestParam.getCollectionName(), requestParam.getPartitionNames()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } catch (StatusRuntimeException e) { // gRPC could throw this exception - logError("LoadPartitionsRequest RPC failed! Collection name:{}, partition names:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionNames(), e.getStatus().toString()); - return R.failed(e); - } catch (IllegalResponseException e) { // milvus exception for illegal response - logError("LoadPartitionsRequest failed! Collection name:{}, partition names:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionNames(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("LoadPartitionsRequest failed! Collection name:{}, partition names:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionNames(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R releasePartitions(@NonNull ReleasePartitionsParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - ReleasePartitionsRequest releasePartitionsRequest = ReleasePartitionsRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .addAllPartitionNames(requestParam.getPartitionNames()) - .build(); - - Status response = blockingStub().releasePartitions(releasePartitionsRequest); - - if (response.getErrorCode() == ErrorCode.Success) { - logInfo("ReleasePartitionsRequest successfully! Collection name:{}, partition names:{}", - requestParam.getCollectionName(), requestParam.getPartitionNames()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } else { - logError("ReleasePartitionsRequest failed! Collection name:{}, partition names:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionNames(), response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - } catch (StatusRuntimeException e) { - logError("ReleasePartitionsRequest RPC failed! Collection name:{}, partition names:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionNames(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("ReleasePartitionsRequest failed! Collection name:{}, partition names:{}\n{}", - requestParam.getCollectionName(), requestParam.getPartitionNames(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R getPartitionStatistics(@NonNull GetPartitionStatisticsParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - GetPartitionStatisticsRequest getPartitionStatisticsRequest = GetPartitionStatisticsRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .setPartitionName(requestParam.getPartitionName()) - .build(); - - GetPartitionStatisticsResponse response = - blockingStub().getPartitionStatistics(getPartitionStatisticsRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("GetPartitionStatisticsRequest successfully!"); - return R.success(response); - } else { - logError("ReleasePartitionsRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("GetPartitionStatisticsRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("GetQuerySegmentInfoRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R showPartitions(@NonNull ShowPartitionsParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - ShowPartitionsRequest showPartitionsRequest = ShowPartitionsRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .addAllPartitionNames(requestParam.getPartitionNames()) - .build(); - - ShowPartitionsResponse response = blockingStub().showPartitions(showPartitionsRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("ShowPartitionsRequest successfully!"); - return R.success(response); - } else { - logError("ShowPartitionsRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("ShowPartitionsRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("ShowPartitionsRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R createAlias(@NonNull CreateAliasParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - CreateAliasRequest createAliasRequest = CreateAliasRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .setAlias(requestParam.getAlias()) - .build(); - - Status response = blockingStub().createAlias(createAliasRequest); - - if (response.getErrorCode() == ErrorCode.Success) { - logInfo("CreateAliasRequest successfully! Collection name:{}, alias name:{}", - requestParam.getCollectionName(), requestParam.getAlias()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } else { - logError("CreateAliasRequest failed! Collection name:{}, alias name:{}\n{}", - requestParam.getCollectionName(), requestParam.getAlias(), response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - } catch (StatusRuntimeException e) { - logError("CreateAliasRequest RPC failed! Collection name:{}, alias name:{}\n{}", - requestParam.getCollectionName(), requestParam.getAlias(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("CreateAliasRequest failed! Collection name:{}, alias name:{}\n{}", - requestParam.getCollectionName(), requestParam.getAlias(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R dropAlias(@NonNull DropAliasParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - DropAliasRequest dropAliasRequest = DropAliasRequest.newBuilder() - .setAlias(requestParam.getAlias()) - .build(); - - Status response = blockingStub().dropAlias(dropAliasRequest); - - if (response.getErrorCode() == ErrorCode.Success) { - logInfo("DropAliasRequest successfully! Alias name:{}", requestParam.getAlias()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } else { - logError("DropAliasRequest failed! Alias name:{}\n{}", - requestParam.getAlias(), response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - } catch (StatusRuntimeException e) { - logError("DropAliasRequest RPC failed! Alias name:{}\n{}", - requestParam.getAlias(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("DropAliasRequest failed! Alias name:{}\n{}", - requestParam.getAlias(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R alterAlias(@NonNull AlterAliasParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - AlterAliasRequest alterAliasRequest = AlterAliasRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .setAlias(requestParam.getAlias()) - .build(); - - Status response = blockingStub().alterAlias(alterAliasRequest); - - if (response.getErrorCode() == ErrorCode.Success) { - logInfo("AlterAliasRequest successfully! Collection name:{}, alias name:{}", - requestParam.getCollectionName(), requestParam.getAlias()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } else { - logError("AlterAliasRequest failed! Collection name:{}, alias name:{}\n{}", - requestParam.getCollectionName(), requestParam.getAlias(), response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - } catch (StatusRuntimeException e) { - logError("AlterAliasRequest RPC failed! Collection name:{}, alias name:{}\n{}", - requestParam.getCollectionName(), requestParam.getAlias(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("AlterAliasRequest failed! Collection name:{}, alias name:{}\n{}", - requestParam.getCollectionName(), requestParam.getAlias(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R createIndex(@NonNull CreateIndexParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - CreateIndexRequest.Builder createIndexRequestBuilder = CreateIndexRequest.newBuilder(); - List extraParamList = assembleKvPair(requestParam.getExtraParam()); - - if (CollectionUtils.isNotEmpty(extraParamList)) { - extraParamList.forEach(createIndexRequestBuilder::addExtraParams); - } - - CreateIndexRequest createIndexRequest = createIndexRequestBuilder.setCollectionName(requestParam.getCollectionName()) - .setFieldName(requestParam.getFieldName()).build(); - - Status response = blockingStub().createIndex(createIndexRequest); - - if (response.getErrorCode() != ErrorCode.Success) { - logError("CreateIndexRequest failed! Collection name:{} Field name:{}\n{}", - requestParam.getCollectionName(), requestParam.getFieldName(), response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - - if (requestParam.isSyncMode()) { - R res = waitForIndex(requestParam.getCollectionName(), requestParam.getFieldName(), - requestParam.getSyncWaitingInterval(), requestParam.getSyncWaitingTimeout()); - if (res.getStatus() != R.Status.Success.getCode()) { - logError("CreateIndexRequest failed in sync mode! Collection name:{} Field name:{}\n{}", - requestParam.getCollectionName(), requestParam.getFieldName(), response.getReason()); - return R.failed(R.Status.valueOf(res.getStatus()), res.getMessage()); - } - } - - logInfo("CreateIndexRequest successfully! Collection name:{} Field name:{}", - requestParam.getCollectionName(), requestParam.getFieldName()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } catch (StatusRuntimeException e) { - logError("CreateIndexRequest RPC failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("CreateIndexRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R dropIndex(@NonNull DropIndexParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - DropIndexRequest dropIndexRequest = DropIndexRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .setFieldName(requestParam.getFieldName()) - .build(); - - Status response = blockingStub().dropIndex(dropIndexRequest); - - if (response.getErrorCode() == ErrorCode.Success) { - logInfo("DropIndexRequest successfully! Collection name:{}", - requestParam.getCollectionName()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } else { - logError("DropIndexRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - } catch (StatusRuntimeException e) { - logError("DropIndexRequest RPC failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("DropIndexRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R describeIndex(@NonNull DescribeIndexParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - DescribeIndexRequest describeIndexRequest = DescribeIndexRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .setFieldName(requestParam.getFieldName()) - .build(); - - DescribeIndexResponse response = blockingStub().describeIndex(describeIndexRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("DescribeIndexRequest successfully!"); - return R.success(response); - } else { - logError("DescribeIndexRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("DescribeIndexRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("DescribeIndexRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R getIndexState(@NonNull GetIndexStateParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - GetIndexStateRequest getIndexStateRequest = GetIndexStateRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .setFieldName(requestParam.getFieldName()) - .build(); - - GetIndexStateResponse response = blockingStub().getIndexState(getIndexStateRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("GetIndexStateRequest successfully!"); - return R.success(response); - } else { - logError("GetIndexStateRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("GetIndexStateRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("GetIndexStateRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R getIndexBuildProgress(@NonNull GetIndexBuildProgressParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - GetIndexBuildProgressRequest getIndexBuildProgressRequest = GetIndexBuildProgressRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .build(); - - GetIndexBuildProgressResponse response = blockingStub().getIndexBuildProgress(getIndexBuildProgressRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("GetIndexBuildProgressRequest successfully!"); - return R.success(response); - } else { - logError("GetIndexBuildProgressRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("GetIndexBuildProgressRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("GetIndexBuildProgressRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R delete(@NonNull DeleteParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - DeleteRequest deleteRequest = DeleteRequest.newBuilder() - .setBase(MsgBase.newBuilder().setMsgType(MsgType.Delete).build()) - .setCollectionName(requestParam.getCollectionName()) - .setPartitionName(requestParam.getPartitionName()) - .setExpr(requestParam.getExpr()) - .build(); - - MutationResult response = blockingStub().delete(deleteRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("DeleteRequest successfully! Collection name:{}", - requestParam.getCollectionName()); - return R.success(response); - } else { - logError("DeleteRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("DeleteRequest RPC failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getMessage()); - return R.failed(e); - } catch (Exception e) { - logError("DeleteRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getMessage()); - return R.failed(e); - } - } - - @Override - public R insert(@NonNull InsertParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - String collectionName = requestParam.getCollectionName(); - String partitionName = requestParam.getPartitionName(); - List fields = requestParam.getFields(); - - //1. gen insert request - MsgBase msgBase = MsgBase.newBuilder().setMsgType(MsgType.Insert).build(); - InsertRequest.Builder insertBuilder = InsertRequest.newBuilder() - .setCollectionName(collectionName) - .setPartitionName(partitionName) - .setBase(msgBase) - .setNumRows(requestParam.getRowCount()); - - //2. gen fieldData - // TODO: check field type(use DescribeCollection get schema to compare) - for (InsertParam.Field field : fields) { - insertBuilder.addFieldsData(genFieldData(field.getName(), field.getType(), field.getValues())); - } - - //3. call insert - InsertRequest insertRequest = insertBuilder.build(); - MutationResult response = blockingStub().insert(insertRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("InsertRequest successfully! Collection name:{}", - requestParam.getCollectionName()); - return R.success(response); - } else { - logError("InsertRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("InsertRequest RPC failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getMessage()); - return R.failed(e); - } catch (Exception e) { - logError("InsertRequest failed! Collection name:{}\n{}", - requestParam.getCollectionName(), e.getMessage()); - return R.failed(e); - } - } - - @Override - @SuppressWarnings("unchecked") - public R search(@NonNull SearchParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - SearchRequest.Builder builder = SearchRequest.newBuilder() - .setDbName("") - .setCollectionName(requestParam.getCollectionName()); - if (!requestParam.getPartitionNames().isEmpty()) { - requestParam.getPartitionNames().forEach(builder::addPartitionNames); - } - - // prepare target vectors - // TODO: check target vector dimension(use DescribeCollection get schema to compare) - PlaceholderType plType = PlaceholderType.None; - List vectors = requestParam.getVectors(); - List byteStrings = new ArrayList<>(); - for (Object vector : vectors) { - if (vector instanceof List) { - plType = PlaceholderType.FloatVector; - List list = (List) vector; - ByteBuffer buf = ByteBuffer.allocate(Float.BYTES * list.size()); - buf.order(ByteOrder.LITTLE_ENDIAN); - list.forEach(buf::putFloat); - - byte[] array = buf.array(); - ByteString bs = ByteString.copyFrom(array); - byteStrings.add(bs); - } else if (vector instanceof ByteBuffer) { - plType = PlaceholderType.BinaryVector; - ByteBuffer buf = (ByteBuffer) vector; - byte[] array = buf.array(); - ByteString bs = ByteString.copyFrom(array); - byteStrings.add(bs); - } else { - String msg = "Search target vector type is illegal(Only allow List or ByteBuffer)"; - logError(msg); - return R.failed(R.Status.UnexpectedError, msg); - } - } - - PlaceholderValue.Builder pldBuilder = PlaceholderValue.newBuilder() - .setTag(Constant.VECTOR_TAG) - .setType(plType); - byteStrings.forEach(pldBuilder::addValues); - - PlaceholderValue plv = pldBuilder.build(); - PlaceholderGroup placeholderGroup = PlaceholderGroup.newBuilder() - .addPlaceholders(plv) - .build(); - - ByteString byteStr = placeholderGroup.toByteString(); - builder.setPlaceholderGroup(byteStr); - - // search parameters - builder.addSearchParams( - KeyValuePair.newBuilder() - .setKey(Constant.VECTOR_FIELD) - .setValue(requestParam.getVectorFieldName()) - .build()) - .addSearchParams( - KeyValuePair.newBuilder() - .setKey(Constant.TOP_K) - .setValue(String.valueOf(requestParam.getTopK())) - .build()) - .addSearchParams( - KeyValuePair.newBuilder() - .setKey(Constant.METRIC_TYPE) - .setValue(requestParam.getMetricType()) - .build()) - .addSearchParams( - KeyValuePair.newBuilder() - .setKey(Constant.ROUND_DECIMAL) - .setValue(String.valueOf(requestParam.getRoundDecimal())) - .build()); - - if (null != requestParam.getParams() && !requestParam.getParams().isEmpty()) { - builder.addSearchParams( - KeyValuePair.newBuilder() - .setKey(Constant.PARAMS) - .setValue(requestParam.getParams()) - .build()); - } - - if (!requestParam.getOutFields().isEmpty()) { - requestParam.getOutFields().forEach(builder::addOutputFields); - } - - // always use expression since dsl is discarded - builder.setDslType(DslType.BoolExprV1); - if (requestParam.getExpr() != null && !requestParam.getExpr().isEmpty()) { - builder.setDsl(requestParam.getExpr()); - } - - SearchRequest searchRequest = builder.build(); - SearchResults response = this.blockingStub().search(searchRequest); - - //TODO: truncate distance value by round decimal - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("SearchRequest successfully!"); - return R.success(response); - } else { - logError("SearchRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("SearchRequest RPC failed:{}", e.getMessage()); - return R.failed(e); - } catch (Exception e) { - logError("SearchRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R query(@NonNull QueryParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - QueryRequest queryRequest = QueryRequest.newBuilder() - .setDbName("") - .setCollectionName(requestParam.getCollectionName()) - .addAllPartitionNames(requestParam.getPartitionNames()) - .addAllOutputFields(requestParam.getOutFields()) - .setExpr(requestParam.getExpr()) - .build(); - - QueryResults response = this.blockingStub().query(queryRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("QueryRequest successfully!"); - return R.success(response); - } else { - logError("QueryRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { -// e.printStackTrace(); - logError("QueryRequest RPC failed:{}", e.getMessage()); - return R.failed(e); - } catch (Exception e) { - logError("QueryRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R calcDistance(@NonNull CalcDistanceParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - List> vectors_left = requestParam.getVectorsLeft(); - List> vectors_right = requestParam.getVectorsRight(); - - FloatArray.Builder left_float_array = FloatArray.newBuilder(); - for (List vector : vectors_left) { - left_float_array.addAllData(vector); - } - - FloatArray.Builder right_float_array = FloatArray.newBuilder(); - for (List vector : vectors_right) { - right_float_array.addAllData(vector); - } - - CalcDistanceRequest calcDistanceRequest = CalcDistanceRequest.newBuilder() - .setOpLeft( - VectorsArray.newBuilder() - .setDataArray( - VectorField.newBuilder() - .setFloatVector(left_float_array.build()) - .setDim(vectors_left.get(0).size()) - .build() - ) - .build() - ) - .setOpRight( - VectorsArray.newBuilder() - .setDataArray( - VectorField.newBuilder() - .setFloatVector(right_float_array.build()) - .setDim(vectors_right.get(0).size()) - .build() - ) - .build() - ) - .addParams( - KeyValuePair.newBuilder() - .setKey("metric") - .setValue(requestParam.getMetricType()) - .build() - ) - .build(); - - CalcDistanceResults response = blockingStub().calcDistance(calcDistanceRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("CalcDistanceRequest successfully!"); - return R.success(response); - } else { - logError("CalcDistanceRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("CalcDistanceRequest RPC failed:{}", e.getMessage()); - return R.failed(e); - } catch (Exception e) { - logError("CalcDistanceRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R getMetrics(@NonNull GetMetricsParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - GetMetricsRequest getMetricsRequest = GetMetricsRequest.newBuilder() - .setRequest(requestParam.getRequest()) - .build(); - - GetMetricsResponse response = blockingStub().getMetrics(getMetricsRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("GetMetricsRequest successfully!"); - return R.success(response); - } else { - logError("GetMetricsRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("GetMetricsRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("GetMetricsRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R getPersistentSegmentInfo(@NonNull GetPersistentSegmentInfoParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - GetPersistentSegmentInfoRequest getSegmentInfoRequest = GetPersistentSegmentInfoRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .build(); - - GetPersistentSegmentInfoResponse response = blockingStub().getPersistentSegmentInfo(getSegmentInfoRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("GetPersistentSegmentInfoRequest successfully!"); - return R.success(response); - } else { - logError("GetPersistentSegmentInfoRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("GetPersistentSegmentInfoRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("GetPersistentSegmentInfoRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R getQuerySegmentInfo(@NonNull GetQuerySegmentInfoParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - GetQuerySegmentInfoRequest getSegmentInfoRequest = GetQuerySegmentInfoRequest.newBuilder() - .setCollectionName(requestParam.getCollectionName()) - .build(); - - GetQuerySegmentInfoResponse response = blockingStub().getQuerySegmentInfo(getSegmentInfoRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("GetQuerySegmentInfoRequest successfully!"); - return R.success(response); - } else { - logError("GetQuerySegmentInfoRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("GetQuerySegmentInfoRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("GetQuerySegmentInfoRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R loadBalance(LoadBalanceParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - LoadBalanceRequest loadBalanceRequest = LoadBalanceRequest.newBuilder() - .setSrcNodeID(requestParam.getSrcNodeID()) - .addAllDstNodeIDs(requestParam.getDestNodeIDs()) - .addAllSealedSegmentIDs(requestParam.getSegmentIDs()) - .build(); - - Status response = blockingStub().loadBalance(loadBalanceRequest); - - if (response.getErrorCode() == ErrorCode.Success) { - logInfo("LoadBalanceRequest successfully!"); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); - } else { - logError("LoadBalanceRequest failed! \n{}", response.getReason()); - return R.failed(R.Status.valueOf(response.getErrorCode().getNumber()), response.getReason()); - } - } catch (StatusRuntimeException e) { - logError("LoadBalanceRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("LoadBalanceRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R getCompactionState(GetCompactionStateParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - GetCompactionStateRequest getCompactionStateRequest = GetCompactionStateRequest.newBuilder() - .setCompactionID(requestParam.getCompactionID()) - .build(); - - GetCompactionStateResponse response = blockingStub().getCompactionState(getCompactionStateRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("GetCompactionStateRequest successfully!"); - return R.success(response); - } else { - logError("GetCompactionStateRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("GetCompactionStateRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("GetCompactionStateRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R manualCompaction(ManualCompactionParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - ManualCompactionRequest manualCompactionRequest = ManualCompactionRequest.newBuilder() - .setCollectionID(requestParam.getCollectionID()) - .build(); - - ManualCompactionResponse response = blockingStub().manualCompaction(manualCompactionRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("ManualCompactionRequest successfully!"); - return R.success(response); - } else { - logError("ManualCompactionRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("ManualCompactionRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("ManualCompactionRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - @Override - public R getCompactionStateWithPlans(GetCompactionPlansParam requestParam) { - if (!clientIsReady()) { - return R.failed(new ClientNotConnectedException("Client rpc channel is not ready")); - } - - logInfo(requestParam.toString()); - - try { - GetCompactionPlansRequest getCompactionPlansRequest = GetCompactionPlansRequest.newBuilder() - .setCompactionID(requestParam.getCompactionID()) - .build(); - - GetCompactionPlansResponse response = blockingStub().getCompactionStateWithPlans(getCompactionPlansRequest); - - if (response.getStatus().getErrorCode() == ErrorCode.Success) { - logInfo("GetCompactionPlansRequest successfully!"); - return R.success(response); - } else { - logError("GetCompactionPlansRequest failed:\n{}", response.getStatus().getReason()); - return R.failed(R.Status.valueOf(response.getStatus().getErrorCode().getNumber()), - response.getStatus().getReason()); - } - } catch (StatusRuntimeException e) { - logError("GetCompactionPlansRequest RPC failed:\n{}", e.getStatus().toString()); - return R.failed(e); - } catch (Exception e) { - logError("GetCompactionPlansRequest failed:\n{}", e.getMessage()); - return R.failed(e); - } - } - - ///////////////////// Log Functions////////////////////// - - private void logInfo(String msg, Object... params) { - logger.info(msg, params); - } - - private void logWarning(String msg, Object... params) { - logger.warn(msg, params); - } - - private void logError(String msg, Object... params) { - logger.error(msg, params); - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/client/MilvusClient.java b/milvus-java-sdk/src/main/java/io/milvus/client/MilvusClient.java deleted file mode 100644 index 2d1a3bc..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/client/MilvusClient.java +++ /dev/null @@ -1,345 +0,0 @@ -/* - * 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 - * - * 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; - -import io.milvus.grpc.*; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; -import io.milvus.param.alias.AlterAliasParam; -import io.milvus.param.alias.CreateAliasParam; -import io.milvus.param.alias.DropAliasParam; -import io.milvus.param.collection.*; -import io.milvus.param.control.*; -import io.milvus.param.dml.*; -import io.milvus.param.index.*; -import io.milvus.param.partition.*; - -import java.util.concurrent.TimeUnit; - -/** The Milvus Client Interface */ -public interface MilvusClient { - - /** Close Milvus client channel, timeout: 1 minute */ - default void close() { - try { - close(TimeUnit.MINUTES.toSeconds(1)); - } catch (InterruptedException e) { - System.out.println("Interrupted during shutdown Milvus client!"); - } - } - - /** - * Close Milvus client channel. - * - * @param maxWaitSeconds timeout unit: second - */ - void close(long maxWaitSeconds) throws InterruptedException; - - /** - * Check if a collection exists. - * - * @param requestParam {@link HasCollectionParam} - * @return {status:result code, data: boolean, whether if has collection or not} - */ - R hasCollection(HasCollectionParam requestParam); - - /** - * Create a collection in Milvus. - * - * @param requestParam {@link CreateCollectionParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R createCollection(CreateCollectionParam requestParam); - - /** - * Drop a collection. Note that this drops all data in the collection. - * - * @param requestParam {@link DropCollectionParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R dropCollection(DropCollectionParam requestParam); - - /** - * Load collection to cache before search/query. - * - * @param requestParam {@link LoadCollectionParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R loadCollection(LoadCollectionParam requestParam); - - /** - * Release a collection from cache to reduce cache usage. Note that you cannot - * search while the corresponding collection is unloaded. - * - * @param requestParam {@link ReleaseCollectionParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R releaseCollection(ReleaseCollectionParam requestParam); - - /** - * Show the details of a collection, e.g. name, schema. - * - * @param requestParam {@link DescribeCollectionParam} - * @return {status:result code, data:DescribeCollectionResponse{schema,collectionID}} - */ - R describeCollection(DescribeCollectionParam requestParam); - - /** - * Show the statistics information of a collection. - * - * @param requestParam {@link GetCollectionStatisticsParam} - * @return {status:result code, data: GetCollectionStatisticsResponse{status,stats}} - */ - R getCollectionStatistics(GetCollectionStatisticsParam requestParam); - - /** - * List all collections or get collection loading status. - * - * @param requestParam {@link ShowCollectionsParam} - * @return {status:result code, data: ShowCollectionsResponse{status,collection_names,collection_ids,created_timestamps,created_utc_timestamps}} - */ - R showCollections(ShowCollectionsParam requestParam); - -// /** -// * Flush collections. -// * Currently we don't allow client call this method since server side has no compaction function -// * -// * @param requestParam {@link FlushParam} -// * @return {status:result code,data: FlushResponse{flush segment ids}} -// */ -// R flush(FlushParam requestParam); - - /** - * Create a partition in a collection. - * - * @param requestParam {@link CreatePartitionParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R createPartition(CreatePartitionParam requestParam); - - /** - * To drop a partition will drop all data in this partition and the _default partition cannot be dropped. - * - * @param requestParam {@link DropPartitionParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R dropPartition(DropPartitionParam requestParam); - - /** - * Check if a partition exists in a collection. - * - * @param requestParam {@link HasPartitionParam} - * @return {status:result code, data: boolean, whether if has collection or not} - */ - R hasPartition(HasPartitionParam requestParam); - - /** - * Load a partition into cache. - * - * @param requestParam {@link LoadPartitionsParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R loadPartitions(LoadPartitionsParam requestParam); - - /** - * Release a partition from cache. - * - * @param requestParam {@link ReleasePartitionsParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R releasePartitions(ReleasePartitionsParam requestParam); - - /** - * Show the statistics information of a partition. - * - * @param requestParam {@link GetPartitionStatisticsParam} - * @return {status:result code,data:GetPartitionStatisticsResponse{status,stats}} - */ - R getPartitionStatistics(GetPartitionStatisticsParam requestParam); - - /** - * Show all partitions in a collection. - * - * @param requestParam {@link ShowPartitionsParam} - * @return {status:result code, data:ShowPartitionsResponse{partition_names,partitionIDs,created_timestamps,created_utc_timestamps}} - */ - R showPartitions(ShowPartitionsParam requestParam); - - /** - * Create an alias for a collection. - * Alias can be used in search/query to replace collection name - * - * @param requestParam {@link CreateAliasParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R createAlias(CreateAliasParam requestParam); - - /** - * Drop an alias. - * - * @param requestParam {@link DropAliasParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R dropAlias(DropAliasParam requestParam); - - /** - * Alter alias from a collection to another. - * - * @param requestParam {@link AlterAliasParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R alterAlias(AlterAliasParam requestParam); - - /** - * Create an index on a vector field. Note that index building is an async progress. - * - * @param requestParam {@link CreateIndexParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R createIndex(CreateIndexParam requestParam); - - /** - * Drop an index. - * - * @param requestParam {@link DropIndexParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R dropIndex(DropIndexParam requestParam); - - /** - * Show index information. Current release of Milvus only supports showing latest built index. - * - * @param requestParam {@link DescribeIndexParam} - * @return {status:result code, data:DescribeIndexResponse{status,index_descriptions}} - */ - R describeIndex(DescribeIndexParam requestParam); - - /** - * Show index building state(in-progress/finished/failed), failed reason. - * - * @param requestParam {@link GetIndexStateParam} - * @return {status:result code, data:GetIndexStateResponse{status,state}} - */ - R getIndexState(GetIndexStateParam requestParam); - - /** - * Show index building progress, such as how many rows are indexed. - * - * @param requestParam {@link GetIndexBuildProgressParam} - * @return {status:result code, data:GetIndexBuildProgressResponse{status,indexed_rows}} - */ - R getIndexBuildProgress(GetIndexBuildProgressParam requestParam); - - /** - * Insert entities into collection. Note that you don't need to input values for auto-id field. - * - * @param requestParam {@link InsertParam} - * @return {status:result code, data: MutationResult{insert results}} - */ - R insert(InsertParam requestParam); - - /** - * Delete entities by expression. Currently release of Milvus only support expression like "xxx in [1, 2, ...]" - * - * @param requestParam {@link DeleteParam} - * @return {status:result code, data: MutationResult{delete results}} - */ - R delete(DeleteParam requestParam); - - /** - * Do ANN search base on a vector field. Use expression to do filtering before search. - * - * @param requestParam {@link SearchParam} - * @return {status:result code, data: SearchResults{topK results}} - */ - R search(SearchParam requestParam); - - /** - * Query entities by expression. Note that the returned entities sequence cannot be guaranteed. - * - * @param requestParam {@link QueryParam} - * @return {status:result code,data: QueryResults{filter results}} - */ - R query(QueryParam requestParam); - - /** - * Calculate distance between specified vectors. - * - * @param requestParam {@link CalcDistanceParam} - * @return {status:result code, data: CalcDistanceResults{distances}} - */ - R calcDistance(CalcDistanceParam requestParam); - - /** - * Get runtime metrics information of Milvus, return in json format. - * - * @param requestParam {@link GetMetricsParam} - * @return {status:result code, data:GetMetricsResponse{status,metrics}} - */ - R getMetrics(GetMetricsParam requestParam); - - /** - * Get information of persistent segments, including row count, persist state(growing or flushed), etc. - * - * @param requestParam {@link GetPersistentSegmentInfoParam} - * @return {status:result code, data:GetPersistentSegmentInfoResponse{status,info}} - */ - R getPersistentSegmentInfo(GetPersistentSegmentInfoParam requestParam); - - /** - * Get query information of segments in a collection, including row count, mem size, index name, etc. - * - * @param requestParam {@link GetQuerySegmentInfoParam} - * @return {status:result code, data:GetQuerySegmentInfoResponse{status,info}} - */ - R getQuerySegmentInfo(GetQuerySegmentInfoParam requestParam); - - /** - * Move segment from a query node to another, to keep load balance. - * - * @param requestParam {@link LoadBalanceParam} - * @return {status:result code, data:RpcStatus{msg: result message}} - */ - R loadBalance(LoadBalanceParam requestParam); - - /** - * Get compaction action state by id. - * - * @param requestParam {@link GetCompactionStateParam} - * @return {status:result code, data:GetCompactionStateResponse{status,info}} - */ - R getCompactionState(GetCompactionStateParam requestParam); - - /** - * Ask server to perform a compaction action. - * - * @param requestParam {@link ManualCompactionParam} - * @return {status:result code, data:ManualCompactionResponse{status,info}} - */ - R manualCompaction(ManualCompactionParam requestParam); - - /** - * Get compaction action state with its plan. - * - * @param requestParam {@link GetCompactionPlansParam} - * @return {status:result code, data:GetCompactionPlansResponse{status,info}} - */ - R getCompactionStateWithPlans(GetCompactionPlansParam requestParam); -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/client/MilvusServiceClient.java b/milvus-java-sdk/src/main/java/io/milvus/client/MilvusServiceClient.java deleted file mode 100644 index 763a06b..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/client/MilvusServiceClient.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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 - * - * 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; - -import io.grpc.ConnectivityState; -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import io.milvus.grpc.MilvusServiceGrpc; -import io.milvus.param.ConnectParam; - -import lombok.NonNull; -import java.util.concurrent.TimeUnit; - -public class MilvusServiceClient extends AbstractMilvusGrpcClient { - - private final ManagedChannel channel; - private final MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub; - private final MilvusServiceGrpc.MilvusServiceFutureStub futureStub; - - public MilvusServiceClient(@NonNull ConnectParam connectParam) { - channel = ManagedChannelBuilder.forAddress(connectParam.getHost(), connectParam.getPort()) - .usePlaintext() - .maxInboundMessageSize(Integer.MAX_VALUE) - .keepAliveTime(connectParam.getKeepAliveTimeMs(), TimeUnit.MILLISECONDS) - .keepAliveTimeout(connectParam.getKeepAliveTimeoutMs(), TimeUnit.MILLISECONDS) - .keepAliveWithoutCalls(connectParam.isKeepAliveWithoutCalls()) - .idleTimeout(connectParam.getIdleTimeoutMs(), TimeUnit.MILLISECONDS) - .build(); - blockingStub = MilvusServiceGrpc.newBlockingStub(channel); - futureStub = MilvusServiceGrpc.newFutureStub(channel); - } - - @Override - protected MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub() { - return this.blockingStub; - } - - @Override - protected MilvusServiceGrpc.MilvusServiceFutureStub futureStub() { - return this.futureStub; - } - - @Override - protected boolean clientIsReady() { - ConnectivityState state = channel.getState(false); - return state != ConnectivityState.SHUTDOWN; - } - - @Override - public void close(long maxWaitSeconds) throws InterruptedException { - channel.shutdownNow(); - channel.awaitTermination(maxWaitSeconds, TimeUnit.SECONDS); - } -} - diff --git a/milvus-java-sdk/src/main/java/io/milvus/exception/ClientNotConnectedException.java b/milvus-java-sdk/src/main/java/io/milvus/exception/ClientNotConnectedException.java deleted file mode 100644 index ea2575d..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/exception/ClientNotConnectedException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 - * - * 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.exception; - -import io.milvus.param.R; - -/** - * Milvus client api throws this exception when client channel is closed. - */ -public class ClientNotConnectedException extends MilvusException { - public ClientNotConnectedException(String msg) { - super(msg, R.Status.ClientNotConnected.getCode()); - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/exception/IllegalResponseException.java b/milvus-java-sdk/src/main/java/io/milvus/exception/IllegalResponseException.java deleted file mode 100644 index 86a257f..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/exception/IllegalResponseException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 - * - * 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.exception; - -import io.milvus.param.R; - -/** - * Some interfaces including search/search/loadCollection can throw this exception - * when server return illegal response, this may indicate a bug of server. - */ -public class IllegalResponseException extends MilvusException { - public IllegalResponseException(String msg) { - super(msg, R.Status.IllegalResponse.getCode()); - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/exception/MilvusException.java b/milvus-java-sdk/src/main/java/io/milvus/exception/MilvusException.java deleted file mode 100644 index 9e12c65..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/exception/MilvusException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 - * - * 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.exception; - -/** - * Base class of Milvus exceptions. - */ -public abstract class MilvusException extends RuntimeException { - protected Integer status; - - public MilvusException(String msg, Integer status) { - super(msg); - this.status = status; - } - - public Integer getStatus() { - return status; - } - - public void setStatus(Integer status) { - this.status = status; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/exception/ParamException.java b/milvus-java-sdk/src/main/java/io/milvus/exception/ParamException.java deleted file mode 100644 index fb6fb12..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/exception/ParamException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 - * - * 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.exception; - -import io.milvus.param.R; - -/** - * Exception for caller input illegal parameters. - */ -public class ParamException extends MilvusException { - public ParamException(String msg) { - super(msg, R.Status.ParamError.getCode()); - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/ConnectParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/ConnectParam.java deleted file mode 100644 index 188e962..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/ConnectParam.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * 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 - * - * 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.param; - -import io.milvus.exception.ParamException; - -import lombok.NonNull; -import java.util.concurrent.TimeUnit; - -/** - * Parameters for client connection. - */ -public class ConnectParam { - private final String host; - private final int port; - private final long connectTimeoutMs; - private final long keepAliveTimeMs; - private final long keepAliveTimeoutMs; - private final boolean keepAliveWithoutCalls; - private final long idleTimeoutMs; - - private ConnectParam(@NonNull Builder builder) { - this.host = builder.host; - this.port = builder.port; - this.connectTimeoutMs = builder.connectTimeoutMs; - this.keepAliveTimeMs = builder.keepAliveTimeMs; - this.keepAliveTimeoutMs = builder.keepAliveTimeoutMs; - this.keepAliveWithoutCalls = builder.keepAliveWithoutCalls; - this.idleTimeoutMs = builder.idleTimeoutMs; - } - - public String getHost() { - return host; - } - - public int getPort() { - return port; - } - - public long getConnectTimeoutMs() { - return connectTimeoutMs; - } - - public long getKeepAliveTimeMs() { - return keepAliveTimeMs; - } - - public long getKeepAliveTimeoutMs() { - return keepAliveTimeoutMs; - } - - public boolean isKeepAliveWithoutCalls() { - return keepAliveWithoutCalls; - } - - public long getIdleTimeoutMs() { - return idleTimeoutMs; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for ConnectParam - */ - public static class Builder { - private String host = "localhost"; - private int port = 19530; - private long connectTimeoutMs = 10000; - private long keepAliveTimeMs = Long.MAX_VALUE; // Disabling keep alive - private long keepAliveTimeoutMs = 20000; - private boolean keepAliveWithoutCalls = false; - private long idleTimeoutMs = TimeUnit.MILLISECONDS.convert(24, TimeUnit.HOURS); - - private Builder() { - } - - /** - * Set host name/address. - * - * @param host host name/address - * @return Builder - */ - public Builder withHost(@NonNull String host) { - this.host = host; - return this; - } - - /** - * Set connection port. Port value must be larger than zero and less than 65536. - * - * @param port port value - * @return Builder - */ - public Builder withPort(int port) { - this.port = port; - return this; - } - - /** - * Set connect time out value of client channel. The time out value must be larger than zero. - * - * @param connectTimeout time out value - * @param timeUnit time out unit - * @return Builder - */ - public Builder withConnectTimeout(long connectTimeout, @NonNull TimeUnit timeUnit) { - this.connectTimeoutMs = timeUnit.toMillis(connectTimeout); - return this; - } - - /** - * Set keep alive time value of client channel. The time out value must be larger than zero. - * - * @param keepAliveTime time out value - * @param timeUnit time out unit - * @return Builder - */ - public Builder withKeepAliveTime(long keepAliveTime, @NonNull TimeUnit timeUnit) { - this.keepAliveTimeMs = timeUnit.toMillis(keepAliveTime); - return this; - } - - /** - * Set keep alive time out value of client channel. The time out value must be larger than zero. - * - * @param keepAliveTimeout time out value - * @param timeUnit time out unit - * @return Builder - */ - public Builder withKeepAliveTimeout(long keepAliveTimeout, @NonNull TimeUnit timeUnit) { - this.keepAliveTimeoutMs = timeUnit.toNanos(keepAliveTimeout); - return this; - } - - /** - * Set client channel keep alive. - * - * @param enable true keep alive - * @return Builder - */ - public Builder keepAliveWithoutCalls(boolean enable) { - keepAliveWithoutCalls = enable; - return this; - } - - /** - * Set idle time out value of client channel. The time out value must be larger than zero. - * - * @param idleTimeout time out value - * @param timeUnit time out unit - * @return Builder - */ - public Builder withIdleTimeout(long idleTimeout, @NonNull TimeUnit timeUnit) { - this.idleTimeoutMs = timeUnit.toMillis(idleTimeout); - return this; - } - - /** - * Verify parameters and create a new ConnectParam instance. - * - * @return ShowCollectionsParam - */ - public ConnectParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(host, "Host name"); - - if (port < 0 || port > 0xFFFF) { - throw new ParamException("Port is out of range!"); - } - - if (keepAliveTimeMs <= 0L) { - throw new ParamException("Keep alive time must be positive!"); - } - - if (connectTimeoutMs <= 0L) { - throw new ParamException("Connect timeout must be positive!"); - } - - if (keepAliveTimeoutMs <= 0L) { - throw new ParamException("Keep alive timeout must be positive!"); - } - - if (idleTimeoutMs <= 0L) { - throw new ParamException("Idle timeout must be positive!"); - } - - return new ConnectParam(this); - } - } - - /** - * Construct a String by ConnectParam instance. - * - * @return String - */ - @Override - public String toString() { - return "ConnectParam{" + - "host='" + host + '\'' + - ", port='" + port + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/Constant.java b/milvus-java-sdk/src/main/java/io/milvus/param/Constant.java deleted file mode 100644 index a2ed55e..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/Constant.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 - * - * 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.param; - -/** - * Constant/static values for internal usage. - */ -public class Constant { - // default value for search key - public static final String VECTOR_TAG = "$0"; - public static final String VECTOR_FIELD = "anns_field"; - public static final String VECTOR_DIM = "dim"; - public static final String TOP_K = "topk"; - public static final String INDEX_TYPE = "index_type"; - public static final String METRIC_TYPE = "metric_type"; - public static final String ROUND_DECIMAL = "round_decimal"; - public static final String PARAMS = "params"; - - // max value for waiting loading collection/partition interval, unit: millisecond - public static final Long MAX_WAITING_LOADING_INTERVAL = 2000L; - - // max value for waiting loading collection/partition timeout, unit: second - public static final Long MAX_WAITING_LOADING_TIMEOUT = 300L; - - // max value for waiting flushing collection/partition interval, unit: millisecond - public static final Long MAX_WAITING_FLUSHING_INTERVAL = 2000L; - - // max value for waiting flushing collection/partition timeout, unit: second - public static final Long MAX_WAITING_FLUSHING_TIMEOUT = 300L; - - // max value for waiting create index interval, unit: millisecond - public static final Long MAX_WAITING_INDEX_INTERVAL = 2000L; -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/IndexType.java b/milvus-java-sdk/src/main/java/io/milvus/param/IndexType.java deleted file mode 100644 index e2f2a0c..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/IndexType.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 - * - * 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.param; - -/** - * Represents available index types. - * For more information: @see Index Types - */ -public enum IndexType { - INVALID, - IVF_FLAT, - IVF_PQ, - IVF_SQ8, - HNSW, - RHNSW_FLAT, - RHNSW_PQ, - RHNSW_SQ, - ANNOY, - //Only supported for binary vectors - BIN_IVF_FLAT, - ; -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/MetricType.java b/milvus-java-sdk/src/main/java/io/milvus/param/MetricType.java deleted file mode 100644 index 092e47d..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/MetricType.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 - * - * 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.param; - -/** - * Represents available metric types. - * For more information: @see Similarity Metrics - */ -public enum MetricType { - INVALID, - L2, - IP, - // Only supported for binary vectors - HAMMING, - JACCARD, - TANIMOTO, - SUBSTRUCTURE, - SUPERSTRUCTURE, - ; -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/ParamUtils.java b/milvus-java-sdk/src/main/java/io/milvus/param/ParamUtils.java deleted file mode 100644 index c8bfead..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/ParamUtils.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.milvus.param; - -import io.milvus.exception.ParamException; -import org.apache.commons.lang3.StringUtils; - -/** - * Util functions for param classes - */ -public class ParamUtils { - /** - * Check a string is empty or null. - * Throws {@link ParamException} if the string is empty of null. - * - * @param target target string - * @param name a name to describe this string - */ - public static void CheckNullEmptyString(String target, String name) throws ParamException { - if (target == null || StringUtils.isBlank(target)) { - throw new ParamException(name + " cannot be null or empty"); - } - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/R.java b/milvus-java-sdk/src/main/java/io/milvus/param/R.java deleted file mode 100644 index dd8cccf..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/R.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * 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 - * - * 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.param; - -import io.milvus.exception.MilvusException; -import io.milvus.grpc.ErrorCode; -import org.apache.commons.lang3.exception.ExceptionUtils; - -import java.util.Arrays; -import java.util.Optional; - -/** - * Util class to wrap gpc response and exceptions. - */ -public class R { - private Exception exception; - private Integer status; - private T data; - - public Exception getException() { - return exception; - } - - public void setException(Exception exception) { - this.exception = exception; - } - - public String getMessage() { return exception.getMessage(); } - - public Integer getStatus() { - return status; - } - - public void setStatus(Integer status) { - this.status = status; - } - - public T getData() { - return data; - } - - public void setData(T data) { - this.data = data; - } - - /** - * Wrap an exception for failure. - * - * @param exception exception object - * @return R - */ - public static R failed(Exception exception) { - R r = new R<>(); - if (exception instanceof MilvusException) { - MilvusException e = (MilvusException) exception; - r.setStatus(e.getStatus()); - } else { - r.setStatus(Status.Unknown.getCode()); - r.exception = exception; - } - r.setException(exception); - return r; - } - - /** - * Wrap an error code and error message for failure. - * - * @param errorCode rpc error code - * @param msg error message - * @return R - */ - public static R failed(ErrorCode errorCode, String msg) { - R r = new R<>(); - r.setStatus(errorCode.ordinal()); - r.setException(new Exception(msg)); - return r; - } - - /** - * Wrap a status code and error message for failure. - * - * @param statusCode status code - * @param msg error message - * @return R - */ - public static R failed(Status statusCode, String msg) { - R r = new R<>(); - r.setStatus(statusCode.getCode()); - r.setException(new Exception(msg)); - return r; - } - - /** - * Direct return a succeed status. - * - * @return R - */ - public static R success() { - R r = new R<>(); - r.setStatus(Status.Success.getCode()); - return r; - } - - /** - * Wrap a succeed rpc response object. - * - * @param data rpc response object - * @return R - */ - public static R success(T data) { - R r = new R<>(); - r.setStatus(Status.Success.getCode()); - r.setData(data); - return r; - } - - /** - * Represents server and client side status code - */ - public enum Status { - // Server side error - Success(0), - UnexpectedError(1), - ConnectFailed(2), - PermissionDenied(3), - CollectionNotExists(4), - IllegalArgument(5), - IllegalDimension(7), - IllegalIndexType(8), - IllegalCollectionName(9), - IllegalTOPK(10), - IllegalRowRecord(11), - IllegalVectorID(12), - IllegalSearchResult(13), - FileNotFound(14), - MetaFailed(15), - CacheFailed(16), - CannotCreateFolder(17), - CannotCreateFile(18), - CannotDeleteFolder(19), - CannotDeleteFile(20), - BuildIndexError(21), - IllegalNLIST(22), - IllegalMetricType(23), - OutOfMemory(24), - IndexNotExist(25), - EmptyCollection(26), - - // internal error code. - DDRequestRace(1000), - - // Client side error - RpcError(-1), - ClientNotConnected(-2), - Unknown(-3), - VersionMismatch(-4), - ParamError(-5), - IllegalResponse(-6); - - private final int code; - - Status(int code) { - this.code = code; - } - - public static Status valueOf(int val) { - Optional search = - Arrays.stream(values()).filter(status -> status.code == val).findFirst(); - return search.orElse(Unknown); - } - - public int getCode() { - return code; - } - } - - /** - * Construct a String by R instance. - * - * @return String - */ - @Override - public String toString() { - if (exception != null) { - return "R{" + - "exception=" + ExceptionUtils.getMessage(exception) + - ", status=" + status + - ", data=" + data + - '}'; - } else { - return "R{" + - "status=" + status + - ", data=" + data + - '}'; - } - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/RpcStatus.java b/milvus-java-sdk/src/main/java/io/milvus/param/RpcStatus.java deleted file mode 100644 index 19fe25f..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/RpcStatus.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 - * - * 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.param; - -/** - * Util class to wrap a message. - */ -public class RpcStatus { - public static final String SUCCESS_MSG = "Success"; - - private final String msg; - - public String getMsg() { - return msg; - } - - public RpcStatus(String msg) { - this.msg = msg; - } - - /** - * Construct a String by RpcStatus instance. - * - * @return String - */ - @Override - public String toString() { - return "RpcStatus{" + - "msg='" + getMsg() + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/alias/AlterAliasParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/alias/AlterAliasParam.java deleted file mode 100644 index 0edbed5..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/alias/AlterAliasParam.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.milvus.param.alias; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for alterAlias interface. - */ -@Getter -public class AlterAliasParam { - private final String collectionName; - private final String alias; - - private AlterAliasParam(@NonNull AlterAliasParam.Builder builder) { - this.collectionName = builder.collectionName; - this.alias = builder.alias; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for AlterAliasParam class. - */ - public static final class Builder { - private String collectionName; - private String alias; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set alias, alias cannot be empty or null. - * - * @param alias alias of the collection - * @return Builder - */ - public Builder withAlias(@NonNull String alias) { - this.alias = alias; - return this; - } - - /** - * Verify parameters and create a new AlterAliasParam instance. - * - * @return AlterAliasParam - */ - public AlterAliasParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(alias, "Alias"); - - return new AlterAliasParam(this); - } - } - - /** - * Construct a String by AlterAliasParam instance. - * - * @return String - */ - @Override - public String toString() { - return "AlterAliasParam{" + - "collectionName='" + collectionName + '\'' + - ", alias='" + alias + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/alias/CreateAliasParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/alias/CreateAliasParam.java deleted file mode 100644 index ca40bec..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/alias/CreateAliasParam.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.milvus.param.alias; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for createAlias interface. - */ -@Getter -public class CreateAliasParam { - private final String collectionName; - private final String alias; - - private CreateAliasParam(@NonNull CreateAliasParam.Builder builder) { - this.collectionName = builder.collectionName; - this.alias = builder.alias; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for CreateAliasParam class. - */ - public static final class Builder { - private String collectionName; - private String alias; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set alias, alias cannot be empty or null. - * - * @param alias alias of the collection - * @return Builder - */ - public Builder withAlias(@NonNull String alias) { - this.alias = alias; - return this; - } - - /** - * Verify parameters and create a new CreateAliasParam instance. - * - * @return CreateAliasParam - */ - public CreateAliasParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(alias, "Alias"); - - return new CreateAliasParam(this); - } - } - - /** - * Construct a String by CreateAliasParam instance. - * - * @return String - */ - @Override - public String toString() { - return "CreateAliasParam{" + - "collectionName='" + collectionName + '\'' + - ", alias='" + alias + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/alias/DropAliasParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/alias/DropAliasParam.java deleted file mode 100644 index 6382d7f..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/alias/DropAliasParam.java +++ /dev/null @@ -1,67 +0,0 @@ -package io.milvus.param.alias; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for dropAlias interface. - */ -@Getter -public class DropAliasParam { - private final String alias; - - private DropAliasParam(@NonNull Builder builder) { - this.alias = builder.alias; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for DropAliasParam class. - */ - public static final class Builder { - private String alias; - - private Builder() { - } - - /** - * Set alias, alias cannot be empty or null. - * - * @param alias alias of the collection - * @return Builder - */ - public Builder withAlias(@NonNull String alias) { - this.alias = alias; - return this; - } - - /** - * Verify parameters and create a new DropAliasParam instance. - * - * @return DropAliasParam - */ - public DropAliasParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(alias, "Alias"); - - return new DropAliasParam(this); - } - } - - /** - * Construct a String by DropAliasParam instance. - * - * @return String - */ - @Override - public String toString() { - return "DropAliasParam{" + - ", alias='" + alias + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/collection/CreateCollectionParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/collection/CreateCollectionParam.java deleted file mode 100644 index ba2728c..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/collection/CreateCollectionParam.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * 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 - * - * 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.param.collection; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; -import java.util.ArrayList; -import java.util.List; - -/** - * Parameters for createCollection interface. - */ -@Getter -public class CreateCollectionParam { - private final String collectionName; - private final int shardsNum; - private final String description; - private final List fieldTypes; - - private CreateCollectionParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.shardsNum = builder.shardsNum; - this.description = builder.description; - this.fieldTypes = builder.fieldTypes; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for CreateCollectionParam class. - */ - public static final class Builder { - private String collectionName; - private int shardsNum = 2; - private String description = ""; - private final List fieldTypes = new ArrayList<>(); - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set shards number, the number must be larger than zero, default value is 2. - * - * @param shardsNum shards number to distribute insert data into multiple data nodes and query nodes. - * @return Builder - */ - public Builder withShardsNum(int shardsNum) { - this.shardsNum = shardsNum; - return this; - } - - /** - * Set collection description, description can be empty, default is "". - * - * @param description description of the collection - * @return Builder - */ - public Builder withDescription(@NonNull String description) { - this.description = description; - return this; - } - - /** - * Set schema of the collection, schema cannot be empty or null. - * @see FieldType - * - * @param fieldTypes a List of FieldType - * @return Builder - */ - public Builder withFieldTypes(@NonNull List fieldTypes) { - this.fieldTypes.addAll(fieldTypes); - return this; - } - - /** - * Add a field schema. - * @see FieldType - * - * @param fieldType a FieldType object - * @return Builder - */ - public Builder addFieldType(@NonNull FieldType fieldType) { - this.fieldTypes.add(fieldType); - return this; - } - - /** - * Verify parameters and create a new CreateCollectionParam instance. - * - * @return CreateCollectionParam - */ - public CreateCollectionParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - if (shardsNum <= 0) { - throw new ParamException("ShardNum must be larger than 0"); - } - - if (fieldTypes == null || fieldTypes.isEmpty()) { - throw new ParamException("Field numbers must be larger than 0"); - } - - for (FieldType fieldType : fieldTypes) { - if (fieldType == null) { - throw new ParamException("Collection field cannot be null"); - } - } - - return new CreateCollectionParam(this); - } - } - - /** - * Construct a String by CreateCollectionParam instance. - * - * @return String - */ - @Override - public String toString() { - return "CreateCollectionParam{" + - "collectionName='" + collectionName + '\'' + - ", shardsNum=" + shardsNum + - ", description='" + description + '\'' + - ", field count=" + fieldTypes.size() + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/collection/DescribeCollectionParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/collection/DescribeCollectionParam.java deleted file mode 100644 index d327c4e..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/collection/DescribeCollectionParam.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 - * - * 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.param.collection; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for describeCollection interface. - */ -@Getter -public class DescribeCollectionParam { - private final String collectionName; - - private DescribeCollectionParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for DescribeCollectionParam class. - */ - public static final class Builder { - private String collectionName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Verify parameters and create a new DescribeCollectionParam instance. - * - * @return DescribeCollectionParam - */ - public DescribeCollectionParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - return new DescribeCollectionParam(this); - } - } - - /** - * Construct a String by DescribeCollectionParam instance. - * - * @return String - */ - @Override - public String toString() { - return "DescribeCollectionParam{" + - "collectionName='" + collectionName + '\'' + '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/collection/DropCollectionParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/collection/DropCollectionParam.java deleted file mode 100644 index a2265c8..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/collection/DropCollectionParam.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 - * - * 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.param.collection; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for dropCollection interface. - */ -@Getter -public class DropCollectionParam { - private final String collectionName; - - private DropCollectionParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for DropCollectionParam class. - */ - public static final class Builder { - private String collectionName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Verify parameters and create a new DropCollectionParam instance. - * - * @return DropCollectionParam - */ - public DropCollectionParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - return new DropCollectionParam(this); - } - } - - /** - * Construct a String by DropCollectionParam instance. - * - * @return String - */ - @Override - public String toString() { - return "DropCollectionParam{" + - "collectionName='" + collectionName + '\'' + '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/collection/FieldType.java b/milvus-java-sdk/src/main/java/io/milvus/param/collection/FieldType.java deleted file mode 100644 index adcca59..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/collection/FieldType.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * 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 - * - * 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.param.collection; - -import io.milvus.exception.ParamException; -import io.milvus.grpc.DataType; -import io.milvus.param.Constant; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; -import java.util.HashMap; -import java.util.Map; - -/** - * Parameters for a collection field. - * @see CreateCollectionParam - */ -@Getter -public class FieldType { - private final String name; - private final boolean primaryKey; - private final String description; - private final DataType dataType; - private final Map typeParams; - private final boolean autoID; - - private FieldType(@NonNull Builder builder){ - this.name = builder.name; - this.primaryKey = builder.primaryKey; - this.description = builder.description; - this.dataType = builder.dataType; - this.typeParams = builder.typeParams; - this.autoID = builder.autoID; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for FieldType class. - */ - public static final class Builder { - private String name; - private boolean primaryKey = false; - private String description = ""; - private DataType dataType; - private final Map typeParams = new HashMap<>(); - private boolean autoID = false; - - private Builder() { - } - - public Builder withName(@NonNull String name) { - this.name = name; - return this; - } - - /** - * Set field to be primary key. - * Note that currently Milvus version only support Long data type as primary key. - * - * @param primaryKey true is primary key, false is not - * @return Builder - */ - public Builder withPrimaryKey(boolean primaryKey) { - this.primaryKey = primaryKey; - return this; - } - - /** - * Set field description, description can be empty, default is "". - * - * @param description description of the field - * @return Builder - */ - public Builder withDescription(@NonNull String description) { - this.description = description; - return this; - } - - /** - * Set data type for field. - * - * @param dataType data type of the field - * @return Builder - */ - public Builder withDataType(@NonNull DataType dataType) { - this.dataType = dataType; - return this; - } - - /** - * Add a parameter pair for field. - * - * @param key parameter key - * @param value parameter value - * @return Builder - */ - public Builder addTypeParam(@NonNull String key, @NonNull String value) { - this.typeParams.put(key, value); - return this; - } - - /** - * Set more parameters for field. - * - * @param typeParams parameters of the field - * @return Builder - */ - public Builder withTypeParams(@NonNull Map typeParams) { - typeParams.forEach(this.typeParams::put); - return this; - } - - /** - * Set dimension of a vector field. Dimension value must be larger than zero. - * - * @param dimension dimension of the field - * @return Builder - */ - public Builder withDimension(@NonNull Integer dimension) { - this.typeParams.put(Constant.VECTOR_DIM, dimension.toString()); - return this; - } - - /** - * Set the field to be auto-id. Note that only primary key field can be set as auto-id. - * If auto-id is enabled, Milvus will automatically generated unique id for each entities, - * user no need to provide values for this field during insert action. - * - * If auto-id is disabled, user need to provide values for this field during insert action. - * - * @param autoID true enable auto-id, false disable auto-id - * @return Builder - */ - public Builder withAutoID(boolean autoID) { - this.autoID = autoID; - return this; - } - - /** - * Verify parameters and create a new FieldType instance. - * - * @return FieldType - */ - public FieldType build() throws ParamException { - ParamUtils.CheckNullEmptyString(name, "Field name"); - - if (dataType == null || dataType == DataType.None) { - throw new ParamException("Field data type is illegal"); - } - - if (dataType == DataType.FloatVector || dataType == DataType.BinaryVector) { - if (!typeParams.containsKey(Constant.VECTOR_DIM)) { - throw new ParamException("Vector field dimension must be specified"); - } - - try { - int dim = Integer.parseInt(typeParams.get(Constant.VECTOR_DIM)); - if (dim <= 0) { - throw new ParamException("Vector field dimension must be larger than zero"); - } - } catch (NumberFormatException e) { - throw new ParamException("Vector field dimension must be an integer number"); - } - } - - return new FieldType(this); - } - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/collection/FlushParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/collection/FlushParam.java deleted file mode 100644 index d9728a4..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/collection/FlushParam.java +++ /dev/null @@ -1,166 +0,0 @@ -package io.milvus.param.collection; - -import io.milvus.exception.ParamException; -import io.milvus.param.Constant; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; -import java.util.ArrayList; -import java.util.List; - -/** - * Parameters for flush interface. - * Note that the flush interface is not exposed currently. - */ -@Getter -public class FlushParam { - private final List collectionNames; - private final Boolean syncFlush; - private final long syncFlushWaitingInterval; - private final long syncFlushWaitingTimeout; - - private FlushParam(@NonNull Builder builder) { - this.collectionNames = builder.collectionNames; - this.syncFlush = builder.syncFlush; - this.syncFlushWaitingInterval = builder.syncFlushWaitingInterval; - this.syncFlushWaitingTimeout = builder.syncFlushWaitingTimeout; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for FlushParam class. - */ - public static final class Builder { - private final List collectionNames = new ArrayList<>(); - - // syncFlush: - // Default behavior is sync flushing, flush() return after collection finish flushing. - private Boolean syncFlush = Boolean.TRUE; - - // syncFlushWaitingInterval: - // When syncFlush is ture, flush() will wait until collection finish flushing, - // this value control the waiting interval. Unit: millisecond. Default value: 500 milliseconds. - private Long syncFlushWaitingInterval = 500L; - - // syncFlushWaitingTimeout: - // When syncFlush is ture, flush() will wait until collection finish flushing, - // this value control the waiting timeout. Unit: second. Default value: 60 seconds. - private Long syncFlushWaitingTimeout = 60L; - - private Builder() { - } - - /** - * Set a list of collections to be flushed. - * - * @param collectionNames a list of collections - * @return Builder - */ - public Builder withCollectionNames(@NonNull List collectionNames) { - this.collectionNames.addAll(collectionNames); - return this; - } - - /** - * Add a collections to be flushed. - * - * @param collectionName name of the collections - * @return Builder - */ - public Builder addCollectionName(@NonNull String collectionName) { - this.collectionNames.add(collectionName); - return this; - } - - /** - * Set flush action to sync mode. - * With sync mode, the client side will keep waiting until all segments of the collection successfully flushed. - * - * If not sync mode, client will return at once after the flush() is called. - * - * @param syncFlush Boolean.TRUE is sync mode, Bollean.FALSE is not - * @return Builder - */ - public Builder withSyncFlush(@NonNull Boolean syncFlush) { - this.syncFlush = syncFlush; - return this; - } - - /** - * Set waiting interval in sync mode. In sync mode, the client will constantly check segments state by interval. - * Interval must be larger than zero, and cannot be larger than Constant.MAX_WAITING_FLUSHING_INTERVAL. - * @see Constant - * - * @param milliseconds interval - * @return Builder - */ - public Builder withSyncFlushWaitingInterval(@NonNull Long milliseconds) { - this.syncFlushWaitingInterval = milliseconds; - return this; - } - - /** - * Set time out value for sync mode. - * Time out value must be larger than zero, and cannot be larger than Constant.MAX_WAITING_FLUSHING_TIMEOUT. - * @see Constant - * - * @param seconds time out value for sync mode - * @return Builder - */ - public Builder withSyncFlushWaitingTimeout(@NonNull Long seconds) { - this.syncFlushWaitingTimeout = seconds; - return this; - } - - /** - * Verify parameters and create a new FlushParam instance. - * - * @return FlushParam - */ - public FlushParam build() throws ParamException { - if (collectionNames.isEmpty()) { - throw new ParamException("CollectionNames can not be empty"); - } - - for (String name : collectionNames) { - ParamUtils.CheckNullEmptyString(name, "Collection name"); - } - - if (syncFlush == Boolean.TRUE) { - if (syncFlushWaitingInterval <= 0) { - throw new ParamException("Sync flush waiting interval must be larger than zero"); - } else if (syncFlushWaitingInterval > Constant.MAX_WAITING_FLUSHING_INTERVAL) { - throw new ParamException("Sync flush waiting interval cannot be larger than " - + Constant.MAX_WAITING_FLUSHING_INTERVAL.toString() + " milliseconds"); - } - - if (syncFlushWaitingTimeout <= 0) { - throw new ParamException("Sync flush waiting timeout must be larger than zero"); - } else if (syncFlushWaitingTimeout > Constant.MAX_WAITING_FLUSHING_TIMEOUT) { - throw new ParamException("Sync flush waiting timeout cannot be larger than " - + Constant.MAX_WAITING_FLUSHING_TIMEOUT.toString() + " seconds"); - } - } - - return new FlushParam(this); - } - } - - /** - * Construct a String by FlushParam instance. - * - * @return String - */ - @Override - public String toString() { - return "FlushParam{" + - "collectionNames='" + collectionNames + '\'' + - ", syncFlush=" + syncFlush.toString() + - ", syncFlushWaitingInterval=" + syncFlushWaitingInterval + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/collection/GetCollectionStatisticsParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/collection/GetCollectionStatisticsParam.java deleted file mode 100644 index 7282284..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/collection/GetCollectionStatisticsParam.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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 - * - * 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.param.collection; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for getCollectionStatistics interface. - */ -@Getter -public class GetCollectionStatisticsParam { - private final String collectionName; - private final boolean flushCollection; - - private GetCollectionStatisticsParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.flushCollection = builder.flushCollection; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for GetCollectionStatisticsParam class. - */ - public static final class Builder { - private String collectionName; - - // if flushCollection is true, getCollectionStatistics() firstly call flush() and wait flush() finish - // Note: use default interval and timeout to wait flush() - private Boolean flushCollection = Boolean.TRUE; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Require a flush action before retrieving collection statistics. - * - * @param flush Boolean.TRUE require a flush action - * @return Builder - */ - public Builder withFlush(@NonNull Boolean flush) { - this.flushCollection = flush; - return this; - } - - /** - * Verify parameters and create a new GetCollectionStatisticsParam instance. - * - * @return GetCollectionStatisticsParam - */ - public GetCollectionStatisticsParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - return new GetCollectionStatisticsParam(this); - } - } - - /** - * Construct a String by GetCollectionStatisticsParam instance. - * - * @return String - */ - @Override - public String toString() { - return "GetCollectionStatisticsParam{" + - "collectionName='" + collectionName + '\'' + - " flush=" + flushCollection + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/collection/HasCollectionParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/collection/HasCollectionParam.java deleted file mode 100644 index 19a8632..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/collection/HasCollectionParam.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 - * - * 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.param.collection; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for hasCollection interface. - */ -@Getter -public class HasCollectionParam { - private final String collectionName; - - private HasCollectionParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for HasCollectionParam class. - */ - public static final class Builder { - private String collectionName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Verify parameters and create a new HasCollectionParam instance. - * - * @return HasCollectionParam - */ - public HasCollectionParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - return new HasCollectionParam(this); - } - } - - /** - * Construct a String by HasCollectionParam instance. - * - * @return String - */ - @Override - public String toString() { - return "HasCollectionParam{" + - "collectionName='" + collectionName + '\'' + '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/collection/LoadCollectionParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/collection/LoadCollectionParam.java deleted file mode 100644 index 8106cb6..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/collection/LoadCollectionParam.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * 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 - * - * 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.param.collection; - -import io.milvus.exception.ParamException; -import io.milvus.param.Constant; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for loadCollection interface. - */ -@Getter -public class LoadCollectionParam { - private final String collectionName; - private final boolean syncLoad; - private final long syncLoadWaitingInterval; - private final long syncLoadWaitingTimeout; - - public LoadCollectionParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.syncLoad = builder.syncLoad; - this.syncLoadWaitingInterval = builder.syncLoadWaitingInterval; - this.syncLoadWaitingTimeout = builder.syncLoadWaitingTimeout; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for LoadCollectionParam class. - */ - public static final class Builder { - private String collectionName; - - // syncLoad: - // Default behavior is sync loading, loadCollection() return after collection finish loading. - private Boolean syncLoad = Boolean.TRUE; - - // syncLoadWaitingDuration: - // When syncLoad is ture, loadCollection() will wait until collection finish loading, - // this value control the waiting interval. Unit: millisecond. Default value: 500 milliseconds. - private Long syncLoadWaitingInterval = 500L; - - // syncLoadWaitingTimeout: - // When syncLoad is ture, loadCollection() will wait until collection finish loading, - // this value control the waiting timeout. Unit: second. Default value: 60 seconds. - private Long syncLoadWaitingTimeout = 60L; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set load action to sync mode. - * With sync mode, the client side will keep waiting until all segments of the collection successfully loaded. - * - * If not sync mode, client will return at once after the loadCollection() is called. - * - * @param syncLoad Boolean.TRUE is sync mode, Boolean.FALSE is not - * @return Builder - */ - public Builder withSyncLoad(@NonNull Boolean syncLoad) { - this.syncLoad = syncLoad; - return this; - } - - /** - * Set waiting interval in sync mode. In sync mode, the client will constantly check collection load state by interval. - * Interval must be larger than zero, and cannot be larger than Constant.MAX_WAITING_LOADING_INTERVAL. - * @see Constant - * - * @param milliseconds interval - * @return Builder - */ - public Builder withSyncLoadWaitingInterval(@NonNull Long milliseconds) { - this.syncLoadWaitingInterval = milliseconds; - return this; - } - - /** - * Set time out value for sync mode. - * Time out value must be larger than zero, and cannot be larger than Constant.MAX_WAITING_LOADING_TIMEOUT. - * @see Constant - * - * @param seconds time out value for sync mode - * @return Builder - */ - public Builder withSyncLoadWaitingTimeout(@NonNull Long seconds) { - this.syncLoadWaitingTimeout = seconds; - return this; - } - - /** - * Verify parameters and create a new LoadCollectionParam instance. - * - * @return LoadCollectionParam - */ - public LoadCollectionParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - if (syncLoad == Boolean.TRUE) { - if (syncLoadWaitingInterval <= 0) { - throw new ParamException("Sync load waiting interval must be larger than zero"); - } else if (syncLoadWaitingInterval > Constant.MAX_WAITING_LOADING_INTERVAL) { - throw new ParamException("Sync load waiting interval cannot be larger than " - + Constant.MAX_WAITING_LOADING_INTERVAL.toString() + " milliseconds"); - } - - if (syncLoadWaitingTimeout <= 0) { - throw new ParamException("Sync load waiting timeout must be larger than zero"); - } else if (syncLoadWaitingTimeout > Constant.MAX_WAITING_LOADING_TIMEOUT) { - throw new ParamException("Sync load waiting timeout cannot be larger than " - + Constant.MAX_WAITING_LOADING_TIMEOUT.toString() + " seconds"); - } - } - - return new LoadCollectionParam(this); - } - } - - /** - * Construct a String by LoadCollectionParam instance. - * - * @return String - */ - @Override - public String toString() { - return "LoadCollectionParam{" + - "collectionName='" + collectionName + '\'' + - ", syncLoad=" + syncLoad + - ", syncLoadWaitingInterval=" + syncLoadWaitingInterval + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/collection/ReleaseCollectionParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/collection/ReleaseCollectionParam.java deleted file mode 100644 index 572c01f..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/collection/ReleaseCollectionParam.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 - * - * 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.param.collection; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for releaseCollection interface. - */ -@Getter -public class ReleaseCollectionParam { - private final String collectionName; - - private ReleaseCollectionParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for ReleaseCollectionParam class. - */ - public static final class Builder { - private String collectionName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Verify parameters and create a new ReleaseCollectionParam instance. - * - * @return ReleaseCollectionParam - */ - public ReleaseCollectionParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - return new ReleaseCollectionParam(this); - } - } - - /** - * Construct a String by ReleaseCollectionParam instance. - * - * @return String - */ - @Override - public String toString() { - return "ReleaseCollectionParam{" + - "collectionName='" + collectionName + '\'' + '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/collection/ShowCollectionsParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/collection/ShowCollectionsParam.java deleted file mode 100644 index b980393..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/collection/ShowCollectionsParam.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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 - * - * 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.param.collection; - -import io.milvus.exception.ParamException; -import io.milvus.grpc.ShowType; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; -import java.util.ArrayList; -import java.util.List; - -/** - * Parameters for showCollections interface. - */ -@Getter -public class ShowCollectionsParam { - private final List collectionNames; - private final ShowType showType; - - private ShowCollectionsParam(@NonNull Builder builder) { - this.collectionNames = builder.collectionNames; - this.showType = builder.showType; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for ShowCollectionsParam class. - */ - public static final class Builder { - private final List collectionNames = new ArrayList<>(); - // showType: - // default showType = ShowType.All - // if collectionNames is not empty, set showType = ShowType.InMemory - private ShowType showType = ShowType.All; - - private Builder() { - } - - /** - * Set a list of collection names, name cannot be empty or null. - * - * @param collectionNames list of collection names - * @return Builder - */ - public Builder withCollectionNames(@NonNull List collectionNames) { - collectionNames.forEach(this::addCollectionName); - return this; - } - - /** - * Add a collection name, name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder addCollectionName(@NonNull String collectionName) { - if (!this.collectionNames.contains(collectionName)) { - this.collectionNames.add(collectionName); - } - return this; - } - - /** - * Verify parameters and create a new ShowCollectionsParam instance. - * - * @return ShowCollectionsParam - */ - public ShowCollectionsParam build() throws ParamException { - if (!collectionNames.isEmpty()) { - for (String collectionName : collectionNames) { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - } - this.showType = ShowType.InMemory; - } - - return new ShowCollectionsParam(this); - } - } - - /** - * Construct a String by ShowCollectionsParam instance. - * - * @return String - */ - @Override - public String toString() { - return "ShowCollectionsParam{" + - "collectionNames='" + collectionNames.toString() + '\'' + - ", showType=" + showType.toString() + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/control/GetCompactionPlansParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/control/GetCompactionPlansParam.java deleted file mode 100644 index 15e871c..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/control/GetCompactionPlansParam.java +++ /dev/null @@ -1,65 +0,0 @@ -package io.milvus.param.control; - -import io.milvus.exception.ParamException; -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for getCompactionStateWithPlans interface. - * - * @see Metric function design - */ -@Getter -public class GetCompactionPlansParam { - private final Long compactionID; - - private GetCompactionPlansParam(@NonNull Builder builder) { - this.compactionID = builder.compactionID; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Construct a String by GetCompactionPlansParam instance. - * - * @return String - */ - @Override - public String toString() { - return "GetCompactionPlansParam{" + - "compactionID='" + compactionID + '\'' + - '}'; - } - - /** - * Builder for GetCompactionPlansParam class. - */ - public static final class Builder { - private Long compactionID; - - private Builder() { - } - - /** - * Set compaction action id to get plans. - * - * @param compactionID compaction action id - * @return Builder - */ - public Builder withCompactionID(@NonNull Long compactionID) { - this.compactionID = compactionID; - return this; - } - - /** - * Verify parameters and create a new GetCompactionPlansParam instance. - * - * @return GetCompactionPlansParam - */ - public GetCompactionPlansParam build() throws ParamException { - return new GetCompactionPlansParam(this); - } - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/control/GetCompactionStateParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/control/GetCompactionStateParam.java deleted file mode 100644 index 77ed5b8..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/control/GetCompactionStateParam.java +++ /dev/null @@ -1,66 +0,0 @@ -package io.milvus.param.control; - -import io.milvus.exception.ParamException; -import lombok.Getter; -import lombok.NonNull; - - -/** - * Parameters for getCompactionState interface. - * - * @see Metric function design - */ -@Getter -public class GetCompactionStateParam { - private final Long compactionID; - - private GetCompactionStateParam(@NonNull Builder builder) { - this.compactionID = builder.compactionID; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Construct a String by GetCompactionStateParam instance. - * - * @return String - */ - @Override - public String toString() { - return "GetCompactionStateParam{" + - "compactionID='" + compactionID + '\'' + - '}'; - } - - /** - * Builder for GetCompactionStateParam class. - */ - public static final class Builder { - private Long compactionID; - - private Builder() { - } - - /** - * Set compaction action id to get state. - * - * @param compactionID compaction action id - * @return Builder - */ - public Builder withCompactionID(@NonNull Long compactionID) { - this.compactionID = compactionID; - return this; - } - - /** - * Verify parameters and create a new GetCompactionStateParam instance. - * - * @return GetCompactionStateParam - */ - public GetCompactionStateParam build() throws ParamException { - return new GetCompactionStateParam(this); - } - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/control/GetMetricsParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/control/GetMetricsParam.java deleted file mode 100644 index c6ec5a5..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/control/GetMetricsParam.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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 - * - * 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.param.control; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for getMetric interface. - */ -@Getter -public class GetMetricsParam { - private final String request; - - private GetMetricsParam(@NonNull Builder builder) { - this.request = builder.request; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for GetMetricsParam class. - */ - public static final class Builder { - private String request; - - private Builder() { - } - - /** - * Set request in json format to retrieve metric information from server. - * @see Metric function design - * - * @param request request string in json format - * @return Builder - */ - public Builder withRequest(@NonNull String request) { - this.request = request; - return this; - } - - /** - * Verify parameters and create a new GetMetricsParam instance. - * - * @return GetMetricsParam - */ - public GetMetricsParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(request, "Request string"); - - // TODO: check the request string is json format - - return new GetMetricsParam(this); - } - } - - /** - * Construct a String by GetMetricsParam instance. - * - * @return String - */ - @Override - public String toString() { - return "GetMetricsParam{" + - "request='" + request + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/control/GetPersistentSegmentInfoParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/control/GetPersistentSegmentInfoParam.java deleted file mode 100644 index a633854..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/control/GetPersistentSegmentInfoParam.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 - * - * 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.param.control; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for getPersistentSegmentInfo interface. - */ -@Getter -public class GetPersistentSegmentInfoParam { - private final String collectionName; - - private GetPersistentSegmentInfoParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for GetPersistentSegmentInfoParam class. - */ - public static final class Builder { - private String collectionName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Verify parameters and create a new GetPersistentSegmentInfoParam instance. - * - * @return GetPersistentSegmentInfoParam - */ - public GetPersistentSegmentInfoParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - return new GetPersistentSegmentInfoParam(this); - } - } - - /** - * Construct a String by GetPersistentSegmentInfoParam instance. - * - * @return String - */ - @Override - public String toString() { - return "GetPersistentSegmentInfoParam{" + - "collectionName='" + collectionName + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/control/GetQuerySegmentInfoParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/control/GetQuerySegmentInfoParam.java deleted file mode 100644 index 2dd4d80..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/control/GetQuerySegmentInfoParam.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 - * - * 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.param.control; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for getQuerySegmentInfo interface. - */ -@Getter -public class GetQuerySegmentInfoParam { - private final String collectionName; - - private GetQuerySegmentInfoParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for GetPersistentSegmentInfoParam class. - */ - public static final class Builder { - private String collectionName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Verify parameters and create a new GetQuerySegmentInfoParam instance. - * - * @return GetQuerySegmentInfoParam - */ - public GetQuerySegmentInfoParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - return new GetQuerySegmentInfoParam(this); - } - } - - /** - * Construct a String by GetQuerySegmentInfoParam instance. - * - * @return String - */ - @Override - public String toString() { - return "GetQuerySegmentInfoParam{" + - "collectionName='" + collectionName + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/control/LoadBalanceParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/control/LoadBalanceParam.java deleted file mode 100644 index bc69a5e..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/control/LoadBalanceParam.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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 - * - * 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.param.control; - -import io.milvus.exception.ParamException; -import lombok.Getter; -import lombok.NonNull; - -import java.util.ArrayList; -import java.util.List; - -/** - * Parameters for loadBalance interface. - * - * @see Handoff and load balance - */ -@Getter -public class LoadBalanceParam { - private final Long srcNodeID; - private final List destNodeIDs; - private final List segmentIDs; - - private LoadBalanceParam(@NonNull Builder builder) { - this.srcNodeID = builder.srcNodeID; - this.destNodeIDs = builder.destNodeIDs; - this.segmentIDs = builder.segmentIDs; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Construct a String by LoadBalanceParam instance. - * - * @return String - */ - @Override - public String toString() { - return "LoadBalanceParam{" + - "srcNodeID='" + srcNodeID + '\'' + - "destNodeIDs='" + destNodeIDs.toString() + '\'' + - "segmentIDs='" + segmentIDs.toString() + '\'' + - '}'; - } - - /** - * Builder for LoadBalanceParam class. - */ - public static final class Builder { - private final List destNodeIDs = new ArrayList<>(); - private final List segmentIDs = new ArrayList<>(); - private Long srcNodeID; - - private Builder() { - } - - /** - * Set source query node id in which the sealed segments were loaded. - * - * @param srcNodeID source query node id - * @return Builder - */ - public Builder withSourceNodeID(@NonNull Long srcNodeID) { - this.srcNodeID = srcNodeID; - return this; - } - - /** - * Add destination query node id to which the sealed segments will be balance. - * - * @param destNodeID destination query node id - * @return Builder - */ - public Builder addDestinationNodeID(@NonNull Long destNodeID) { - if (!destNodeIDs.contains(destNodeID)) { - destNodeIDs.add(destNodeID); - } - - return this; - } - - /** - * Set destination query node id array to which the sealed segments will be balance. - * - * @param destNodeIDs destination query node id array - * @return Builder - */ - public Builder withDestinationNodeID(@NonNull List destNodeIDs) { - destNodeIDs.forEach(this::addDestinationNodeID); - return this; - } - - /** - * Add a sealed segments id to be balanced. - * - * @param segmentID sealed segment id - * @return Builder - */ - public Builder addSegmentID(@NonNull Long segmentID) { - if (!segmentIDs.contains(segmentID)) { - segmentIDs.add(segmentID); - } - - return this; - } - - /** - * Set sealed segments id array to be balanced. - * - * @param segmentIDs sealed segments id array - * @return Builder - */ - public Builder withSegmentIDs(@NonNull List segmentIDs) { - segmentIDs.forEach(this::addSegmentID); - return this; - } - - /** - * Verify parameters and create a new LoadBalanceParam instance. - * - * @return LoadBalanceParam - */ - public LoadBalanceParam build() throws ParamException { - if (segmentIDs.isEmpty()) { - throw new ParamException("Sealed segment id array cannot be empty"); - } - - if (destNodeIDs.isEmpty()) { - throw new ParamException("Destination query node id array cannot be empty"); - } - - return new LoadBalanceParam(this); - } - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/control/ManualCompactionParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/control/ManualCompactionParam.java deleted file mode 100644 index d7a9867..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/control/ManualCompactionParam.java +++ /dev/null @@ -1,65 +0,0 @@ -package io.milvus.param.control; - -import io.milvus.exception.ParamException; -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for manualCompaction interface. - * - * @see Metric function design - */ -@Getter -public class ManualCompactionParam { - private final Long collectionID; - - private ManualCompactionParam(@NonNull Builder builder) { - this.collectionID = builder.collectionID; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Construct a String by ManualCompactionParam instance. - * - * @return String - */ - @Override - public String toString() { - return "ManualCompactionParam{" + - "collectionID='" + collectionID + '\'' + - '}'; - } - - /** - * Builder for ManualCompactionParam class. - */ - public static final class Builder { - private Long collectionID; - - private Builder() { - } - - /** - * Ask server to compact a collection. - * - * @param collectionID target collection id - * @return Builder - */ - public Builder withCollectionID(@NonNull Long collectionID) { - this.collectionID = collectionID; - return this; - } - - /** - * Verify parameters and create a new ManualCompactionParam instance. - * - * @return ManualCompactionParam - */ - public ManualCompactionParam build() throws ParamException { - return new ManualCompactionParam(this); - } - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/dml/CalcDistanceParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/dml/CalcDistanceParam.java deleted file mode 100644 index 56c109d..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/dml/CalcDistanceParam.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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 - * - * 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.param.dml; - -import io.milvus.exception.ParamException; -import io.milvus.param.MetricType; - -import lombok.Getter; -import lombok.NonNull; -import java.util.List; - -/** - * Parameters for calcDistance interface. - * Note that currently only support float vectors calculation. - */ -@Getter -public class CalcDistanceParam { - private final List> vectorsLeft; - private final List> vectorsRight; - private final String metricType; - - private CalcDistanceParam(@NonNull Builder builder) { - this.vectorsLeft = builder.vectorsLeft; - this.vectorsRight = builder.vectorsRight; - this.metricType = builder.metricType.name(); - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for CalcDistanceParam class. - */ - public static class Builder { - private List> vectorsLeft; - private List> vectorsRight; - private MetricType metricType; - - private Builder() { - } - - /** - * Set a list of left side vectors. The list cannot be null or empty, each vector list cannot be null or empty. - * - * @param vectors a list of float list, each float list is a vector. - * @return Builder - */ - public Builder withVectorsLeft(@NonNull List> vectors) { - this.vectorsLeft = vectors; - return this; - } - - /** - * Set a list of right side vectors. The list cannot be null or empty, each vector list cannot be null or empty. - * - * @param vectors a list of float list, each float list is a vector. - * @return Builder - */ - public Builder withVectorsRight(@NonNull List> vectors) { - this.vectorsRight = vectors; - return this; - } - - /** - * Set metric type of calculation. Note that currently only support L2 and IP. - * - * @param metricType metric type - * @return Builder - */ - public Builder withMetricType(MetricType metricType) { - this.metricType = metricType; - return this; - } - - /** - * Verify parameters and create a new CalcDistanceParam instance. - * - * @return CalcDistanceParam - */ - public CalcDistanceParam build() throws ParamException { - if (metricType == MetricType.INVALID) { - throw new ParamException("Metric type is illegal"); - } - - if (metricType != MetricType.L2 && metricType != MetricType.IP) { - throw new ParamException("Only support L2 or IP metric type now!"); - } - - if (vectorsLeft == null || vectorsLeft.isEmpty()) { - throw new ParamException("Left vectors can not be empty"); - } - - int count = vectorsLeft.get(0).size(); - for (List vector : vectorsLeft) { - if (vector.size() != count) { - throw new ParamException("Left vector's dimension must be equal"); - } - } - - if (vectorsRight == null || vectorsRight.isEmpty()) { - throw new ParamException("Right vectors can not be empty"); - } - - count = vectorsRight.get(0).size(); - for (List vector : vectorsRight) { - if (vector.size() != count) { - throw new ParamException("Right vector's dimension must be equal"); - } - } - - return new CalcDistanceParam(this); - } - } - - /** - * Construct a String by CalcDistanceParam instance. - * - * @return String - */ - @Override - public String toString() { - return "CalcDistanceParam{ left vector count:" + vectorsLeft.size() + - " right vector count:" + vectorsRight.size() + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/dml/DeleteParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/dml/DeleteParam.java deleted file mode 100644 index fdb41b1..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/dml/DeleteParam.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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 - * - * 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.param.dml; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for delete interface. - */ -@Getter -public class DeleteParam { - private final String collectionName; - private final String partitionName; - private final String expr; - - private DeleteParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.partitionName = builder.partitionName; - this.expr = builder.expr; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for DeleteParam class. - */ - public static class Builder { - private String collectionName; - private String partitionName = ""; - private String expr; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Optional. Set partition name. - * - * @param partitionName partition name - * @return Builder - */ - public Builder withPartitionName(@NonNull String partitionName) { - this.partitionName = partitionName; - return this; - } - - /** - * Set expr to filter out entities to be deleted. - * @see Boolean Expression Rules - * - * @param expr filtering expression - * @return Builder - */ - public Builder withExpr(@NonNull String expr) { - this.expr = expr; - return this; - } - - /** - * Verify parameters and create a new DeleteParam instance. - * - * @return DeleteParam - */ - public DeleteParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(expr, "Expression"); - - return new DeleteParam(this); - } - } - - /** - * Construct a String by DeleteParam instance. - * - * @return String - */ - @Override - public String toString() { - return "DeleteParam{" + - "collectionName='" + collectionName + '\'' + - ", partitionName='" + partitionName + '\'' + - ", expr='" + expr + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/dml/InsertParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/dml/InsertParam.java deleted file mode 100644 index ef8123c..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/dml/InsertParam.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * 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 - * - * 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.param.dml; - -import io.milvus.exception.ParamException; -import io.milvus.grpc.DataType; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; -import java.nio.ByteBuffer; -import java.util.List; - -/** - * Parameters for insert interface. - */ -@Getter -public class InsertParam { - private final List fields; - - private final String collectionName; - private final String partitionName; - private final int rowCount; - - private InsertParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.partitionName = builder.partitionName; - this.fields = builder.fields; - this.rowCount = builder.rowCount; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for InsertParam class. - */ - public static class Builder { - private String collectionName; - private String partitionName = "_default"; - private List fields; - private int rowCount; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Optional. Set partition name. - * - * @param partitionName partition name - * @return Builder - */ - public Builder withPartitionName(@NonNull String partitionName) { - this.partitionName = partitionName; - return this; - } - - /** - * Set insert data. The fields list cannot be empty. - * @see Field - * - * @param fields insert data - * @return Builder - */ - public Builder withFields(@NonNull List fields) { - this.fields = fields; - return this; - } - - /** - * Verify parameters and create a new InsertParam instance. - * - * @return InsertParam - */ - @SuppressWarnings("unchecked") - public InsertParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - if (fields.isEmpty()) { - throw new ParamException("Fields cannot be empty"); - } - - for (Field field : fields) { - if (field == null) { - throw new ParamException("Field cannot be null." + - " If the field is auto-id, just ignore it from withFields()"); - } - - ParamUtils.CheckNullEmptyString(field.getName(), "Field name"); - - if (field.getValues() == null || field.getValues().isEmpty()) { - throw new ParamException("Field value cannot be empty." + - " If the field is auto-id, just ignore it from withFields()"); - } - } - - // check row count - int count = fields.get(0).getValues().size(); - for (Field field : fields) { - if (field.getValues().size() != count) { - throw new ParamException("Row count of fields must be equal"); - } - } - this.rowCount = count; - - if (count == 0) { - throw new ParamException("Row count is zero"); - } - - // check value type and vector dimension - for (Field field : fields) { - List values = field.getValues(); - if (field.getType() == DataType.FloatVector) { - for (Object obj : values) { - if (!(obj instanceof List)) { - throw new ParamException("Float vector field's value must be Lst"); - } - - List temp = (List)obj; - for (Object v : temp) { - if (!(v instanceof Float)) { - throw new ParamException("Float vector's value type must be Float"); - } - } - } - - List first = (List) values.get(0); - int dim = first.size(); - for (int i = 1; i < values.size(); ++i) { - List temp = (List) values.get(i); - if (dim != temp.size()) { - throw new ParamException("Vector dimension must be equal"); - } - } - } else if (field.getType() == DataType.BinaryVector) { - for (Object obj : values) { - if (!(obj instanceof ByteBuffer)) { - throw new ParamException("Binary vector field's type must be ByteBuffer"); - } - } - - ByteBuffer first = (ByteBuffer) values.get(0); - int dim = first.position(); - for (int i = 1; i < values.size(); ++i) { - ByteBuffer temp = (ByteBuffer) values.get(i); - if (dim != temp.position()) { - throw new ParamException("Vector dimension must be equal"); - } - } - } else if (field.getType() == DataType.Int64) { - for (Object obj : values) { - if (!(obj instanceof Long)) { - throw new ParamException("Int64 field value type must be Long"); - } - } - } else if (field.getType() == DataType.Int32 || field.getType() == DataType.Int16 - || field.getType() == DataType.Int8 ) { - for (Object obj : values) { - if (!(obj instanceof Integer) && !(obj instanceof Short)) { - throw new ParamException("Int32/Int16/Int8 field value type must be Integer or Short"); - } - } - } else if (field.getType() == DataType.Float) { - for (Object obj : values) { - if (!(obj instanceof Float)) { - throw new ParamException("Float field value type must be Float"); - } - } - } else if (field.getType() == DataType.Double) { - for (Object obj : values) { - if (!(obj instanceof Double)) { - throw new ParamException("Double field value type must be Double"); - } - } - } else if (field.getType() == DataType.Bool) { - for (Object obj : values) { - if (!(obj instanceof Boolean)) { - throw new ParamException("Bool field value type must be Boolean"); - } - } - } else if (field.getType() == DataType.String) { - for (Object obj : values) { - if (!(obj instanceof String)) { - throw new ParamException("String field value type must be String"); - } - } - } - } - - return new InsertParam(this); - } - } - - /** - * Construct a String by InsertParam instance. - * - * @return String - */ - @Override - public String toString() { - return "InsertParam{" + - "collectionName='" + collectionName + '\'' + - ", partitionName='" + partitionName + '\'' + - ", row_count=" + rowCount + - '}'; - } - - /** - * Internal class for insert data. - * if dataType is scalar(bool/int/float/double): values is List, List... - * if dataType is FloatVector: values is List> - * if dataType is BinaryVector: values is List - */ - public static class Field { - private final String name; - private final DataType type; - private final List values; - - public Field(String name, DataType type, List values) { - this.name = name; - this.type = type; - this.values = values; - } - - public String getName() { - return name; - } - - public DataType getType() { - return type; - } - - public List getValues() { - return values; - } - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/dml/QueryParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/dml/QueryParam.java deleted file mode 100644 index 7837195..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/dml/QueryParam.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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 - * - * 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.param.dml; - -import com.google.common.collect.Lists; -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; -import java.util.ArrayList; -import java.util.List; - -/** - * Parameters for query interface. - */ -@Getter -public class QueryParam { - private final String collectionName; - private final List partitionNames; - private final List outFields; - private final String expr; - - private QueryParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.partitionNames = builder.partitionNames; - this.outFields = builder.outFields; - this.expr = builder.expr; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for QueryParam class. - */ - public static class Builder { - private String collectionName; - private List partitionNames = Lists.newArrayList(); - private List outFields = new ArrayList<>(); - private String expr = ""; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Optional. Set partition names list to specify query scope. - * - * @param partitionNames partition names list - * @return Builder - */ - public Builder withPartitionNames(@NonNull List partitionNames) { - this.partitionNames = partitionNames; - return this; - } - - /** - * Optional. Specify output fields. - * - * @param outFields output fields - * @return Builder - */ - public Builder withOutFields(@NonNull List outFields) { - this.outFields = outFields; - return this; - } - - /** - * Set expression to filter out entities to be queried. - * @see Boolean Expression Rules - * - * @param expr filtering expression - * @return Builder - */ - public Builder withExpr(@NonNull String expr) { - this.expr = expr; - return this; - } - - /** - * Verify parameters and create a new QueryParam instance. - * - * @return QueryParam - */ - public QueryParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(expr, "Expression"); - - return new QueryParam(this); - } - } - - /** - * Construct a String by QueryParam instance. - * - * @return String - */ - @Override - public String toString() { - return "QueryParam{" + - "collectionName='" + collectionName + '\'' + - ", partitionNames='" + partitionNames.toString() + '\'' + - ", expr='" + expr + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/dml/SearchParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/dml/SearchParam.java deleted file mode 100644 index f608506..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/dml/SearchParam.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * 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 - * - * 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.param.dml; - -import com.google.common.collect.Lists; -import io.milvus.exception.ParamException; -import io.milvus.param.MetricType; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; - -/** - * Parameters for search interface. - */ -@Getter -public class SearchParam { - private final String collectionName; - private final List partitionNames; - private final String metricType; - private final String vectorFieldName; - private final int topK; - private final String expr; - private final List outFields; - private final List vectors; - private final int roundDecimal; - private final String params; - - private SearchParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.partitionNames = builder.partitionNames; - this.metricType = builder.metricType.name(); - this.vectorFieldName = builder.vectorFieldName; - this.topK = builder.topK; - this.expr = builder.expr; - this.outFields = builder.outFields; - this.vectors = builder.vectors; - this.roundDecimal = builder.roundDecimal; - this.params = builder.params; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for SearchParam class. - */ - public static class Builder { - private String collectionName; - private List partitionNames = Lists.newArrayList(); - private MetricType metricType = MetricType.L2; - private String vectorFieldName; - private Integer topK; - private String expr = ""; - private List outFields = new ArrayList<>(); - private List vectors; - private Integer roundDecimal = -1; - private String params = "{}"; - - Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Optional. Set partition names list to specify search scope. - * - * @param partitionNames partition names list - * @return Builder - */ - public Builder withPartitionNames(@NonNull List partitionNames) { - this.partitionNames = partitionNames; - return this; - } - - /** - * Set metric type of ANN searching. - * - * @param metricType metric type - * @return Builder - */ - public Builder withMetricType(@NonNull MetricType metricType) { - this.metricType = metricType; - return this; - } - - /** - * Set target vector field name. Field name cannot be empty or null. - * - * @param vectorFieldName vector field name - * @return Builder - */ - public Builder withVectorFieldName(@NonNull String vectorFieldName) { - this.vectorFieldName = vectorFieldName; - return this; - } - - /** - * Set topK value of ANN search. - * - * @param topK topK value - * @return Builder - */ - public Builder withTopK(@NonNull Integer topK) { - this.topK = topK; - return this; - } - - /** - * Optional. Set expression to filter out entities before searching. - * @see Boolean Expression Rules - * - * @param expr filtering expression - * @return Builder - */ - public Builder withExpr(@NonNull String expr) { - this.expr = expr; - return this; - } - - /** - * Optional. Specify output fields. - * - * @param outFields output fields - * @return Builder - */ - public Builder withOutFields(@NonNull List outFields) { - this.outFields = outFields; - return this; - } - - /** - * Set target vectors. - * - * @param vectors list of target vectors - * If vector type is FloatVector: vectors is List> - * If vector type is BinaryVector: vectors is List - * @return Builder - */ - public Builder withVectors(@NonNull List vectors) { - this.vectors = vectors; - return this; - } - - /** - * Specify how many digits after the decimal point for returned results. - * - * @param decimal how many digits after the decimal point - * @return Builder - */ - public Builder withRoundDecimal(@NonNull Integer decimal) { - this.roundDecimal = decimal; - return this; - } - - /** - * Set extra search parameters according to index type. - * - * For example: IVF index, the extra parameters can be "{\"nprobe\":10}" - * For more information: @see Index Selection - * - * @param params extra parameters in json format - * @return Builder - */ - public Builder withParams(@NonNull String params) { - this.params = params; - return this; - } - - /** - * Verify parameters and create a new SearchParam instance. - * - * @return SearchParam - */ - public SearchParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(vectorFieldName, "Target field name"); - - if (metricType == MetricType.INVALID) { - throw new ParamException("Metric type is illegal"); - } - - if (vectors == null || vectors.isEmpty()) { - throw new ParamException("Target vectors can not be empty"); - } - - if (vectors.get(0) instanceof List) { - // float vectors - List first = (List) vectors.get(0); - if (!(first.get(0) instanceof Float)) { - throw new ParamException("Float vector field's value must be Lst"); - } - - int dim = first.size(); - for (int i = 1; i < vectors.size(); ++i) { - List temp = (List) vectors.get(i); - if (dim != temp.size()) { - throw new ParamException("Target vector dimension must be equal"); - } - } - } else if (vectors.get(0) instanceof ByteBuffer) { - // binary vectors - ByteBuffer first = (ByteBuffer) vectors.get(0); - int dim = first.position(); - for (int i = 1; i < vectors.size(); ++i) { - ByteBuffer temp = (ByteBuffer) vectors.get(i); - if (dim != temp.position()) { - throw new ParamException("Target vector dimension must be equal"); - } - } - } else { - throw new ParamException("Target vector type must be Lst or ByteBuffer"); - } - - return new SearchParam(this); - } - } - - /** - * Construct a String by SearchParam instance. - * - * @return String - */ - @Override - public String toString() { - return "SearchParam{" + - "collectionName='" + collectionName + '\'' + - ", partitionNames='" + partitionNames.toString() + '\'' + - ", metricType=" + metricType + - ", target vectors count=" + vectors.size() + - ", vectorFieldName='" + vectorFieldName + '\'' + - ", topK=" + topK + - ", expr='" + expr + '\'' + - ", params='" + params + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/index/CreateIndexParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/index/CreateIndexParam.java deleted file mode 100644 index c1c578c..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/index/CreateIndexParam.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * 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 - * - * 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.param.index; - -import io.milvus.exception.ParamException; -import io.milvus.param.Constant; -import io.milvus.param.IndexType; -import io.milvus.param.MetricType; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; -import java.util.HashMap; -import java.util.Map; - -/** - * Parameters for createIndex interface. - */ -@Getter -public class CreateIndexParam { - private final String collectionName; - private final String fieldName; - private final Map extraParam = new HashMap<>(); - private final boolean syncMode; - private final long syncWaitingInterval; - private final long syncWaitingTimeout; - - private CreateIndexParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.fieldName = builder.fieldName; - this.extraParam.put(Constant.INDEX_TYPE, builder.indexType.name()); - this.extraParam.put(Constant.METRIC_TYPE, builder.metricType.name()); - this.extraParam.put(Constant.PARAMS, builder.extraParam); - this.syncMode = builder.syncMode; - this.syncWaitingInterval = builder.syncWaitingInterval; - this.syncWaitingTimeout = builder.syncWaitingTimeout; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for CreateIndexParam class. - */ - public static final class Builder { - private String collectionName; - private String fieldName; - private IndexType indexType; - private MetricType metricType; - private String extraParam; - - // syncMode: - // Default behavior is sync mode, createIndex() return after the index successfully created. - private Boolean syncMode = Boolean.TRUE; - - // syncWaitingDuration: - // When syncMode is ture, createIndex() return after the index successfully created. - // this value control the waiting interval. Unit: millisecond. Default value: 500 milliseconds. - private Long syncWaitingInterval = 500L; - - // syncWaitingTimeout: - // When syncMode is ture, createIndex() return after the index successfully created. - // this value control the waiting timeout. Unit: second. Default value: 600 seconds. - private Long syncWaitingTimeout = 600L; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set target field name. Field name cannot be empty or null. - * - * @param fieldName field name - * @return Builder - */ - public Builder withFieldName(@NonNull String fieldName) { - this.fieldName = fieldName; - return this; - } - - /** - * Set index type of the index. - * - * @param indexType index type - * @return Builder - */ - public Builder withIndexType(@NonNull IndexType indexType) { - this.indexType = indexType; - return this; - } - - /** - * Set metric type of the index. - * - * @param metricType metric type - * @return Builder - */ - public Builder withMetricType(@NonNull MetricType metricType) { - this.metricType = metricType; - return this; - } - - /** - * Set extra index parameters according to index type. - * - * For example: IVF index, the extra parameters can be "{\"nlist\":1024}" - * For more information: @see Index Selection - * - * @param extraParam extra parameters in json format - * @return Builder - */ - public Builder withExtraParam(@NonNull String extraParam) { - this.extraParam = extraParam; - return this; - } - - /** - * Set to sync mode. - * With sync mode, the client side will keep waiting until all segments of the collection successfully indexed. - * - * If not sync mode, client will return at once after the createIndex() is called. - * - * @param syncMode Boolean.TRUE is sync mode, Boolean.FALSE is not - * @return Builder - */ - public Builder withSyncMode(@NonNull Boolean syncMode) { - this.syncMode = syncMode; - return this; - } - - /** - * Set waiting interval in sync mode. In sync mode, the client will constantly check index state by interval. - * Interval must be larger than zero, and cannot be larger than Constant.MAX_WAITING_INDEX_INTERVAL. - * @see Constant - * - * @param milliseconds interval - * @return Builder - */ - public Builder withSyncWaitingInterval(@NonNull Long milliseconds) { - this.syncWaitingInterval = milliseconds; - return this; - } - - /** - * Set time out value for sync mode. - * Time out value must be larger than zero. No upper limit. Default value is 600 seconds. - * @see Constant - * - * @param seconds time out value for sync mode - * @return Builder - */ - public Builder withSyncWaitingTimeout(@NonNull Long seconds) { - this.syncWaitingTimeout = seconds; - return this; - } - - /** - * Verify parameters and create a new CreateIndexParam instance. - * - * @return CreateIndexParam - */ - public CreateIndexParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(fieldName, "Field name"); - - if (indexType == IndexType.INVALID) { - throw new ParamException("Index type is required"); - } - - if (metricType == MetricType.INVALID) { - throw new ParamException("Metric type is required"); - } - - if (syncMode == Boolean.TRUE) { - if (syncWaitingInterval <= 0) { - throw new ParamException("Sync index waiting interval must be larger than zero"); - } else if (syncWaitingInterval > Constant.MAX_WAITING_LOADING_INTERVAL) { - throw new ParamException("Sync index waiting interval cannot be larger than " - + Constant.MAX_WAITING_LOADING_INTERVAL.toString() + " milliseconds"); - } - - if (syncWaitingTimeout <= 0) { - throw new ParamException("Sync index waiting timeout must be larger than zero"); - } - } - - ParamUtils.CheckNullEmptyString(extraParam, "Index extra param"); - - return new CreateIndexParam(this); - } - } - - /** - * Construct a String by CreateIndexParam instance. - * - * @return String - */ - @Override - public String toString() { - return "CreateIndexParam{" + - "collectionName='" + collectionName + '\'' + - ", fieldName='" + fieldName + '\'' + - ", params='" + extraParam.toString() + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/index/DescribeIndexParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/index/DescribeIndexParam.java deleted file mode 100644 index 37e2f10..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/index/DescribeIndexParam.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 - * - * 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.param.index; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for describeIndex interface. - */ -@Getter -public class DescribeIndexParam { - private final String collectionName; - private final String fieldName; - - private DescribeIndexParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.fieldName = builder.fieldName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for DescribeIndexParam class. - */ - public static final class Builder { - private String collectionName; - private String fieldName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set target field name. Field name cannot be empty or null. - * - * @param fieldName field name - * @return Builder - */ - public Builder withFieldName(@NonNull String fieldName) { - this.fieldName = fieldName; - return this; - } - - /** - * Verify parameters and create a new DescribeIndexParam instance. - * - * @return DescribeIndexParam - */ - public DescribeIndexParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(fieldName, "Field name"); - - return new DescribeIndexParam(this); - } - } - - /** - * Construct a String by DescribeIndexParam instance. - * - * @return String - */ - @Override - public String toString() { - return "DescribeIndexParam{" + - "collectionName='" + collectionName + '\'' + - ", fieldName='" + fieldName + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/index/DropIndexParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/index/DropIndexParam.java deleted file mode 100644 index aa70452..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/index/DropIndexParam.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 - * - * 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.param.index; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for dropIndex interface. - */ -@Getter -public class DropIndexParam { - private final String collectionName; - private final String fieldName; - - private DropIndexParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.fieldName = builder.fieldName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for DropIndexParam class. - */ - public static final class Builder { - private String collectionName; - private String fieldName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set target field name. Field name cannot be empty or null. - * - * @param fieldName field name - * @return Builder - */ - public Builder withFieldName(@NonNull String fieldName) { - this.fieldName = fieldName; - return this; - } - - /** - * Verify parameters and create a new DropIndexParam instance. - * - * @return DropIndexParam - */ - public DropIndexParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(fieldName, "Field name"); - - return new DropIndexParam(this); - } - } - - /** - * Construct a String by DropIndexParam instance. - * - * @return String - */ - @Override - public String toString() { - return "DropIndexParam{" + - "collectionName='" + collectionName + '\'' + - ", fieldName='" + fieldName + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/index/GetIndexBuildProgressParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/index/GetIndexBuildProgressParam.java deleted file mode 100644 index 8cce87f..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/index/GetIndexBuildProgressParam.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 - * - * 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.param.index; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for getIndexBuildProgress interface. - */ -@Getter -public class GetIndexBuildProgressParam { - private final String collectionName; - - private GetIndexBuildProgressParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for GetIndexBuildProgressParam class. - */ - public static final class Builder { - private String collectionName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Verify parameters and create a new GetIndexBuildProgressParam instance. - * - * @return GetIndexBuildProgressParam - */ - public GetIndexBuildProgressParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - return new GetIndexBuildProgressParam(this); - } - } - - /** - * Construct a String by GetIndexBuildProgressParam instance. - * - * @return String - */ - @Override - public String toString() { - return "GetIndexBuildProgressParam{" + - "collectionName='" + collectionName + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/index/GetIndexStateParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/index/GetIndexStateParam.java deleted file mode 100644 index df22954..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/index/GetIndexStateParam.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 - * - * 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.param.index; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for getIndexState interface. - */ -@Getter -public class GetIndexStateParam { - private final String collectionName; - private final String fieldName; - - private GetIndexStateParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.fieldName = builder.fieldName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for GetIndexStateParam class. - */ - public static final class Builder { - private String collectionName; - private String fieldName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set target field name. Field name cannot be empty or null. - * - * @param fieldName field name - * @return Builder - */ - public Builder withFieldName(@NonNull String fieldName) { - this.fieldName = fieldName; - return this; - } - - /** - * Verify parameters and create a new GetIndexStateParam instance. - * - * @return GetIndexStateParam - */ - public GetIndexStateParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(fieldName, "Field name"); - - return new GetIndexStateParam(this); - } - } - - /** - * Construct a String by GetIndexStateParam instance. - * - * @return String - */ - @Override - public String toString() { - return "GetIndexStateParam{" + - "collectionName='" + collectionName + '\'' + - ", fieldName='" + fieldName + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/partition/CreatePartitionParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/partition/CreatePartitionParam.java deleted file mode 100644 index b795558..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/partition/CreatePartitionParam.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 - * - * 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.param.partition; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for createPartition interface. - */ -@Getter -public class CreatePartitionParam { - private final String collectionName; - private final String partitionName; - - private CreatePartitionParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.partitionName = builder.partitionName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for CreatePartitionParam class. - */ - public static final class Builder { - private String collectionName; - private String partitionName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set partition name. Partition name cannot be empty or null. - * - * @param partitionName partition name - * @return Builder - */ - public Builder withPartitionName(@NonNull String partitionName) { - this.partitionName = partitionName; - return this; - } - - /** - * Verify parameters and create a new CreatePartitionParam instance. - * - * @return CreatePartitionParam - */ - public CreatePartitionParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(partitionName, "Partition name"); - - return new CreatePartitionParam(this); - } - } - - /** - * Construct a String by CreatePartitionParam instance. - * - * @return String - */ - @Override - public String toString() { - return "CreatePartitionParam{" + - "collectionName='" + collectionName + '\'' + - ", partitionName='" + partitionName + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/partition/DropPartitionParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/partition/DropPartitionParam.java deleted file mode 100644 index 93ae0a5..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/partition/DropPartitionParam.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 - * - * 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.param.partition; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for dropPartition interface. - */ -@Getter -public class DropPartitionParam { - private final String collectionName; - private final String partitionName; - - private DropPartitionParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.partitionName = builder.partitionName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for DropPartitionParam class. - */ - public static final class Builder { - private String collectionName; - private String partitionName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set partition name. Partition name cannot be empty or null. - * - * @param partitionName partition name - * @return Builder - */ - public Builder withPartitionName(@NonNull String partitionName) { - this.partitionName = partitionName; - return this; - } - - /** - * Verify parameters and create a new DropPartitionParam instance. - * - * @return DropPartitionParam - */ - public DropPartitionParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(partitionName, "Partition name"); - - return new DropPartitionParam(this); - } - } - - /** - * Construct a String by DropPartitionParam instance. - * - * @return String - */ - @Override - public String toString() { - return "DropPartitionParam{" + - "collectionName='" + collectionName + '\'' + - ", partitionName='" + partitionName + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/partition/GetPartitionStatisticsParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/partition/GetPartitionStatisticsParam.java deleted file mode 100644 index 74e183a..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/partition/GetPartitionStatisticsParam.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 - * - * 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.param.partition; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for getPartitionStatistics interface. - */ -@Getter -public class GetPartitionStatisticsParam { - private final String collectionName; - private final String partitionName; - - private GetPartitionStatisticsParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.partitionName = builder.partitionName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for GetPartitionStatisticsParam class. - */ - public static final class Builder { - private String collectionName; - private String partitionName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set partition name. Partition name cannot be empty or null. - * - * @param partitionName partition name - * @return Builder - */ - public Builder withPartitionName(@NonNull String partitionName) { - this.partitionName = partitionName; - return this; - } - - /** - * Verify parameters and create a new GetPartitionStatisticsParam instance. - * - * @return GetPartitionStatisticsParam - */ - public GetPartitionStatisticsParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(partitionName, "Partition name"); - - return new GetPartitionStatisticsParam(this); - } - } - - /** - * Construct a String by GetPartitionStatisticsParam instance. - * - * @return String - */ - @Override - public String toString() { - return "GetPartitionStatisticsParam{" + - "collectionName='" + collectionName + '\'' + - ", partitionName='" + partitionName + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/partition/HasPartitionParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/partition/HasPartitionParam.java deleted file mode 100644 index b16ef10..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/partition/HasPartitionParam.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 - * - * 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.param.partition; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; - -/** - * Parameters for hasPartition interface. - */ -@Getter -public class HasPartitionParam { - private final String collectionName; - private final String partitionName; - - private HasPartitionParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.partitionName = builder.partitionName; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for HasPartitionParam class. - */ - public static final class Builder { - private String collectionName; - private String partitionName; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set partition name. Partition name cannot be empty or null. - * - * @param partitionName partition name - * @return Builder - */ - public Builder withPartitionName(@NonNull String partitionName) { - this.partitionName = partitionName; - return this; - } - - /** - * Verify parameters and create a new HasPartitionParam instance. - * - * @return HasPartitionParam - */ - public HasPartitionParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - ParamUtils.CheckNullEmptyString(partitionName, "Partition name"); - - return new HasPartitionParam(this); - } - } - - /** - * Construct a String by HasPartitionParam instance. - * - * @return String - */ - @Override - public String toString() { - return "HasPartitionParam{" + - "collectionName='" + collectionName + '\'' + - ", partitionName='" + partitionName + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/partition/LoadPartitionsParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/partition/LoadPartitionsParam.java deleted file mode 100644 index b940f57..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/partition/LoadPartitionsParam.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * 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 - * - * 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.param.partition; - -import io.milvus.exception.ParamException; -import io.milvus.param.Constant; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; -import java.util.ArrayList; -import java.util.List; - -/** - * Parameters for loadPartition interface. - */ -@Getter -public class LoadPartitionsParam { - private final String collectionName; - private final List partitionNames; - private final boolean syncLoad; - private final long syncLoadWaitingInterval; - private final long syncLoadWaitingTimeout; - - private LoadPartitionsParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.partitionNames = builder.partitionNames; - this.syncLoad = builder.syncLoad; - this.syncLoadWaitingInterval = builder.syncLoadWaitingInterval; - this.syncLoadWaitingTimeout = builder.syncLoadWaitingTimeout; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for LoadPartitionsParam class. - */ - public static final class Builder { - private String collectionName; - private final List partitionNames = new ArrayList<>(); - - // syncLoad: - // Default behavior is sync loading, loadPartition() return after partition finish loading. - private Boolean syncLoad = Boolean.TRUE; - - // syncLoadWaitingDuration: - // When syncLoad is ture, loadPartition() will wait until partition finish loading, - // this value control the waiting interval. Unit: millisecond. Default value: 500 milliseconds. - private Long syncLoadWaitingInterval = 500L; - - // syncLoadWaitingTimeout: - // When syncLoad is ture, loadPartition() will wait until partition finish loading, - // this value control the waiting timeout. Unit: second. Default value: 60 seconds. - private Long syncLoadWaitingTimeout = 60L; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set partition names list. Partition names list cannot be null or empty. - * - * @param partitionNames partition names list - * @return Builder - */ - public Builder withPartitionNames(@NonNull List partitionNames) { - partitionNames.forEach(this::addPartitionName); - return this; - } - - /** - * Add a partition name. Partition name cannot be empty or null. - * - * @param partitionName partition name - * @return Builder - */ - public Builder addPartitionName(@NonNull String partitionName) { - if (!this.partitionNames.contains(partitionName)) { - this.partitionNames.add(partitionName); - } - return this; - } - - /** - * Set load action to sync mode. - * With sync mode, the client side will keep waiting until all segments of the partition successfully loaded. - * - * If not sync mode, client will return at once after the loadPartitions() is called. - * - * @param syncLoad Boolean.TRUE is sync mode, Boolean.FALSE is not - * @return Builder - */ - public Builder withSyncLoad(@NonNull Boolean syncLoad) { - this.syncLoad = syncLoad; - return this; - } - - /** - * Set waiting interval in sync mode. In sync mode, the client will constantly check partition load state by interval. - * Interval must be larger than zero, and cannot be larger than Constant.MAX_WAITING_LOADING_INTERVAL. - * @see Constant - * - * @param milliseconds interval - * @return Builder - */ - public Builder withSyncLoadWaitingInterval(@NonNull Long milliseconds) { - this.syncLoadWaitingInterval = milliseconds; - return this; - } - - /** - * Set time out value for sync mode. - * Time out value must be larger than zero, and cannot be larger than Constant.MAX_WAITING_LOADING_TIMEOUT. - * @see Constant - * - * @param seconds time out value for sync mode - * @return Builder - */ - public Builder withSyncLoadWaitingTimeout(@NonNull Long seconds) { - this.syncLoadWaitingTimeout = seconds; - return this; - } - - /** - * Verify parameters and create a new LoadPartitionsParam instance. - * - * @return LoadPartitionsParam - */ - public LoadPartitionsParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - if (partitionNames.isEmpty()) { - throw new ParamException("Partition names cannot be empty"); - } - - for (String name : partitionNames) { - ParamUtils.CheckNullEmptyString(name, "Partition name"); - } - - if (syncLoad == Boolean.TRUE) { - if (syncLoadWaitingInterval <= 0) { - throw new ParamException("Sync load waiting interval must be larger than zero"); - } else if (syncLoadWaitingInterval > Constant.MAX_WAITING_LOADING_INTERVAL) { - throw new ParamException("Sync load waiting interval cannot be larger than " - + Constant.MAX_WAITING_LOADING_INTERVAL.toString() + " milliseconds"); - } - - if (syncLoadWaitingTimeout <= 0) { - throw new ParamException("Sync load waiting interval must be larger than zero"); - } else if (syncLoadWaitingTimeout > Constant.MAX_WAITING_LOADING_TIMEOUT) { - throw new ParamException("Sync load waiting interval cannot be larger than " - + Constant.MAX_WAITING_LOADING_TIMEOUT.toString() + " seconds"); - } - } - - return new LoadPartitionsParam(this); - } - } - - /** - * Construct a String by LoadPartitionsParam instance. - * - * @return String - */ - @Override - public String toString() { - return "LoadPartitionsParam{" + - "collectionName='" + collectionName + '\'' + - ", partitionName='" + partitionNames.toString() + '\'' + - ", syncLoad=" + syncLoad + - ", syncLoadWaitingInterval=" + syncLoadWaitingInterval + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/partition/ReleasePartitionsParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/partition/ReleasePartitionsParam.java deleted file mode 100644 index 07ca361..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/partition/ReleasePartitionsParam.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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 - * - * 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.param.partition; - -import io.milvus.exception.ParamException; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; -import java.util.ArrayList; -import java.util.List; - -/** - * Parameters for releasePartition interface. - */ -@Getter -public class ReleasePartitionsParam { - private final String collectionName; - private final List partitionNames; - - private ReleasePartitionsParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.partitionNames = builder.partitionNames; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for ReleasePartitionsParam class. - */ - public static final class Builder { - private String collectionName; - private final List partitionNames = new ArrayList<>(); - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set partition names list. Partition names list cannot be null or empty. - * - * @param partitionNames partition names list - * @return Builder - */ - public Builder withPartitionNames(@NonNull List partitionNames) { - partitionNames.forEach(this::addPartitionName); - return this; - } - - /** - * Add a partition name. Partition name cannot be empty or null. - * - * @param partitionName partition name - * @return Builder - */ - public Builder addPartitionName(@NonNull String partitionName) { - if (!this.partitionNames.contains(partitionName)) { - this.partitionNames.add(partitionName); - } - return this; - } - - /** - * Verify parameters and create a new ReleasePartitionsParam instance. - * - * @return ReleasePartitionsParam - */ - public ReleasePartitionsParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - if (partitionNames.isEmpty()) { - throw new ParamException("Partition names cannot be empty"); - } - - for (String name : partitionNames) { - ParamUtils.CheckNullEmptyString(name, "Partition name"); - } - - return new ReleasePartitionsParam(this); - } - } - - /** - * Construct a String by ReleasePartitionsParam instance. - * - * @return String - */ - @Override - public String toString() { - return "ReleasePartitionsParam{" + - "collectionName='" + collectionName + '\'' + - ", partitionNames='" + partitionNames.toString() + '\'' + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/java/io/milvus/param/partition/ShowPartitionsParam.java b/milvus-java-sdk/src/main/java/io/milvus/param/partition/ShowPartitionsParam.java deleted file mode 100644 index c49c24a..0000000 --- a/milvus-java-sdk/src/main/java/io/milvus/param/partition/ShowPartitionsParam.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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 - * - * 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.param.partition; - -import io.milvus.exception.ParamException; -import io.milvus.grpc.ShowType; -import io.milvus.param.ParamUtils; - -import lombok.Getter; -import lombok.NonNull; -import java.util.ArrayList; -import java.util.List; - -/** - * Parameters for showPartition interface. - */ -@Getter -public class ShowPartitionsParam { - private final String collectionName; - private final List partitionNames; - private final ShowType showType; - - private ShowPartitionsParam(@NonNull Builder builder) { - this.collectionName = builder.collectionName; - this.partitionNames = builder.partitionNames; - this.showType = builder.showType; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for ShowPartitionsParam class. - */ - public static final class Builder { - private String collectionName; - private List partitionNames = new ArrayList<>(); - - // showType: - // default showType = ShowType.All - // if partitionNames is not empty, set showType = ShowType.InMemory - private ShowType showType = ShowType.All; - - private Builder() { - } - - /** - * Set collection name. Collection name cannot be empty or null. - * - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(@NonNull String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set partition names list. Partition names list cannot be null or empty. - * - * @param partitionNames partition names list - * @return Builder - */ - public Builder withPartitionNames(@NonNull List partitionNames) { - partitionNames.forEach(this::addPartitionName); - return this; - } - - /** - * Add a partition name. Partition name cannot be empty or null. - * - * @param partitionName partition name - * @return Builder - */ - public Builder addPartitionName(@NonNull String partitionName) { - if (!this.partitionNames.contains(partitionName)) { - this.partitionNames.add(partitionName); - } - return this; - } - - /** - * Verify parameters and create a new ShowPartitionsParam instance. - * - * @return ShowPartitionsParam - */ - public ShowPartitionsParam build() throws ParamException { - ParamUtils.CheckNullEmptyString(collectionName, "Collection name"); - - if (partitionNames != null && !partitionNames.isEmpty()) { - for (String partitionName : partitionNames) { - ParamUtils.CheckNullEmptyString(partitionName, "Partition name"); - } - this.showType = ShowType.InMemory; - } - - return new ShowPartitionsParam(this); - } - } - - /** - * Construct a String by ShowPartitionsParam instance. - * - * @return String - */ - @Override - public String toString() { - return "ShowPartitionsParam{" + - "collectionName='" + collectionName + '\'' + - ", partitionNames='" + partitionNames.toString() + '\'' + - ", showType=" + showType.toString() + - '}'; - } -} diff --git a/milvus-java-sdk/src/main/proto/common.proto b/milvus-java-sdk/src/main/proto/common.proto deleted file mode 100644 index acd0aa2..0000000 --- a/milvus-java-sdk/src/main/proto/common.proto +++ /dev/null @@ -1,187 +0,0 @@ -syntax = "proto3"; - -package common; -option java_multiple_files = true; -option java_package = "io.milvus.grpc"; -option java_outer_classname = "CommonProto"; -option java_generate_equals_and_hash = true; - - -enum ErrorCode { - Success = 0; - UnexpectedError = 1; - ConnectFailed = 2; - PermissionDenied = 3; - CollectionNotExists = 4; - IllegalArgument = 5; - IllegalDimension = 7; - IllegalIndexType = 8; - IllegalCollectionName = 9; - IllegalTOPK = 10; - IllegalRowRecord = 11; - IllegalVectorID = 12; - IllegalSearchResult = 13; - FileNotFound = 14; - MetaFailed = 15; - CacheFailed = 16; - CannotCreateFolder = 17; - CannotCreateFile = 18; - CannotDeleteFolder = 19; - CannotDeleteFile = 20; - BuildIndexError = 21; - IllegalNLIST = 22; - IllegalMetricType = 23; - OutOfMemory = 24; - IndexNotExist = 25; - EmptyCollection = 26; - - // internal error code. - DDRequestRace = 1000; -} - -enum IndexState { - IndexStateNone = 0; - Unissued = 1; - InProgress = 2; - Finished = 3; - Failed = 4; -} - -enum SegmentState { - SegmentStateNone = 0; - NotExist = 1; - Growing = 2; - Sealed = 3; - Flushed = 4; - Flushing = 5; - Dropped = 6; -} - -message Status { - ErrorCode error_code = 1; - string reason = 2; -} - -message KeyValuePair { - string key = 1; - string value = 2; -} - -message KeyDataPair { - string key = 1; - bytes data = 2; -} - -message Blob { - bytes value = 1; -} - -message Address { - string ip = 1; - int64 port = 2; -} - -enum MsgType { - Undefined = 0; - /* DEFINITION REQUESTS: COLLECTION */ - CreateCollection = 100; - DropCollection = 101; - HasCollection = 102; - DescribeCollection = 103; - ShowCollections = 104; - GetSystemConfigs = 105; - LoadCollection = 106; - ReleaseCollection = 107; - CreateAlias = 108; - DropAlias = 109; - AlterAlias = 110; - - - /* DEFINITION REQUESTS: PARTITION */ - CreatePartition = 200; - DropPartition = 201; - HasPartition = 202; - DescribePartition = 203; - ShowPartitions = 204; - LoadPartitions = 205; - ReleasePartitions = 206; - - /* DEFINE REQUESTS: SEGMENT */ - ShowSegments = 250; - DescribeSegment = 251; - LoadSegments = 252; - ReleaseSegments = 253; - HandoffSegments = 254; - LoadBalanceSegments = 255; - - /* DEFINITION REQUESTS: INDEX */ - CreateIndex = 300; - DescribeIndex = 301; - DropIndex = 302; - - /* MANIPULATION REQUESTS */ - Insert = 400; - Delete = 401; - Flush = 402; - - /* QUERY */ - Search = 500; - SearchResult = 501; - GetIndexState = 502; - GetIndexBuildProgress = 503; - GetCollectionStatistics = 504; - GetPartitionStatistics = 505; - Retrieve = 506; - RetrieveResult = 507; - WatchDmChannels = 508; - RemoveDmChannels = 509; - WatchQueryChannels = 510; - RemoveQueryChannels = 511; - SealedSegmentsChangeInfo = 512; - WatchDeltaChannels = 513; - - /* DATA SERVICE */ - SegmentInfo = 600; - SystemInfo = 601; - - /* SYSTEM CONTROL */ - TimeTick = 1200; - QueryNodeStats = 1201; // GOOSE TODO: Remove kQueryNodeStats - LoadIndex = 1202; - RequestID = 1203; - RequestTSO = 1204; - AllocateSegment = 1205; - SegmentStatistics = 1206; - SegmentFlushDone = 1207; - - DataNodeTt = 1208; -} - -message MsgBase { - MsgType msg_type = 1; - int64 msgID = 2; - uint64 timestamp = 3; - int64 sourceID = 4; -} - -enum DslType { - Dsl = 0; - BoolExprV1 = 1; -} - -// Don't Modify This. @czs -message MsgHeader { - common.MsgBase base = 1; -} - -// Don't Modify This. @czs -message DMLMsgHeader { - common.MsgBase base = 1; - string shardName = 2; -} - -enum CompactionState { - UndefiedState = 0; - Executing = 1; - Completed = 2; -} diff --git a/milvus-java-sdk/src/main/proto/milvus.proto b/milvus-java-sdk/src/main/proto/milvus.proto deleted file mode 100644 index 0ded8b9..0000000 --- a/milvus-java-sdk/src/main/proto/milvus.proto +++ /dev/null @@ -1,773 +0,0 @@ -syntax = "proto3"; - -import "common.proto"; -import "schema.proto"; - -option java_multiple_files = true; -option java_package = "io.milvus.grpc"; -option java_outer_classname = "MilvusProto"; -option java_generate_equals_and_hash = true; - -package milvus.proto.milvus; - -service MilvusService { - rpc CreateCollection(CreateCollectionRequest) returns (common.Status) {} - rpc DropCollection(DropCollectionRequest) returns (common.Status) {} - rpc HasCollection(HasCollectionRequest) returns (BoolResponse) {} - rpc LoadCollection(LoadCollectionRequest) returns (common.Status) {} - rpc ReleaseCollection(ReleaseCollectionRequest) returns (common.Status) {} - rpc DescribeCollection(DescribeCollectionRequest) returns (DescribeCollectionResponse) {} - rpc GetCollectionStatistics(GetCollectionStatisticsRequest) returns (GetCollectionStatisticsResponse) {} - rpc ShowCollections(ShowCollectionsRequest) returns (ShowCollectionsResponse) {} - - rpc CreatePartition(CreatePartitionRequest) returns (common.Status) {} - rpc DropPartition(DropPartitionRequest) returns (common.Status) {} - rpc HasPartition(HasPartitionRequest) returns (BoolResponse) {} - rpc LoadPartitions(LoadPartitionsRequest) returns (common.Status) {} - rpc ReleasePartitions(ReleasePartitionsRequest) returns (common.Status) {} - rpc GetPartitionStatistics(GetPartitionStatisticsRequest) returns (GetPartitionStatisticsResponse) {} - rpc ShowPartitions(ShowPartitionsRequest) returns (ShowPartitionsResponse) {} - - rpc CreateAlias(CreateAliasRequest) returns (common.Status) {} - rpc DropAlias(DropAliasRequest) returns (common.Status) {} - rpc AlterAlias(AlterAliasRequest) returns (common.Status) {} - - rpc CreateIndex(CreateIndexRequest) returns (common.Status) {} - rpc DescribeIndex(DescribeIndexRequest) returns (DescribeIndexResponse) {} - rpc GetIndexState(GetIndexStateRequest) returns (GetIndexStateResponse) {} - rpc GetIndexBuildProgress(GetIndexBuildProgressRequest) returns (GetIndexBuildProgressResponse) {} - rpc DropIndex(DropIndexRequest) returns (common.Status) {} - - rpc Insert(InsertRequest) returns (MutationResult) {} - rpc Delete(DeleteRequest) returns (MutationResult) {} - rpc Search(SearchRequest) returns (SearchResults) {} - rpc Flush(FlushRequest) returns (FlushResponse) {} - rpc Query(QueryRequest) returns (QueryResults) {} - rpc CalcDistance(CalcDistanceRequest) returns (CalcDistanceResults) {} - - rpc GetPersistentSegmentInfo(GetPersistentSegmentInfoRequest) returns (GetPersistentSegmentInfoResponse) {} - rpc GetQuerySegmentInfo(GetQuerySegmentInfoRequest) returns (GetQuerySegmentInfoResponse) {} - - rpc Dummy(DummyRequest) returns (DummyResponse) {} - - // TODO: remove - rpc RegisterLink(RegisterLinkRequest) returns (RegisterLinkResponse) {} - - // https://wiki.lfaidata.foundation/display/MIL/MEP+8+--+Add+metrics+for+proxy - rpc GetMetrics(GetMetricsRequest) returns (GetMetricsResponse) {} - rpc LoadBalance(LoadBalanceRequest) returns (common.Status) {} - rpc GetCompactionState(GetCompactionStateRequest) returns (GetCompactionStateResponse) {} - rpc ManualCompaction(ManualCompactionRequest) returns (ManualCompactionResponse) {} - rpc GetCompactionStateWithPlans(GetCompactionPlansRequest) returns (GetCompactionPlansResponse) {} -} - -message CreateAliasRequest { - common.MsgBase base = 1; - string db_name = 2; - string collection_name = 3; - string alias = 4; -} - -message DropAliasRequest { - common.MsgBase base = 1; - string db_name = 2; - string alias = 3; -} - -message AlterAliasRequest{ - common.MsgBase base = 1; - string db_name = 2; - string collection_name = 3; - string alias = 4; -} - -/** -* Create collection in milvus -*/ -message CreateCollectionRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The unique collection name in milvus.(Required) - string collection_name = 3; - // The serialized `schema.CollectionSchema`(Required) - bytes schema = 4; - // Once set, no modification is allowed (Optional) - // https://github.com/milvus-io/milvus/issues/6690 - int32 shards_num = 5; -} - -/** -* Drop collection in milvus, also will drop data in collection. -*/ -message DropCollectionRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The unique collection name in milvus.(Required) - string collection_name = 3; -} - -/** -* Check collection exist in milvus or not. -*/ -message HasCollectionRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name you want to check. - string collection_name = 3; - // If time_stamp is not zero, will return true when time_stamp >= created collection timestamp, otherwise will return false. - uint64 time_stamp = 4; -} - - -message BoolResponse { - common.Status status = 1; - bool value = 2; -} - -message StringResponse { - common.Status status = 1; - string value = 2; -} - -/** -* Get collection meta datas like: schema, collectionID, shards number ... -*/ -message DescribeCollectionRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name you want to describe, you can pass collection_name or collectionID - string collection_name = 3; - // The collection ID you want to describe - int64 collectionID = 4; - // If time_stamp is not zero, will describe collection success when time_stamp >= created collection timestamp, otherwise will throw error. - uint64 time_stamp = 5; -} - -/** -* DescribeCollection Response -*/ -message DescribeCollectionResponse { - // Contain error_code and reason - common.Status status = 1; - // The schema param when you created collection. - schema.CollectionSchema schema = 2; - // The collection id - int64 collectionID = 3; - // System design related, users should not perceive - repeated string virtual_channel_names = 4; - // System design related, users should not perceive - repeated string physical_channel_names = 5; - // Hybrid timestamp in milvus - uint64 created_timestamp = 6; - // The utc timestamp calculated by created_timestamp - uint64 created_utc_timestamp = 7; - // The shards number you set. - int32 shards_num = 8; - // The aliases of this collection - repeated string aliases = 9; - // The message ID/posititon when collection is created - repeated common.KeyDataPair start_positions = 10; -} - -/** -* Load collection data into query nodes, then you can do vector search on this collection. -*/ -message LoadCollectionRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name you want to load - string collection_name = 3; -} - -/** -* Release collection data from query nodes, then you can't do vector search on this collection. -*/ -message ReleaseCollectionRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name you want to release - string collection_name = 3; -} - -/** -* Get collection statistics like row_count. -*/ -message GetCollectionStatisticsRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name you want get statistics - string collection_name = 3; -} - -/** -* Will return collection statistics in stats field like [{key:"row_count",value:"1"}] -*/ -message GetCollectionStatisticsResponse { - // Contain error_code and reason - common.Status status = 1; - // Collection statistics data - repeated common.KeyValuePair stats = 2; -} - -/* -* This is for ShowCollectionsRequest type field. -*/ -enum ShowType { - // Will return all colloections - All = 0; - // Will return loaded collections with their inMemory_percentages - InMemory = 1; -} - -/* -* List collections -*/ -message ShowCollectionsRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // Not useful for now - uint64 time_stamp = 3; - // Decide return Loaded collections or All collections(Optional) - ShowType type = 4; - // When type is InMemory, will return these collection's inMemory_percentages.(Optional) - repeated string collection_names = 5; -} - -/* -* Return basic collection infos. -*/ -message ShowCollectionsResponse { - // Contain error_code and reason - common.Status status = 1; - // Collection name array - repeated string collection_names = 2; - // Collection Id array - repeated int64 collection_ids = 3; - // Hybrid timestamps in milvus - repeated uint64 created_timestamps = 4; - // The utc timestamp calculated by created_timestamp - repeated uint64 created_utc_timestamps = 5; - // Load percentage on querynode when type is InMemory - repeated int64 inMemory_percentages = 6; -} - -/* -* Create partition in created collection. -*/ -message CreatePartitionRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name in milvus - string collection_name = 3; - // The partition name you want to create. - string partition_name = 4; -} - -/* -* Drop partition in created collection. -*/ -message DropPartitionRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name in milvus - string collection_name = 3; - // The partition name you want to drop - string partition_name = 4; -} - -/* -* Check if partition exist in collection or not. -*/ -message HasPartitionRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name in milvus - string collection_name = 3; - // The partition name you want to check - string partition_name = 4; -} - -/* -* Load specific partitions data of one collection into query nodes -* Then you can get these data as result when you do vector search on this collection. -*/ -message LoadPartitionsRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name in milvus - string collection_name = 3; - // The partition names you want to load - repeated string partition_names = 4; -} - -/* -* Release specific partitions data of one collection from query nodes. -* Then you can not get these data as result when you do vector search on this collection. -*/ -message ReleasePartitionsRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name in milvus - string collection_name = 3; - // The partition names you want to release - repeated string partition_names = 4; -} - -/* -* Get partition statistics like row_count. -*/ -message GetPartitionStatisticsRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name in milvus - string collection_name = 3; - // The partition name you want to collect statistics - string partition_name = 4; -} - -message GetPartitionStatisticsResponse { - common.Status status = 1; - repeated common.KeyValuePair stats = 2; -} - -/* -* List all partitions for particular collection -*/ -message ShowPartitionsRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The collection name you want to describe, you can pass collection_name or collectionID - string collection_name = 3; - // The collection id in milvus - int64 collectionID = 4; - // When type is InMemory, will return these patitions's inMemory_percentages.(Optional) - repeated string partition_names = 5; - // Decide return Loaded partitions or All partitions(Optional) - ShowType type = 6; -} - -/* -* List all partitions for particular collection response. -* The returned datas are all rows, we can format to columns by therir index. -*/ -message ShowPartitionsResponse { - // Contain error_code and reason - common.Status status = 1; - // All partition names for this collection - repeated string partition_names = 2; - // All partition ids for this collection - repeated int64 partitionIDs = 3; - // All hybrid timestamps - repeated uint64 created_timestamps = 4; - // All utc timestamps calculated by created_timestamps - repeated uint64 created_utc_timestamps = 5; - // Load percentage on querynode - repeated int64 inMemory_percentages = 6; -} - -message DescribeSegmentRequest { - common.MsgBase base = 1; - int64 collectionID = 2; - int64 segmentID = 3; -} - -message DescribeSegmentResponse { - common.Status status = 1; - int64 indexID = 2; - int64 buildID = 3; - bool enable_index = 4; -} - -message ShowSegmentsRequest { - common.MsgBase base = 1; - int64 collectionID = 2; - int64 partitionID = 3; -} - -message ShowSegmentsResponse { - common.Status status = 1; - repeated int64 segmentIDs = 2; -} - -/* -* Create index for vector datas -*/ -message CreateIndexRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The particular collection name you want to create index. - string collection_name = 3; - // The vector field name in this particular collection - string field_name = 4; - // Support keys: index_type,metric_type, params. Different index_type may has different params. - repeated common.KeyValuePair extra_params = 5; -} - -/* -* Get created index information. -* Current release of Milvus only supports showing latest built index. -*/ -message DescribeIndexRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2; - // The particular collection name in Milvus - string collection_name = 3; - // The vector field name in this particular collection - string field_name = 4; - // No need to set up for now @2021.06.30 - string index_name = 5; -} - -/* -* Index informations -*/ -message IndexDescription { - // Index name - string index_name = 1; - // Index id - int64 indexID = 2; - // Will return index_type, metric_type, params(like nlist). - repeated common.KeyValuePair params = 3; - // The vector field name - string field_name = 4; -} - -/* -* Describe index response -*/ -message DescribeIndexResponse { - // Response status - common.Status status = 1; - // All index informations, for now only return tha latest index you created for the collection. - repeated IndexDescription index_descriptions = 2; -} - -/* -* Get index building progress -*/ -message GetIndexBuildProgressRequest { - // Not useful for now - common.MsgBase base = 1; - // Not useful for now - string db_name = 2 ; - // The collection name in milvus - string collection_name = 3; - // The vector field name in this collection - string field_name = 4; - // Not useful for now - string index_name = 5; -} - -message GetIndexBuildProgressResponse { - common.Status status = 1; - int64 indexed_rows = 2; - int64 total_rows = 3; -} - -message GetIndexStateRequest { - common.MsgBase base = 1; // must - string db_name = 2 ; - string collection_name = 3; // must - string field_name = 4; - string index_name = 5; // No need to set up for now @2021.06.30 -} - -message GetIndexStateResponse { - common.Status status = 1; - common.IndexState state = 2; - string fail_reason = 3; -} - -message DropIndexRequest { - common.MsgBase base = 1; // must - string db_name = 2; - string collection_name = 3; // must - string field_name = 4; - string index_name = 5; // No need to set up for now @2021.06.30 -} - -message InsertRequest { - common.MsgBase base = 1; - string db_name = 2; - string collection_name = 3; - string partition_name = 4; - repeated schema.FieldData fields_data = 5; - repeated uint32 hash_keys = 6; - uint32 num_rows = 7; -} - -message MutationResult { - common.Status status = 1; - schema.IDs IDs = 2; // required for insert, delete - repeated uint32 succ_index = 3; // error indexes indicate - repeated uint32 err_index = 4; // error indexes indicate - bool acknowledged = 5; - int64 insert_cnt = 6; - int64 delete_cnt = 7; - int64 upsert_cnt = 8; - uint64 timestamp = 9; -} - -message DeleteRequest { - common.MsgBase base = 1; - string db_name = 2; - string collection_name = 3; - string partition_name = 4; - string expr = 5; - repeated uint32 hash_keys = 6; -} - -enum PlaceholderType { - None = 0; - BinaryVector = 100; - FloatVector = 101; -} - -message PlaceholderValue { - string tag = 1; - PlaceholderType type = 2; - // values is a 2d-array, every array contains a vector - repeated bytes values = 3; -} - -message PlaceholderGroup { - repeated PlaceholderValue placeholders = 1; -} - -message SearchRequest { - common.MsgBase base = 1; // must - string db_name = 2; - string collection_name = 3; // must - repeated string partition_names = 4; // must - string dsl = 5; // must - // serialized `PlaceholderGroup` - bytes placeholder_group = 6; // must - common.DslType dsl_type = 7; // must - repeated string output_fields = 8; - repeated common.KeyValuePair search_params = 9; // must - uint64 travel_timestamp = 10; - uint64 guarantee_timestamp = 11; // guarantee_timestamp -} - -message Hits { - repeated int64 IDs = 1; - repeated bytes row_data = 2; - repeated float scores = 3; -} - -message SearchResults { - common.Status status = 1; - schema.SearchResultData results = 2; -} - -message FlushRequest { - common.MsgBase base = 1; - string db_name = 2; - repeated string collection_names = 3; -} - -message FlushResponse{ - common.Status status = 1; - string db_name = 2; - map coll_segIDs = 3; -} - -message QueryRequest { - common.MsgBase base = 1; - string db_name = 2; - string collection_name = 3; - string expr = 4; - repeated string output_fields = 5; - repeated string partition_names = 6; - uint64 travel_timestamp = 7; - uint64 guarantee_timestamp = 8; // guarantee_timestamp -} - -message QueryResults { - common.Status status = 1; - repeated schema.FieldData fields_data = 2; -} - -message VectorIDs { - string collection_name = 1; - string field_name = 2; - schema.IDs id_array = 3; - repeated string partition_names = 4; -} - -message VectorsArray { - oneof array { - VectorIDs id_array = 1; // vector ids - schema.VectorField data_array = 2; // vectors data - } -} - -message CalcDistanceRequest { - common.MsgBase base = 1; - VectorsArray op_left = 2; // vectors on the left of operator - VectorsArray op_right = 3; // vectors on the right of operator - repeated common.KeyValuePair params = 4; // "metric":"L2"/"IP"/"HAMMIN"/"TANIMOTO" -} - -message CalcDistanceResults { - common.Status status = 1; - // num(op_left)*num(op_right) distance values, "HAMMIN" return integer distance - oneof array { - schema.IntArray int_dist = 2; - schema.FloatArray float_dist = 3; - } -} - -message PersistentSegmentInfo { - int64 segmentID = 1; - int64 collectionID = 2; - int64 partitionID = 3; - int64 num_rows = 4; - common.SegmentState state = 5; -} - -message GetPersistentSegmentInfoRequest { - common.MsgBase base = 1; // must - string dbName = 2; - string collectionName = 3; // must -} - -message GetPersistentSegmentInfoResponse { - common.Status status = 1; - repeated PersistentSegmentInfo infos = 2; -} - -message QuerySegmentInfo { - int64 segmentID = 1; - int64 collectionID = 2; - int64 partitionID = 3; - int64 mem_size = 4; - int64 num_rows = 5; - string index_name = 6; - int64 indexID = 7; - int64 nodeID = 8; - common.SegmentState state = 9; -} - -message GetQuerySegmentInfoRequest { - common.MsgBase base = 1; // must - string dbName = 2; - string collectionName = 3; // must -} - -message GetQuerySegmentInfoResponse { - common.Status status = 1; - repeated QuerySegmentInfo infos = 2; -} - -message DummyRequest { - string request_type = 1; -} - -message DummyResponse { - string response = 1; -} - -message RegisterLinkRequest { -} - -message RegisterLinkResponse { - common.Address address = 1; - common.Status status = 2; -} - -message GetMetricsRequest { - common.MsgBase base = 1; - string request = 2; // request is of jsonic format -} - -message GetMetricsResponse { - common.Status status = 1; - string response = 2; // response is of jsonic format - string component_name = 3; // metrics from which component -} - -/* -* Do load balancing operation from src_nodeID to dst_nodeID. -*/ -message LoadBalanceRequest { - common.MsgBase base = 1; - int64 src_nodeID = 2; - repeated int64 dst_nodeIDs = 3; - repeated int64 sealed_segmentIDs = 4; -} - -message ManualCompactionRequest { - int64 collectionID = 1; - uint64 timetravel = 2; -} - -message ManualCompactionResponse { - common.Status status = 1; - int64 compactionID = 2; -} - -message GetCompactionStateRequest { - int64 compactionID = 1; -} - -message GetCompactionStateResponse { - common.Status status = 1; - common.CompactionState state = 2; - int64 executingPlanNo = 3; - int64 timeoutPlanNo = 4; - int64 completedPlanNo = 5; -} - -message GetCompactionPlansRequest { - int64 compactionID = 1; -} - -message GetCompactionPlansResponse { - common.Status status = 1; - common.CompactionState state = 2; - repeated CompactionMergeInfo mergeInfos = 3; -} - -message CompactionMergeInfo { - repeated int64 sources = 1; - int64 target = 2; -} - -service ProxyService { - rpc RegisterLink(RegisterLinkRequest) returns (RegisterLinkResponse) {} -} diff --git a/milvus-java-sdk/src/main/proto/schema.proto b/milvus-java-sdk/src/main/proto/schema.proto deleted file mode 100644 index 9ddcaa9..0000000 --- a/milvus-java-sdk/src/main/proto/schema.proto +++ /dev/null @@ -1,128 +0,0 @@ -syntax = "proto3"; - -import "common.proto"; - -package schema; -option java_multiple_files = true; -option java_package = "io.milvus.grpc"; -option java_outer_classname = "SchemaProto"; -option java_generate_equals_and_hash = true; - -/** - * @brief Field data type - */ -enum DataType { - None = 0; - Bool = 1; - Int8 = 2; - Int16 = 3; - Int32 = 4; - Int64 = 5; - - Float = 10; - Double = 11; - - String = 20; - - BinaryVector = 100; - FloatVector = 101; -} - -/** - * @brief Field schema - */ -message FieldSchema { - int64 fieldID = 1; - string name = 2; - bool is_primary_key = 3; - string description = 4; - DataType data_type = 5; - repeated common.KeyValuePair type_params = 6; - repeated common.KeyValuePair index_params = 7; - bool autoID = 8; -} - -/** - * @brief Collection schema - */ -message CollectionSchema { - string name = 1; - string description = 2; - bool autoID = 3; // deprecated later, keep compatible with c++ part now - repeated FieldSchema fields = 4; -} - -message BoolArray { - repeated bool data = 1; -} - -message IntArray { - repeated int32 data = 1; -} - -message LongArray { - repeated int64 data = 1; -} - -message FloatArray { - repeated float data = 1; -} - -message DoubleArray { - repeated double data = 1; -} - -// For special fields such as bigdecimal, array... -message BytesArray { - repeated bytes data = 1; -} - -message StringArray { - repeated string data = 1; -} - -message ScalarField { - oneof data { - BoolArray bool_data = 1; - IntArray int_data = 2; - LongArray long_data = 3; - FloatArray float_data = 4; - DoubleArray double_data = 5; - StringArray string_data = 6; - BytesArray bytes_data = 7; - } -} - -message VectorField { - int64 dim = 1; - oneof data { - FloatArray float_vector = 2; - bytes binary_vector = 3; - } -} - -message FieldData { - DataType type = 1; - string field_name = 2; - oneof field { - ScalarField scalars = 3; - VectorField vectors = 4; - } - int64 field_id = 5; -} - -message IDs { - oneof id_field { - LongArray int_id = 1; - StringArray str_id = 2; - } -} - -message SearchResultData { - int64 num_queries = 1; - int64 top_k = 2; - repeated FieldData fields_data = 3; - repeated float scores = 4; - IDs ids = 5; - repeated int64 topks = 6; -} diff --git a/milvus-java-sdk/src/main/resources/log4j2.xml b/milvus-java-sdk/src/main/resources/log4j2.xml deleted file mode 100644 index e13b79d..0000000 --- a/milvus-java-sdk/src/main/resources/log4j2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/milvus-java-sdk/src/main/resources/milvus-client.properties b/milvus-java-sdk/src/main/resources/milvus-client.properties deleted file mode 100644 index 951752f..0000000 --- a/milvus-java-sdk/src/main/resources/milvus-client.properties +++ /dev/null @@ -1,3 +0,0 @@ -groupId=${project.groupId} -artifactId=${project.artifactId} -version=${project.version} diff --git a/pom.xml b/pom.xml index ed00b02..602ef28 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,6 @@ ${project.version} - org.openpnp opencv diff --git a/proxima-be-java-sdk/pom.xml b/proxima-be-java-sdk/pom.xml deleted file mode 100644 index 4ac0c65..0000000 --- a/proxima-be-java-sdk/pom.xml +++ /dev/null @@ -1,127 +0,0 @@ - - - - 4.0.0 - com.alibaba.proxima - proxima-be-java-sdk - 0.2.0 - - - UTF-8 - - - - - io.grpc - grpc-netty-shaded - 1.36.0 - - - io.grpc - grpc-stub - 1.36.0 - - - io.grpc - grpc-protobuf - 1.36.0 - - - com.google.guava - guava - 21.0 - - - org.projectlombok - lombok - 1.16.16 - - - com.google.protobuf - protobuf-java - 3.14.0 - - - org.slf4j - slf4j-api - 1.7.30 - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.12.1 - - - - - - - src/main/resources - true - - - - - kr.motd.maven - os-maven-plugin - 1.6.2 - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.8 - 1.8 - UTF-8 - - - - org.xolstice.maven.plugins - protobuf-maven-plugin - 0.6.1 - - com.google.protobuf:protoc:3.14.0:exe:${os.detected.classifier} - grpc-java - io.grpc:protoc-gen-grpc-java:1.36.0:exe:${os.detected.classifier} - false - - - - - compile - compile-custom - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - true - - - - - - - - maven-jar-plugin - 3.0.2 - - - *.proto - - - - - - - - \ No newline at end of file diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/CollectionConfig.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/CollectionConfig.java deleted file mode 100644 index 2a21071..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/CollectionConfig.java +++ /dev/null @@ -1,199 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief CollectionConfig contains params for collection - */ - -package com.alibaba.proxima.be.client; - -import java.util.*; - -/** - * Contains config for collection - */ -public class CollectionConfig { - private final String collectionName; - private final long maxDocsPerSegment; - private final List forwardColumnNames; - private final List indexColumnParams; - private final DatabaseRepository databaseRepository; - - private CollectionConfig(Builder builder) { - this.collectionName = builder.collectionName; - this.maxDocsPerSegment = builder.maxDocsPerSegment; - this.forwardColumnNames = builder.forwardColumnNames; - this.indexColumnParams = builder.indexColumnParams; - this.databaseRepository = builder.databaseRepository; - } - - public String getCollectionName() { - return collectionName; - } - - public long getMaxDocsPerSegment() { - return maxDocsPerSegment; - } - - public List getForwardColumnNames() { - return forwardColumnNames; - } - - public List getIndexColumnParams() { - return indexColumnParams; - } - - public DatabaseRepository getDatabaseRepository() { - return databaseRepository; - } - - /** - * New collection config builder object - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for CollectionConfig - */ - public static class Builder { - // Required parameters - private String collectionName; - private List indexColumnParams = new ArrayList<>(); - - // Optional parameters - private long maxDocsPerSegment = 0; - private List forwardColumnNames = new ArrayList<>(); - private DatabaseRepository databaseRepository = null; - - /** - * Constructor without parameters - */ - public Builder() { - } - - /** - * Constructor with collectionName and indexColumnParams - * @param collectionName collection name - * @param indexColumnParams index column parameters - */ - public Builder(String collectionName, List indexColumnParams) { - this.collectionName = collectionName; - this.indexColumnParams = indexColumnParams; - } - - /** - * Set collection name - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Optional. Set forward column names - * @param forwardColumnNames forward column name list - * @return Builder - */ - public Builder withForwardColumnNames(List forwardColumnNames) { - this.forwardColumnNames = forwardColumnNames; - return this; - } - - // - - /** - * Optional. Set max docs per segment. Default 0 - * @param maxDocsPerSegment max docs per segment - * @return Builder - */ - public Builder withMaxDocsPerSegment(long maxDocsPerSegment) { - this.maxDocsPerSegment = maxDocsPerSegment; - return this; - } - - // Set index column params list - - /** - * Set index column parameters - * @param indexColumnParams index column parameters - * @return Buildder - */ - public Builder withIndexColumnParams(List indexColumnParams) { - this.indexColumnParams = indexColumnParams; - return this; - } - - /** - * Optional. Set database repository - * @param databaseRepository mysql database repository - * @return Builder - */ - public Builder withDatabaseRepository(DatabaseRepository databaseRepository) { - this.databaseRepository = databaseRepository; - return this; - } - - /** - * Add one forward column - * @param forwardColumn forward column name - * @return Builder - */ - public Builder addForwardColumn(String forwardColumn) { - this.forwardColumnNames.add(forwardColumn); - return this; - } - - /** - * Add one column index param - * @param indexParam index column parameters - * @return Builder - */ - public Builder addIndexColumnParam(IndexColumnParam indexParam) { - this.indexColumnParams.add(indexParam); - return this; - } - - /** - * Add one index column param - * @param columnName index column name - * @param dataType index data type - * @param dimension index dimension - * @return Builder - */ - public Builder addIndexColumnParam(String columnName, DataType dataType, int dimension) { - this.indexColumnParams.add(IndexColumnParam.newBuilder() - .withColumnName(columnName) - .withDataType(dataType) - .withDimension(dimension) - .build()); - return this; - } - - /** - * Build collection config - * @return CollectionConfig - */ - public CollectionConfig build() { - return new CollectionConfig(this); - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/CollectionInfo.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/CollectionInfo.java deleted file mode 100644 index 4d191b9..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/CollectionInfo.java +++ /dev/null @@ -1,189 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief CollectionInfo contains information for collection - */ - -package com.alibaba.proxima.be.client; - -/** - * Contains information for collection - */ -public class CollectionInfo { - private final CollectionConfig collectionConfig; - private final CollectionStatus collectionStatus; - private final String uuid; - private final LsnContext latestLsnContext; - private final long magicNumber; - - private CollectionInfo(Builder builder) { - this.collectionConfig = builder.collectionConfig; - this.collectionStatus = builder.collectionStatus; - this.uuid = builder.uuid; - this.latestLsnContext = builder.latestLsnContext; - this.magicNumber = builder.magicNumber; - } - - public CollectionConfig getCollectionConfig() { - return collectionConfig; - } - - public CollectionStatus getCollectionStatus() { - return collectionStatus; - } - - public String getUuid() { - return uuid; - } - - public LsnContext getLatestLsnContext() { - return latestLsnContext; - } - - public long getMagicNumber() { - return magicNumber; - } - - // New CollectionInfo builder - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for CollectionInfo - */ - public static class Builder { - // required parameters - private CollectionConfig collectionConfig; - private CollectionStatus collectionStatus; - private String uuid; - - // optional parameters - private LsnContext latestLsnContext = null; - private long magicNumber = 0; - - /** - * Constructor without parameters - */ - public Builder() { - } - - /** - * Set collection config - * @param collectionConfig collection config - * @return Builder - */ - public Builder withCollectionConfig(CollectionConfig collectionConfig) { - this.collectionConfig = collectionConfig; - return this; - } - - /** - * Sset collection status - * @param collectionStatus collection status - * @return Builder - */ - public Builder withCollectionStatus(CollectionStatus collectionStatus) { - this.collectionStatus = collectionStatus; - return this; - } - - /** - * Set uuid - * @param uuid unique user id - * @return Builder - */ - public Builder withUuid(String uuid) { - this.uuid = uuid; - return this; - } - - /** - * Set latest lsn context - * @param latestLsnContext latest lsn context, only use with mysql repository - * @return Builder - */ - public Builder withLatestLsnContext(LsnContext latestLsnContext) { - this.latestLsnContext = latestLsnContext; - return this; - } - - /** - * Set magic number - * @param magicNumber magic number from server - * @return Builder - */ - public Builder withMagicNumber(long magicNumber) { - this.magicNumber = magicNumber; - return this; - } - - /** - * Build CollectionInfo object - * @return CollectionInfo - */ - public CollectionInfo build() { - return new CollectionInfo(this); - } - } - - /** - * Collection running status - */ - public enum CollectionStatus { - /** - * Collection initialized - */ - INITIALIZED(0), - /** - * Collection serving - */ - SERVING(1), - /** - * Collection dropped - */ - DROPPED(2), - /** - * Unknown status - */ - UNKNOWN(-1); - - private int value; - - CollectionStatus(int value) { - this.value = value; - } - - public int getValue() { - return this.value; - } - - public static CollectionStatus valueOf(int value) { - switch (value) { - case 0: - return INITIALIZED; - case 1: - return SERVING; - case 2: - return DROPPED; - default: - return UNKNOWN; - } - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/CollectionStats.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/CollectionStats.java deleted file mode 100644 index 9910b90..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/CollectionStats.java +++ /dev/null @@ -1,469 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief CollectionStats contains running statistic information for collection - */ - -package com.alibaba.proxima.be.client; - -import java.util.ArrayList; -import java.util.List; - -/** - * Contains statistic information for collection - */ -public class CollectionStats { - private final String collectionName; - private final String collectionPath; - private final long totalDocCount; - private final long totalSegmentCount; - private final long totalIndexFileCount; - private final long totalIndexFileSize; - private final List segmentStats; - - public CollectionStats(Builder builder) { - this.collectionName = builder.collectionName; - this.collectionPath = builder.collectionPath; - this.totalDocCount = builder.totalDocCount; - this.totalSegmentCount = builder.totalSegmentCount; - this.totalIndexFileCount = builder.totalIndexFileCount; - this.totalIndexFileSize = builder.totalIndexFileSize; - this.segmentStats = builder.segmentStats; - } - - public String getCollectionName() { - return collectionName; - } - - public String getCollectionPath() { - return collectionPath; - } - - public long getTotalDocCount() { - return totalDocCount; - } - - public long getTotalSegmentCount() { - return totalSegmentCount; - } - - public long getTotalIndexFileCount() { - return totalIndexFileCount; - } - - public long getTotalIndexFileSize() { - return totalIndexFileSize; - } - - public List getSegmentStats() { - return segmentStats; - } - - /** - * Get total segments count - * @return total segment stats count - */ - public int getSegmentStatsCount() { - if (this.segmentStats != null) { - return this.segmentStats.size(); - } - return 0; - } - - /** - * Get one segments stats - * @param index segment index - * @return SegmentStats - */ - public SegmentStats getSegmentStats(int index) { - return this.segmentStats.get(index); - } - - /** - * New Collection stats builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for CollectionStats - */ - public static class Builder { - // required parameters - private String collectionName; - private String collectionPath; - private long totalDocCount; - private long totalSegmentCount; - private long totalIndexFileCount; - private long totalIndexFileSize; - private List segmentStats = new ArrayList<>(); - - /** - * Constructor without parameters - */ - public Builder() { - } - - /** - * Set collection name - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set collection path - * @param collectionPath collection index path - * @return Builder - */ - public Builder withCollectionPath(String collectionPath) { - this.collectionPath = collectionPath; - return this; - } - - /** - * Set total document count - * @param totalDocCount total document count - * @return Builder - */ - public Builder withTotalDocCount(long totalDocCount) { - this.totalDocCount = totalDocCount; - return this; - } - - /** - * Set total segment count - * @param totalSegmentCount total segment count - * @return Builder - */ - public Builder withTotalSegmentCount(long totalSegmentCount) { - this.totalSegmentCount = totalSegmentCount; - return this; - } - - /** - * Set total index file count - * @param totalIndexFileCount total index file count - * @return Builder - */ - public Builder withTotalIndexFileCount(long totalIndexFileCount) { - this.totalIndexFileCount = totalIndexFileCount; - return this; - } - - /** - * Set total index file size - * @param totalIndexFileSize total index file size - * @return Builder - */ - public Builder withTotalIndexFileSize(long totalIndexFileSize) { - this.totalIndexFileSize = totalIndexFileSize; - return this; - } - - /** - * Set segment stats list - * @param segmentStatsList segment stats list - * @return Builder - */ - public Builder withSegmentStats(List segmentStatsList) { - this.segmentStats = segmentStatsList; - return this; - } - - /** - * Add segment stats - * @param segmentStats segment stats - * @return Builder - */ - public Builder addSegmentStats(SegmentStats segmentStats) { - this.segmentStats.add(segmentStats); - return this; - } - - /** - * Build collection stats object - * @return CollectionStats - */ - public CollectionStats build() { - return new CollectionStats(this); - } - } - - /** - * Segment running state - */ - public enum SegmentState { - /** - * Segment created - */ - CREATED(0), - /** - * Segment writing - */ - WRITING(1), - /** - * Segment dumping - */ - DUMPING(2), - /** - * Segment compacting - */ - COMPACTING(3), - /** - * Segment persist - */ - PERSIST(4), - /** - * Unknown state - */ - UNKNOWN(-1); - - private final int value; - - SegmentState(int value) { - this.value = value; - } - - public int getValue() { - return this.value; - } - - public static SegmentState valueOf(int value) { - switch (value) { - case 0: - return CREATED; - case 1: - return WRITING; - case 2: - return DUMPING; - case 3: - return COMPACTING; - case 4: - return PERSIST; - default: - return UNKNOWN; - } - } - } - - /** - * Statistic for one segment - */ - public static class SegmentStats { - private final int segmentId; - private final SegmentState segmentState; - private final long docDount; - private final long indexFileCount; - private final long indexFileSize; - private final long minDocId; - private final long maxDocId; - private final long minPrimaryKey; - private final long maxPrimaryKey; - private final long minTimestamp; - private final long maxTimestamp; - private final long minLsn; - private final long maxLsn; - private final String segmentPath; - - private SegmentStats(Builder builder) { - this.segmentId = builder.segmentId; - this.segmentState = builder.segmentState; - this.docDount = builder.docDount; - this.indexFileCount = builder.indexFileCount; - this.indexFileSize = builder.indexFileSize; - this.minDocId = builder.minDocId; - this.maxDocId = builder.maxDocId; - this.minPrimaryKey = builder.minPrimaryKey; - this.maxPrimaryKey = builder.maxPrimaryKey; - this.minTimestamp = builder.minTimestamp; - this.maxTimestamp = builder.maxTimestamp; - this.minLsn = builder.minLsn; - this.maxLsn = builder.maxLsn; - this.segmentPath = builder.segmentPath; - } - - public int getSegmentId() { - return segmentId; - } - - public SegmentState getSegmentState() { - return segmentState; - } - - public long getDocDount() { - return docDount; - } - - public long getIndexFileCount() { - return indexFileCount; - } - - public long getIndexFileSize() { - return indexFileSize; - } - - public long getMinDocId() { - return minDocId; - } - - public long getMaxDocId() { - return maxDocId; - } - - public long getMinPrimaryKey() { - return minPrimaryKey; - } - - public long getMaxPrimaryKey() { - return maxPrimaryKey; - } - - public long getMinTimestamp() { - return minTimestamp; - } - - public long getMaxTimestamp() { - return maxTimestamp; - } - - public long getMinLsn() { - return minLsn; - } - - public long getMaxLsn() { - return maxLsn; - } - - public String getSegmentPath() { - return segmentPath; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Segment stats builder - */ - public static class Builder { - private int segmentId; - private SegmentState segmentState; - private long docDount; - private long indexFileCount; - private long indexFileSize; - private long minDocId; - private long maxDocId; - private long minPrimaryKey; - private long maxPrimaryKey; - private long minTimestamp; - private long maxTimestamp; - private long minLsn; - private long maxLsn; - private String segmentPath; - - public Builder() { - } - - public Builder withSegmentId(int segmentId) { - this.segmentId = segmentId; - return this; - } - - public Builder withSegmentState(SegmentState segmentState) { - this.segmentState = segmentState; - return this; - } - - public Builder withDocDount(long docDount) { - this.docDount = docDount; - return this; - } - - public Builder withIndexFileCount(long indexFileCount) { - this.indexFileCount = indexFileCount; - return this; - } - - public Builder withIndexFileSize(long indexFileSize) { - this.indexFileSize = indexFileSize; - return this; - } - - public Builder withMinDocId(long minDocId) { - this.minDocId = minDocId; - return this; - } - - public Builder withMaxDocId(long maxDocId) { - this.maxDocId = maxDocId; - return this; - } - - public Builder withMinPrimaryKey(long minPrimaryKey) { - this.minPrimaryKey = minPrimaryKey; - return this; - } - - public Builder withMaxPrimaryKey(long maxPrimaryKey) { - this.maxPrimaryKey = maxPrimaryKey; - return this; - } - - public Builder withMinTimestamp(long minTimestamp) { - this.minTimestamp = minTimestamp; - return this; - } - - public Builder withMaxTimestamp(long maxTimestamp) { - this.maxTimestamp = maxTimestamp; - return this; - } - - public Builder withMinLsn(long minLsn) { - this.minLsn = minLsn; - return this; - } - - public Builder withMaxLsn(long maxLsn) { - this.maxLsn = maxLsn; - return this; - } - - public Builder withSegmentPath(String segmentPath) { - this.segmentPath = segmentPath; - return this; - } - - /** - * Build segment stats object - * @return SegmentStats - */ - public SegmentStats build() { - return new SegmentStats(this); - } - } - } - - -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ConnectParam.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ConnectParam.java deleted file mode 100644 index 86a1bc2..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ConnectParam.java +++ /dev/null @@ -1,197 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief ConnectParam contains the grpc connecting parameters - */ - -package com.alibaba.proxima.be.client; - -import java.util.concurrent.TimeUnit; - -/** - * ConnectParam contains the grpc connecting param - */ -public class ConnectParam { - // required parameters - private final String host; - private final int port; - // optional parameters - private final long timeoutNanos; - private final long idleTimeoutNanos; - private final long keepAliveTimeNanos; - private final long keepAliveTimeoutNanos; - - // - - /** - * Constructor with builder - * @param builder builder - */ - private ConnectParam(Builder builder) { - this.port = builder.port; - this.host = builder.host; - this.timeoutNanos = builder.timeoutNanos; - this.idleTimeoutNanos = builder.idleTimeoutNanos; - this.keepAliveTimeNanos = builder.keepAliveTimeNanos; - this.keepAliveTimeoutNanos = builder.keepAliveTimeoutNanos; - } - - /** - * Get host - * @return String - */ - public String getHost() { - return this.host; - } - - /** - * Get port - * @return int - */ - public int getPort() { - return this.port; - } - - /** - * Get timeout with unit - * @param timeUnit time unit - * @return request timeout - */ - public long getTimeout(TimeUnit timeUnit) { - return timeUnit.convert(this.timeoutNanos, TimeUnit.NANOSECONDS); - } - - /** - * Get idle timeout with unit - * @param timeUnit time unit - * @return idle timeout by time unit - */ - public long getIdleTimeout(TimeUnit timeUnit) { - return timeUnit.convert(this.idleTimeoutNanos, TimeUnit.NANOSECONDS); - } - - /** - * Get keep alive time with unit - * @param timeUnit time unit - * @return keep alive time by time unit - */ - public long getKeepAliveTime(TimeUnit timeUnit) { - return timeUnit.convert(this.keepAliveTimeNanos, TimeUnit.NANOSECONDS); - } - - /** - * Get keep alive timeout with unit - * @param timeUnit time unit - * @return keep alive timeout by time unit - */ - public long getKeepAliveTimeout(TimeUnit timeUnit) { - return timeUnit.convert(this.keepAliveTimeoutNanos, TimeUnit.NANOSECONDS); - } - - /** - * New ConnectParam builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for ConnectParam - */ - public static class Builder { - private String host = "localhost"; - private int port = 16000; - private long timeoutNanos = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS); - private long idleTimeoutNanos = TimeUnit.NANOSECONDS.convert(12, TimeUnit.HOURS); - private long keepAliveTimeNanos = Long.MAX_VALUE; - private long keepAliveTimeoutNanos = TimeUnit.NANOSECONDS.convert(30, TimeUnit.SECONDS); - - /** - * Build ConnectParam object - * @return ConnectParam - */ - public ConnectParam build() { - return new ConnectParam(this); - } - - /** - * Set host - * @param host grpc server host - * @return Builder - */ - public Builder withHost(String host) { - this.host = host; - return this; - } - - /** - * Set grpc port - * @param port grpc server port - * @return Builder - */ - public Builder withPort(int port) { - this.port = port; - return this; - } - - /** - * Set request timeout - * @param timeout request timeout value - * @param timeUnit time unit - * @return Builder - */ - public Builder withTimeout(long timeout, TimeUnit timeUnit) { - this.timeoutNanos = timeUnit.toNanos(timeout); - return this; - } - - /** - * Set idle timeout - * @param idleTimeout idle timeout by time unit - * @param timeUnit time unit - * @return Builder - */ - public Builder withIdleTimeout(long idleTimeout, TimeUnit timeUnit) { - this.idleTimeoutNanos = timeUnit.toNanos(idleTimeout); - return this; - } - - /** - * Set keep alive time - * @param keepAliveTime keep alive time by time unit - * @param timeUnit time unit - * @return Builder - */ - public Builder withKeepAliveTimeNanos(long keepAliveTime, TimeUnit timeUnit) { - this.keepAliveTimeNanos = timeUnit.toNanos(keepAliveTime); - return this; - } - - /** - * Set keep alive timeout - * @param keepAliveTimeout keep alive timeout by time unit - * @param timeUnit time unit - * @return Builder - */ - public Builder withKeepAliveTimeoutNanos(long keepAliveTimeout, TimeUnit timeUnit) { - this.keepAliveTimeoutNanos = timeUnit.toNanos(keepAliveTimeout); - return this; - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/DataType.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/DataType.java deleted file mode 100644 index 00f22a2..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/DataType.java +++ /dev/null @@ -1,154 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief DataType contains all data types for proxima search engine - */ - -package com.alibaba.proxima.be.client; - -/** - * DataType contains all supported data types - */ -public enum DataType { - /** - * Undefined data type - */ - UNDEFINED(0), - /** - * Binary data type - */ - BINARY(1), - /** - * String data type - */ - STRING(2), - /** - * Bool data type - */ - BOOL(3), - /** - * Int32 data type - */ - INT32(4), - /** - * Int64 data type - */ - INT64(5), - /** - * Uint32 data type - */ - UINT32(6), - /** - * Uint64 data type - */ - UINT64(7), - /** - * Float data type - */ - FLOAT(8), - /** - * Double data type - */ - DOUBLE(9), - - /** - * Vector binary32 data type - */ - VECTOR_BINARY32(20), - /** - * Vector binary64 data type - */ - VECTOR_BINARY64(21), - /** - * Vector fp16 data type - */ - VECTOR_FP16(22), - /** - * Vector fp32 data type - */ - VECTOR_FP32(23), - /** - * Vector double data type - */ - VECTOR_FP64(24), - /** - * Vector int4 data type - */ - VECTOR_INT4(25), - /** - * Vector int8 data type - */ - VECTOR_INT8(26), - /** - * Vector int16 data type - */ - VECTOR_INT16(27); - - private int value; - - DataType(int value) { - this.value = value; - } - - public int getValue() { - return this.value; - } - - public static DataType valueOf(int value) { - switch (value) { - case 0: - return UNDEFINED; - case 1: - return BINARY; - case 2: - return STRING; - case 3: - return BOOL; - case 4: - return INT32; - case 5: - return INT64; - case 6: - return UINT32; - case 7: - return UINT64; - case 8: - return FLOAT; - case 9: - return DOUBLE; - case 20: - return VECTOR_BINARY32; - case 21: - return VECTOR_BINARY64; - case 22: - return VECTOR_FP16; - case 23: - return VECTOR_FP32; - case 24: - return VECTOR_FP64; - case 25: - return VECTOR_INT4; - case 26: - return VECTOR_INT8; - case 27: - return VECTOR_INT16; - default: - return UNDEFINED; - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/DatabaseRepository.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/DatabaseRepository.java deleted file mode 100644 index 8f1f148..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/DatabaseRepository.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief DatabaseRepository contains the database config - */ - -package com.alibaba.proxima.be.client; - -/** - * Contains the database config - */ -public class DatabaseRepository { - private final String repositoryName; - private final String connectionUri; - private final String tableName; - private final String user; - private final String password; - - private DatabaseRepository(Builder builder) { - this.repositoryName = builder.repositoryName; - this.connectionUri = builder.connectionUri; - this.tableName = builder.tableName; - this.user = builder.user; - this.password = builder.password; - } - - public String getRepositoryName() { - return repositoryName; - } - - public String getConnectionUri() { - return connectionUri; - } - - public String getTableName() { - return tableName; - } - - public String getUser() { - return user; - } - - public String getPassword() { - return password; - } - - /** - * New DatabaseRepository builde - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for DatabaseRepository - */ - public static class Builder { - // required parameters - private String repositoryName; - private String connectionUri; - private String tableName; - private String user; - private String password; - - /** - * Empty constructor - */ - public Builder() { - } - - /** - * Set repository name - * @param repositoryName repository name - * @return Builder - */ - public Builder withRepositoryName(String repositoryName) { - this.repositoryName = repositoryName; - return this; - } - - /** - * Set connection uri - * @param connectionUri connection uri - * @return Builder - */ - public Builder withConnectionUri(String connectionUri) { - this.connectionUri = connectionUri; - return this; - } - - /** - * Set table name - * @param tableName mysql table name - * @return Builder - */ - public Builder withTableName(String tableName) { - this.tableName = tableName; - return this; - } - - /** - * Set database username - * @param user user name - * @return Builder - */ - public Builder withUser(String user) { - this.user = user; - return this; - } - - /** - * Set database password - * @param password myssql password - * @return Builder - */ - public Builder withPassword(String password) { - this.password = password; - return this; - } - - /** - * Build the DatabaseRepository object - * @return DatabaseRepository - */ - public DatabaseRepository build() { - return new DatabaseRepository(this); - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/DescribeCollectionResponse.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/DescribeCollectionResponse.java deleted file mode 100644 index 073af74..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/DescribeCollectionResponse.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Contains the specified collection info - */ - -package com.alibaba.proxima.be.client; - -/** - * Contains the specified collection information - */ -public class DescribeCollectionResponse { - private Status status; - private CollectionInfo collectionInfo; - - /** - * Constructor with status and collection info - * @param status request success or failed - * @param collectionInfo collection info - */ - public DescribeCollectionResponse(Status status, CollectionInfo collectionInfo) { - this.status = status; - this.collectionInfo = collectionInfo; - } - - /** - * Constructor with ErrorCode - * @param code error code - */ - public DescribeCollectionResponse(Status.ErrorCode code) { - this.status = new Status(code); - this.collectionInfo = null; - } - - /** - * Constructor with error code and reason - * @param code error code - * @param reason error reason - */ - public DescribeCollectionResponse(Status.ErrorCode code, String reason) { - this.status = new Status(code, reason); - this.collectionInfo = null; - } - - public Status getStatus() { - return status; - } - - public CollectionInfo getCollectionInfo() { - return collectionInfo; - } - - /** - * Is response success - * @return true means success. - */ - public boolean ok() { - return this.status.ok(); - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/Document.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/Document.java deleted file mode 100644 index 81d7a0b..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/Document.java +++ /dev/null @@ -1,225 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Document contains the pk, score, and forward values - */ - -package com.alibaba.proxima.be.client; - -import com.alibaba.proxima.be.grpc.GenericValue; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -/** - * Document information - */ -public class Document { - private final long primaryKey; - private final float score; - private final Map forwardColumnMap; - - private Document(Builder builder) { - this.primaryKey = builder.primaryKey; - this.score = builder.score; - this.forwardColumnMap = builder.forwardColumnMap; - } - - public long getPrimaryKey() { - return primaryKey; - } - - public float getScore() { - return score; - } - - public Map getForwardColumnMap() { - return forwardColumnMap; - } - - /** - * Get forward column count - * @return Forward column count - */ - public int getForwardColumnCount() { - if (forwardColumnMap != null) { - return forwardColumnMap.size(); - } - return 0; - } - - /** - * Get forward key set - * @return forward key set - */ - public Set getForwardKeySet() { - return this.forwardColumnMap.keySet(); - } - - /** - * Get specified forward value - * @param key the forward key - * @return ForwardValue - */ - public ForwardValue getForwardValue(String key) { - return this.forwardColumnMap.get(key); - } - - /** - * New document builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Represents all types forward value - */ - public static class ForwardValue { - private GenericValue value; - - private ForwardValue(Builder builder) { - this.value = builder.value; - } - - // Get float value - public float getFloatValue() { - return this.value.getFloatValue(); - } - - // Get double value - public double getDoubleValue() { - return this.value.getDoubleValue(); - } - - // Get int64 value - public long getInt64Value() { - return this.value.getInt64Value(); - } - - // Get int32 value - public int getInt32Value() { - return this.value.getInt32Value(); - } - - // Get uint64 value - public long getUint64Value() { - return this.value.getUint64Value(); - } - - // Get uint32 value - public int getUint32Value() { - return this.value.getUint32Value(); - } - - // Get boolean value - public boolean getBooleanValue() { - return this.value.getBoolValue(); - } - - /** - * Get string value, if forward's type not string, will also convert to string - * @return String - */ - public String getStringValue() { - switch (value.getValueOneofCase()) { - case VALUEONEOF_NOT_SET: - return ""; - case BYTES_VALUE: - return value.getBytesValue().toString(); - case STRING_VALUE: - return value.getStringValue(); - case BOOL_VALUE: - return String.valueOf(value.getBoolValue()); - case INT32_VALUE: - return String.valueOf(value.getInt32Value()); - case INT64_VALUE: - return String.valueOf(value.getInt64Value()); - case UINT32_VALUE: - return String.valueOf(value.getUint32Value()); - case UINT64_VALUE: - return String.valueOf(value.getUint64Value()); - case FLOAT_VALUE: - return String.valueOf(value.getFloatValue()); - case DOUBLE_VALUE: - return String.valueOf(value.getDoubleValue()); - default: - return ""; - } - } - - // Get bytes value - public byte[] getBytesValue() { - return this.value.getBytesValue().toByteArray(); - } - - /** Builder for ForwardValue */ - public static class Builder { - private GenericValue value; - - public Builder(GenericValue genericValue) { - this.value = genericValue; - } - - public ForwardValue build() { - return new ForwardValue(this); - } - } - } - - /** - * Builder for Document - */ - public static class Builder { - // required parameters - private long primaryKey; - private float score; - - // optional parameters - private Map forwardColumnMap = new HashMap<>(); - - // Empty constructor - public Builder() { - } - - // Constructor - public Builder withPrimaryKey(long primaryKey) { - this.primaryKey = primaryKey; - return this; - } - - // Set score - public Builder withScore(float score) { - this.score = score; - return this; - } - - // Set forward column map - public Builder withForwardColumnMap(Map forwardColumnMap) { - this.forwardColumnMap = forwardColumnMap; - return this; - } - - // Build Document object - public Document build() { - return new Document(this); - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/GetDocumentRequest.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/GetDocumentRequest.java deleted file mode 100644 index 7797852..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/GetDocumentRequest.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Get single document by primary key - */ - -package com.alibaba.proxima.be.client; - -/** - * Get document request - */ -public class GetDocumentRequest { - private final String collectionName; - private final long primaryKey; - private boolean debugMode; - - private GetDocumentRequest(Builder builder) { - this.collectionName = builder.collectionName; - this.primaryKey = builder.primaryKey; - this.debugMode = builder.debugMode; - } - - public String getCollectionName() { - return collectionName; - } - - public long getPrimaryKey() { - return primaryKey; - } - - public boolean isDebugMode() { - return debugMode; - } - - /** - * New GetDocumentRequest builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for GetDocumentRequest - */ - public static class Builder { - // required parameters - private String collectionName; - private long primaryKey; - - // optional parameters - private boolean debugMode = false; - - /** - * Empty constructor - */ - public Builder() { - } - - /** - * Constructor with collection name and primary key - * @param collectionName collection name - * @param primaryKey primary key - */ - public Builder(String collectionName, long primaryKey) { - this.collectionName = collectionName; - this.primaryKey = primaryKey; - } - - /** - * Set collection name - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set primary key - * @param primaryKey primary key to query - * @return Builder - */ - public Builder withPrimaryKey(long primaryKey) { - this.primaryKey = primaryKey; - return this; - } - - /** - * Set debug mode - * @param debugMode is debug mode, true means debug - * @return Builder - */ - public Builder withDebugMode(boolean debugMode) { - this.debugMode = debugMode; - return this; - } - - /** - * Build get document request object - * @return GetDocumentRequest - */ - public GetDocumentRequest build() { - return new GetDocumentRequest(this); - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/GetDocumentResponse.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/GetDocumentResponse.java deleted file mode 100644 index afa245d..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/GetDocumentResponse.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Contains document information - */ - -package com.alibaba.proxima.be.client; - -/** - * GetDocumentResponse contains document information - */ -public class GetDocumentResponse { - private Status status; - private String debugInfo; - private Document document; - - public GetDocumentResponse(Status.ErrorCode code) { - this.status = new Status(code); - this.debugInfo = null; - this.document = null; - } - - public GetDocumentResponse(Status.ErrorCode code, String reason) { - this.status = new Status(code, reason); - this.debugInfo = ""; - this.document = null; - } - - public GetDocumentResponse(Status status, String debugInfo, Document document) { - this.status = status; - this.debugInfo = debugInfo; - this.document = document; - } - - public Status getStatus() { - return status; - } - - public String getDebugInfo() { - return debugInfo; - } - - public Document getDocument() { - return document; - } - - /** - * Is response success, true means success, false means failed - * @return boolean - */ - public boolean ok() { - return this.status.getCode() == 0; - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/GetVersionResponse.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/GetVersionResponse.java deleted file mode 100644 index ea81559..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/GetVersionResponse.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Proxima Search Engine version - */ - -package com.alibaba.proxima.be.client; - -/** - * Contains the server version - */ -public class GetVersionResponse { - Status status; - String version; - - public GetVersionResponse(Status.ErrorCode errorCode) { - this.status = new Status(errorCode); - this.version = ""; - } - - public GetVersionResponse(Status.ErrorCode errorCode, String errorMsg) { - this.status = new Status(errorCode, errorMsg); - this.version = ""; - } - - public GetVersionResponse(Status status, String version) { - this.status = status; - this.version = version; - } - - public Status getStatus() { - return status; - } - - public String getVersion() { - return version; - } - - /** - * Is the response success - * @return boolean - */ - public boolean ok() { - return this.status.ok(); - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/IndexColumnParam.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/IndexColumnParam.java deleted file mode 100644 index 364cbe1..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/IndexColumnParam.java +++ /dev/null @@ -1,178 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief IndexColumnParam contains parameters for index column - */ - -package com.alibaba.proxima.be.client; - -import java.util.HashMap; -import java.util.Map; - -/** - * Contains parameters for index column - */ -public class IndexColumnParam { - private final String columnName; - private final IndexType indexType; - private final DataType dataType; - private final int dimension; - private final Map extraParams; - - private IndexColumnParam(Builder builder) { - this.columnName = builder.columnName; - this.indexType = builder.indexType; - this.dataType = builder.dataType; - this.dimension = builder.dimension; - this.extraParams = builder.extraParams; - } - - public String getColumnName() { - return columnName; - } - - public IndexType getIndexType() { - return indexType; - } - - public DataType getDataType() { - return dataType; - } - - public int getDimension() { - return dimension; - } - - public Map getExtraParams() { - return extraParams; - } - - /** - * New IndexColumnParam builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for IndexColumnParam - */ - public static class Builder { - // required parameters - private String columnName; - private DataType dataType = DataType.UNDEFINED; - private int dimension = 0; - - // optional parameters - private IndexType indexType = IndexType.PROXIMA_GRAPH_INDEX; - private Map extraParams = new HashMap<>(); - - /** - * Empty constructor - */ - public Builder() { - } - - /** - * Constructor with parameters - * @param columnName index column name - * @param dataType index data type - * @param dimension index dimension - */ - public Builder(String columnName, DataType dataType, int dimension) { - this.columnName = columnName; - this.dataType = dataType; - this.dimension = dimension; - } - - /** - * Set index column name - * @param columnName index column name - * @return Builder - */ - public Builder withColumnName(String columnName) { - this.columnName = columnName; - return this; - } - - /** - * Set index data type - * @param dataType index data type - * @return Builder - */ - public Builder withDataType(DataType dataType) { - this.dataType = dataType; - return this; - } - - // Set dimension - - /** - * Set index dimension - * @param dimension index dimension - * @return Builder - */ - public Builder withDimension(int dimension) { - this.dimension = dimension; - return this; - } - - /** - * Set index type - * @param indexType index type - * @return Builder - */ - public Builder withIndexType(IndexType indexType) { - this.indexType = indexType; - return this; - } - - // Set extra params - - /** - * Set extra parameters - * @param extraParams extra parameters - * @return Builder - */ - public Builder withExtraParams(Map extraParams) { - this.extraParams = extraParams; - return this; - } - - /** - * Add one extra param - * @param key extra parameter key - * @param value extra parameter value - * @return Builder - */ - public Builder addExtraParam(String key, String value) { - this.extraParams.put(key, value); - return this; - } - - /** - * Build IndexColumnParam object - * @return IndexColumnParam - */ - public IndexColumnParam build() { - return new IndexColumnParam(this); - } - } -} - diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/IndexType.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/IndexType.java deleted file mode 100644 index 59c54b1..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/IndexType.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief IndexType contains all supported index types - */ - -package com.alibaba.proxima.be.client; - -/** - * Contains all index types - */ -public enum IndexType { - /** - * Undefined index type - */ - UNDEFINED(0), - /** - * Poxima graph index type - */ - PROXIMA_GRAPH_INDEX(1); - - private int value; - - IndexType(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - public static IndexType valueOf(int value) { - switch (value) { - case 0: - return UNDEFINED; - case 1: - return PROXIMA_GRAPH_INDEX; - default: - return UNDEFINED; - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ListCollectionsResponse.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ListCollectionsResponse.java deleted file mode 100644 index 3eecea8..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ListCollectionsResponse.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief ListCollectionsResponse contains collections info and status - */ - -package com.alibaba.proxima.be.client; - -import java.util.List; - -/** - * Contains collections information - */ -public class ListCollectionsResponse { - private Status status; - private List collections; - - // Constructor - - /** - * Constructor with status and collections - * @param status status - * @param collections collection list - */ - public ListCollectionsResponse(Status status, List collections) { - this.status = status; - this.collections = collections; - } - - /** - * Constructor with error code - * @param code error code - */ - public ListCollectionsResponse(Status.ErrorCode code) { - this.status = new Status(code); - this.collections = null; - } - - /** - * Constructor with code and reason - * @param code error code - * @param reason error message - */ - public ListCollectionsResponse(Status.ErrorCode code, String reason) { - this.status = new Status(code, reason); - this.collections = null; - } - - /** - * Get collection count - * @return int - */ - public int getCollectionCount() { - if (this.collections != null) { - return this.collections.size(); - } - return 0; - } - - /** - * Get specified collection info - * @param index the collection index - * @return CollectionInfo - */ - public CollectionInfo getCollection(int index) { - return this.collections.get(index); - } - - /** - * Get status - * @return Status - */ - public Status getStatus() { - return this.status; - } - - /** - * Is request success, true means success - * @return boolean - */ - public boolean ok() { - return this.status.ok(); - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ListCondition.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ListCondition.java deleted file mode 100644 index f819bf4..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ListCondition.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Represents the list condition. - */ - -package com.alibaba.proxima.be.client; - -/** - * List collections condition - */ -public class ListCondition { - private final String repositoryName; - - private ListCondition(Builder builder) { - this.repositoryName = builder.repositoryName; - } - - public String getRepositoryName() { - return repositoryName; - } - - /** - * New ListCondition builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for ListCondition - */ - public static class Builder { - private String repositoryName; - - /** - * Empty constructor - */ - public Builder() { - } - - /** - * Set repository name - * @param repositoryName repository name - * @return Builder - */ - public Builder withRepositoryName(String repositoryName) { - this.repositoryName = repositoryName; - return this; - } - - /** - * Build list condition object - * @return ListCondition - */ - public ListCondition build() { - return new ListCondition(this); - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/LsnContext.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/LsnContext.java deleted file mode 100644 index 0d7d42e..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/LsnContext.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Contains lsn and context infor - */ - -package com.alibaba.proxima.be.client; - -/** - * Lsn context information - */ -public class LsnContext { - private long lsn; - private String context; - - private LsnContext(Builder builder) { - this.lsn = builder.lsn; - this.context = builder.context; - } - - public long getLsn() { - return lsn; - } - - public String getContext() { - return context; - } - - // New LsnContext builder - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for LsnContext - */ - public static class Builder { - // required parameters - private long lsn; - private String context; - - public Builder() { - } - - public Builder(long lsn, String context) { - this.lsn = lsn; - this.context = context; - } - - /** - * Set lsn number - * @param lsn log sequence number - * @return Builder - */ - public Builder withLsn(long lsn) { - this.lsn = lsn; - return this; - } - - /** - * Set context information - * @param context lsn context - * @return Builder - */ - public Builder withContext(String context) { - this.context = context; - return this; - } - - /** - * Build LsnContext object - * @return LsnContext - */ - public LsnContext build() { - return new LsnContext(this); - } - } - -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProtoConverter.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProtoConverter.java deleted file mode 100644 index b462499..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProtoConverter.java +++ /dev/null @@ -1,395 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Convert between proto and inner struct - */ - -package com.alibaba.proxima.be.client; - - -import com.google.protobuf.ByteString; -import com.alibaba.proxima.be.grpc.KeyValuePair; -import com.alibaba.proxima.be.grpc.CollectionName; -import com.alibaba.proxima.be.grpc.OperationType; -import com.alibaba.proxima.be.grpc.GenericKeyValue; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Convert between proto object and inner object - */ -public class ProtoConverter { - public static com.alibaba.proxima.be.grpc.DataType toPb(DataType dataType) { - return com.alibaba.proxima.be.grpc.DataType.forNumber(dataType.getValue()); - } - - public static com.alibaba.proxima.be.grpc.IndexType toPb(IndexType indexType) { - return com.alibaba.proxima.be.grpc.IndexType.forNumber(indexType.getValue()); - } - - public static com.alibaba.proxima.be.grpc.CollectionConfig toPb(CollectionConfig config) { - List indexParams = config.getIndexColumnParams(); - List indexParamList = new ArrayList<>(); - for (IndexColumnParam indexParam : indexParams) { - Map extraParams = indexParam.getExtraParams(); - List extraParamList = new ArrayList<>(); - for (Map.Entry entry : extraParams.entrySet()) { - extraParamList.add( - KeyValuePair.newBuilder().setKey(entry.getKey()).setValue(entry.getValue()).build()); - } - indexParamList.add( - com.alibaba.proxima.be.grpc.CollectionConfig.IndexColumnParam.newBuilder() - .setColumnName(indexParam.getColumnName()) - .setDataType(toPb(indexParam.getDataType())) - .setIndexType(toPb(indexParam.getIndexType())) - .setDimension(indexParam.getDimension()) - .addAllExtraParams(extraParamList) - .build() - ); - } - com.alibaba.proxima.be.grpc.CollectionConfig.Builder builder = - com.alibaba.proxima.be.grpc.CollectionConfig.newBuilder() - .setCollectionName(config.getCollectionName()) - .setMaxDocsPerSegment(config.getMaxDocsPerSegment()) - .addAllForwardColumnNames(config.getForwardColumnNames()) - .addAllIndexColumnParams(indexParamList); - - DatabaseRepository databaseRepository = config.getDatabaseRepository(); - if (databaseRepository != null) { - com.alibaba.proxima.be.grpc.CollectionConfig.RepositoryConfig.Database database = - com.alibaba.proxima.be.grpc.CollectionConfig.RepositoryConfig.Database.newBuilder() - .setConnectionUri(databaseRepository.getConnectionUri()) - .setTableName(databaseRepository.getTableName()) - .setUser(databaseRepository.getUser()) - .setPassword(databaseRepository.getPassword()) - .build(); - com.alibaba.proxima.be.grpc.CollectionConfig.RepositoryConfig repositoryConfig = - com.alibaba.proxima.be.grpc.CollectionConfig.RepositoryConfig.newBuilder() - .setRepositoryType(com.alibaba.proxima.be.grpc.CollectionConfig - .RepositoryConfig.RepositoryType.RT_DATABASE) - .setRepositoryName(databaseRepository.getRepositoryName()) - .setDatabase(database) - .build(); - builder.setRepositoryConfig(repositoryConfig); - } - - return builder.build(); - } - - public static CollectionName toPb(String collectionName) { - return CollectionName.newBuilder() - .setCollectionName(collectionName) - .build(); - } - - public static com.alibaba.proxima.be.grpc.ListCondition toPb(ListCondition listCondition) { - if (listCondition == null || listCondition.getRepositoryName() == null) { - return com.alibaba.proxima.be.grpc.ListCondition.newBuilder().build(); - } - return com.alibaba.proxima.be.grpc.ListCondition.newBuilder() - .setRepositoryName(listCondition.getRepositoryName()) - .build(); - } - - public static com.alibaba.proxima.be.grpc.WriteRequest toPb(WriteRequest request) { - return com.alibaba.proxima.be.grpc.WriteRequest.newBuilder() - .setCollectionName(request.getCollectionName()) - .setRowMeta(toPb(request.getRowMeta())) - .addAllRows(toPb(request.getRows())) - .setRequestId(request.getRequestId()) - .setMagicNumber(request.getMagicNumber()) - .build(); - } - - public static com.alibaba.proxima.be.grpc.QueryRequest toPb(QueryRequest request) { - return com.alibaba.proxima.be.grpc.QueryRequest.newBuilder() - .setQueryType( - com.alibaba.proxima.be.grpc.QueryRequest.QueryType.forNumber(request.getQueryType().getValue())) - .setCollectionName(request.getCollectionName()) - .setDebugMode(request.isDebugMode()) - .setKnnParam(toPb(request.getKnnQueryParam())) - .build(); - } - - public static com.alibaba.proxima.be.grpc.GetDocumentRequest toPb(GetDocumentRequest request) { - return com.alibaba.proxima.be.grpc.GetDocumentRequest.newBuilder() - .setCollectionName(request.getCollectionName()) - .setPrimaryKey(request.getPrimaryKey()) - .setDebugMode(request.isDebugMode()) - .build(); - } - - public static Status fromPb(com.alibaba.proxima.be.grpc.Status status) { - return new Status(status.getCode(), status.getReason()); - } - - public static ListCollectionsResponse fromPb(com.alibaba.proxima.be.grpc.ListCollectionsResponse pbResponse) { - Status status = new Status(pbResponse.getStatus().getCode(), pbResponse.getStatus().getReason()); - List collectionInfoList = new ArrayList<>(); - for (int i = 0; i < pbResponse.getCollectionsCount(); ++i) { - collectionInfoList.add(fromPb(pbResponse.getCollections(i))); - } - return new ListCollectionsResponse(status, collectionInfoList); - } - - public static DescribeCollectionResponse fromPb(com.alibaba.proxima.be.grpc.DescribeCollectionResponse pbResponse) { - Status status = new Status(pbResponse.getStatus().getCode(), pbResponse.getStatus().getReason()); - return new DescribeCollectionResponse(status, fromPb(pbResponse.getCollection())); - } - - public static StatsCollectionResponse fromPb(com.alibaba.proxima.be.grpc.StatsCollectionResponse pbResponse) { - Status status = new Status(pbResponse.getStatus().getCode(), pbResponse.getStatus().getReason()); - return new StatsCollectionResponse(status, fromPb(pbResponse.getCollectionStats())); - } - - public static QueryResponse fromPb(com.alibaba.proxima.be.grpc.QueryResponse pbResponse) { - Status status = new Status(pbResponse.getStatus().getCode(), pbResponse.getStatus().getReason()); - return new QueryResponse(status, pbResponse.getLatencyUs(), - pbResponse.getDebugInfo(), fromPb(pbResponse.getResultsList())); - } - - public static GetDocumentResponse fromPb(com.alibaba.proxima.be.grpc.GetDocumentResponse pbResponse) { - Status status = new Status(pbResponse.getStatus().getCode(), pbResponse.getStatus().getReason()); - Document document = fromPb(pbResponse.getDocument()); - return new GetDocumentResponse(status, pbResponse.getDebugInfo(), document); - } - - public static GetVersionResponse fromPb(com.alibaba.proxima.be.grpc.GetVersionResponse pbResponse) { - return new GetVersionResponse(fromPb(pbResponse.getStatus()), pbResponse.getVersion()); - } - - private static com.alibaba.proxima.be.grpc.QueryRequest.KnnQueryParam toPb(QueryRequest.KnnQueryParam queryParam) { - - com.alibaba.proxima.be.grpc.QueryRequest.KnnQueryParam.Builder builder = - com.alibaba.proxima.be.grpc.QueryRequest.KnnQueryParam.newBuilder() - .setColumnName(queryParam.getColumnName()) - .setTopk(queryParam.getTopk()) - .setBatchCount(queryParam.getBatchCount()) - .setDimension(queryParam.getDimension()) - .setDataType(com.alibaba.proxima.be.grpc.DataType.forNumber(queryParam.getDataType().getValue())) - .setRadius(queryParam.getRadius()) - .setIsLinear(queryParam.isLinear()); - if (queryParam.getFeatures() != null) { - builder.setFeatures(ByteString.copyFrom(queryParam.getFeatures())); - } else { - builder.setMatrix(queryParam.getMatrix()); - } - List extraParamList = new ArrayList<>(); - Map extraParams = queryParam.getExtraParams(); - for (Map.Entry entry : extraParams.entrySet()) { - extraParamList.add( - KeyValuePair.newBuilder() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build() - ); - } - builder.addAllExtraParams(extraParamList); - - return builder.build(); - } - - private static com.alibaba.proxima.be.grpc.WriteRequest.RowMeta toPb(WriteRequest.RowMeta rowMeta) { - List indexColumnMetaList = new ArrayList<>(); - List indexColumnMetas = rowMeta.getIndexColumnMetas(); - for (int i = 0; i < indexColumnMetas.size(); ++i) { - WriteRequest.IndexColumnMeta columnMeta = indexColumnMetas.get(i); - indexColumnMetaList.add(com.alibaba.proxima.be.grpc.WriteRequest.IndexColumnMeta.newBuilder() - .setColumnName(columnMeta.getColumnName()) - .setDataType(com.alibaba.proxima.be.grpc.DataType.forNumber(columnMeta.getDataType().getValue())) - .setDimension(columnMeta.getDimension()) - .build()); - } - return com.alibaba.proxima.be.grpc.WriteRequest.RowMeta.newBuilder() - .addAllForwardColumnNames(rowMeta.getForwardColumnNames()) - .addAllIndexColumnMetas(indexColumnMetaList) - .build(); - } - - private static List toPb(List rows) { - List pbRowList = new ArrayList<>(); - for (int i = 0; i < rows.size(); ++i) { - WriteRequest.Row row = rows.get(i); - com.alibaba.proxima.be.grpc.WriteRequest.Row.Builder builder = - com.alibaba.proxima.be.grpc.WriteRequest.Row.newBuilder() - .setPrimaryKey(row.getPrimaryKey()) - .setOperationType(OperationType.forNumber(row.getOperationType().getValue())) - .setIndexColumnValues(row.getIndexValues()) - .setForwardColumnValues(row.getForwardValues()); - LsnContext lsnContext = row.getLsnContext(); - if (lsnContext != null) { - builder.setLsnContext( - com.alibaba.proxima.be.grpc.LsnContext.newBuilder() - .setLsn(lsnContext.getLsn()) - .setContext(lsnContext.getContext()) - .build()); - } - pbRowList.add(builder.build()); - } - return pbRowList; - } - - private static List fromPb(List pbResults) { - List queryResultList = new ArrayList<>(); - if (pbResults == null) { - return queryResultList; - } - for (int i = 0; i < pbResults.size(); ++i) { - queryResultList.add(fromPb(pbResults.get(i))); - } - return queryResultList; - } - - private static QueryResult fromPb(com.alibaba.proxima.be.grpc.QueryResponse.Result pbResult) { - QueryResult.Builder builder = new QueryResult.Builder(); - for (int i = 0; i < pbResult.getDocumentsCount(); ++i) { - builder.addDocument(fromPb(pbResult.getDocuments(i))); - } - return builder.build(); - } - - private static Document fromPb(com.alibaba.proxima.be.grpc.Document pbDocument) { - if (pbDocument == null) { - return null; - } - Map forwardMap = new HashMap<>(); - for (int i = 0; i < pbDocument.getForwardColumnValuesCount(); ++i) { - GenericKeyValue keyValue = pbDocument.getForwardColumnValues(i); - forwardMap.put(keyValue.getKey(), - new Document.ForwardValue.Builder(keyValue.getValue()).build()); - } - return new Document.Builder() - .withPrimaryKey(pbDocument.getPrimaryKey()) - .withScore(pbDocument.getScore()) - .withForwardColumnMap(forwardMap) - .build(); - } - - private static CollectionStats fromPb(com.alibaba.proxima.be.grpc.CollectionStats pbStats) { - CollectionStats.Builder builder = new CollectionStats.Builder() - .withCollectionName(pbStats.getCollectionName()) - .withCollectionPath(pbStats.getCollectionPath()) - .withTotalDocCount(pbStats.getTotalDocCount()) - .withTotalIndexFileCount(pbStats.getTotalIndexFileCount()) - .withTotalIndexFileSize(pbStats.getTotalIndexFileSize()) - .withTotalSegmentCount(pbStats.getTotalSegmentCount()); - for (int i = 0; i < pbStats.getSegmentStatsCount(); ++i) { - builder.addSegmentStats(fromPb(pbStats.getSegmentStats(i))); - } - return builder.build(); - } - - private static CollectionStats.SegmentStats fromPb( - com.alibaba.proxima.be.grpc.CollectionStats.SegmentStats pbStats) { - if (pbStats == null) { - return null; - } - return new CollectionStats.SegmentStats.Builder() - .withSegmentId(pbStats.getSegmentId()) - .withSegmentState(CollectionStats.SegmentState.valueOf(pbStats.getState().getNumber())) - .withDocDount(pbStats.getDocCount()) - .withIndexFileCount(pbStats.getIndexFileCount()) - .withIndexFileSize(pbStats.getIndexFileSize()) - .withMinDocId(pbStats.getMinDocId()) - .withMaxDocId(pbStats.getMaxDocId()) - .withMinDocId(pbStats.getMinDocId()) - .withMinPrimaryKey(pbStats.getMinPrimaryKey()) - .withMaxPrimaryKey(pbStats.getMaxPrimaryKey()) - .withMinTimestamp(pbStats.getMinTimestamp()) - .withMaxTimestamp(pbStats.getMaxTimestamp()) - .withMinLsn(pbStats.getMinLsn()) - .withMaxLsn(pbStats.getMaxLsn()) - .withSegmentPath(pbStats.getSegmentPath()) - .build(); - } - - private static CollectionInfo fromPb(com.alibaba.proxima.be.grpc.CollectionInfo pbInfo) { - if (pbInfo == null) { - return null; - } - CollectionInfo.Builder builder = new CollectionInfo.Builder() - .withCollectionConfig(fromPb(pbInfo.getConfig())) - .withCollectionStatus(fromPb(pbInfo.getStatus())) - .withUuid(pbInfo.getUuid()) - .withMagicNumber(pbInfo.getMagicNumber()); - if (pbInfo.hasLatestLsnContext()) { - com.alibaba.proxima.be.grpc.LsnContext lsnContext = pbInfo.getLatestLsnContext(); - builder.withLatestLsnContext( - LsnContext.newBuilder() - .withLsn(lsnContext.getLsn()) - .withContext(lsnContext.getContext()) - .build()); - } - return builder.build(); - } - - private static CollectionConfig fromPb(com.alibaba.proxima.be.grpc.CollectionConfig config) { - List columnParams = - config.getIndexColumnParamsList(); - List columnParamList = new ArrayList<>(); - for (int i = 0; i < columnParams.size(); ++i) { - columnParamList.add(fromPb(columnParams.get(i))); - } - CollectionConfig.Builder builder = new CollectionConfig.Builder() - .withCollectionName(config.getCollectionName()) - .withMaxDocsPerSegment(config.getMaxDocsPerSegment()) - .withForwardColumnNames(config.getForwardColumnNamesList()) - .withIndexColumnParams(columnParamList); - if (config.hasRepositoryConfig()) { - builder.withDatabaseRepository(fromPb(config.getRepositoryConfig())); - } - return builder.build(); - } - - private static IndexColumnParam fromPb( - com.alibaba.proxima.be.grpc.CollectionConfig.IndexColumnParam indexParam) { - if (indexParam == null) { - return null; - } - Map extraParamMap = new HashMap<>(); - for (int i = 0; i < indexParam.getExtraParamsCount(); ++i) { - KeyValuePair keyValuePair = indexParam.getExtraParams(i); - extraParamMap.put(keyValuePair.getKey(), keyValuePair.getValue()); - } - return new IndexColumnParam.Builder( - indexParam.getColumnName(), - DataType.valueOf(indexParam.getDataType().getNumber()), - indexParam.getDimension()) - .withIndexType(IndexType.valueOf(indexParam.getIndexType().getNumber())) - .build(); - } - - private static DatabaseRepository fromPb( - com.alibaba.proxima.be.grpc.CollectionConfig.RepositoryConfig config) { - return new DatabaseRepository.Builder() - .withConnectionUri(config.getDatabase().getConnectionUri()) - .withPassword(config.getDatabase().getPassword()) - .withUser(config.getDatabase().getUser()) - .withTableName(config.getDatabase().getTableName()) - .withRepositoryName(config.getRepositoryName()) - .build(); - } - - private static CollectionInfo.CollectionStatus fromPb( - com.alibaba.proxima.be.grpc.CollectionInfo.CollectionStatus status) { - return CollectionInfo.CollectionStatus.valueOf(status.getNumber()); - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProximaGrpcSearchClient.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProximaGrpcSearchClient.java deleted file mode 100644 index ce9279f..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProximaGrpcSearchClient.java +++ /dev/null @@ -1,455 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Implements all interfaces with ProximaSearchClient - */ - -package com.alibaba.proxima.be.client; - -import com.alibaba.proxima.be.grpc.CollectionName; -import com.alibaba.proxima.be.grpc.GetVersionRequest; -import com.alibaba.proxima.be.grpc.ProximaServiceGrpc; -import io.grpc.ConnectivityState; -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import io.grpc.StatusRuntimeException; - -import java.util.List; -import java.util.concurrent.TimeUnit; - -/** - * Proxima Grpc Search Client - */ -public class ProximaGrpcSearchClient implements ProximaSearchClient { - private ManagedChannel channel; - private ProximaServiceGrpc.ProximaServiceBlockingStub blockingStub; - private ConnectParam connectParam; - - /** - * Constructor ProximaGrpcSearchClient with ConnectParam - * @param connectParam grpc connecting parameters - */ - public ProximaGrpcSearchClient(ConnectParam connectParam) { - this.connectParam = connectParam; - this.channel = ManagedChannelBuilder.forAddress(connectParam.getHost(), connectParam.getPort()) - .usePlaintext() - .idleTimeout(connectParam.getIdleTimeout(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS) - .keepAliveTime(connectParam.getKeepAliveTime(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS) - .keepAliveTimeout(connectParam.getKeepAliveTimeout(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS) - .maxInboundMessageSize(Integer.MAX_VALUE) - .build(); - this.blockingStub = ProximaServiceGrpc.newBlockingStub(this.channel); - this.checkServerVersion(); - } - - /** - * Close client - */ - @Override - public void close() { - this.close(10); - } - - /** - * Close client - * @param maxWaitSeconds max wait seconds when close client - */ - @Override - public void close(int maxWaitSeconds) { - this.channel.shutdown(); - long now = System.nanoTime(); - long deadline = now + TimeUnit.SECONDS.toNanos(maxWaitSeconds); - boolean interrupted = false; - try { - while (now < deadline && !channel.isTerminated()) { - try { - channel.awaitTermination(deadline - now, TimeUnit.NANOSECONDS); - } catch (InterruptedException ex) { - interrupted = true; - } - } - if (!channel.isTerminated()) { - channel.shutdownNow(); - } - } finally { - if (interrupted) { - Thread.currentThread().interrupt(); - } - } - } - - /** - * Get proxima server version - * @return GetVersionResponse - */ - @Override - public GetVersionResponse getVersion() { - if (!checkAvailable()) { - return new GetVersionResponse(Status.ErrorCode.CLIENT_NOT_CONNECTED); - } - GetVersionRequest request = GetVersionRequest.newBuilder().build(); - com.alibaba.proxima.be.grpc.GetVersionResponse pbResponse; - try { - pbResponse = blockingStub().getVersion(request); - } catch (StatusRuntimeException e) { - return new GetVersionResponse(errorCode(e), e.getStatus().toString()); - } - - return ProtoConverter.fromPb(pbResponse); - } - - /** - * Create collection with collection config - * @param collectionConfig the CollectionConfig object - * @return Status - */ - @Override - public Status createCollection(CollectionConfig collectionConfig) { - if (!checkAvailable()) { - return new Status(Status.ErrorCode.CLIENT_NOT_CONNECTED); - } - - this.validate(collectionConfig); - - com.alibaba.proxima.be.grpc.Status status; - com.alibaba.proxima.be.grpc.CollectionConfig request = ProtoConverter.toPb(collectionConfig); - try { - status = blockingStub().createCollection(request); - } catch (StatusRuntimeException e) { - return new Status(errorCode(e), e.getStatus().toString()); - } - return ProtoConverter.fromPb(status); - } - - /** - * Drop collection with colleciton name - * @param collectionName the collection name - * @return Status - */ - @Override - public Status dropCollection(String collectionName) { - if (!checkAvailable()) { - return new Status(Status.ErrorCode.CLIENT_NOT_CONNECTED); - } - - CollectionName request = ProtoConverter.toPb(collectionName); - com.alibaba.proxima.be.grpc.Status status; - try { - status = blockingStub().dropCollection(request); - } catch (StatusRuntimeException e) { - return new Status(errorCode(e), e.getStatus().toString()); - } - return ProtoConverter.fromPb(status); - } - - /** - * Describe collection with colleciton name - * @param collectionName the collection name - * @return describe collection response - */ - @Override - public DescribeCollectionResponse describeCollection(String collectionName) { - if (!checkAvailable()) { - return new DescribeCollectionResponse(Status.ErrorCode.CLIENT_NOT_CONNECTED); - } - - CollectionName request = ProtoConverter.toPb(collectionName); - com.alibaba.proxima.be.grpc.DescribeCollectionResponse pbResponse; - try { - pbResponse = blockingStub().withDeadlineAfter(connectParam.getTimeout(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS) - .describeCollection(request); - } catch (StatusRuntimeException e) { - return new DescribeCollectionResponse(errorCode(e), e.getStatus().toString()); - } - - return ProtoConverter.fromPb(pbResponse); - } - - /** - * List collections with list condition - * @param listCondition list collections condition - * @return list collection response - */ - @Override - public ListCollectionsResponse listCollections(ListCondition listCondition) { - if (!checkAvailable()) { - return new ListCollectionsResponse(Status.ErrorCode.CLIENT_NOT_CONNECTED); - } - - com.alibaba.proxima.be.grpc.ListCondition request = ProtoConverter.toPb(listCondition); - com.alibaba.proxima.be.grpc.ListCollectionsResponse pbResponse; - try { - pbResponse = blockingStub().listCollections(request); - } catch (StatusRuntimeException e) { - return new ListCollectionsResponse(errorCode(e), e.getStatus().toString()); - } - - return ProtoConverter.fromPb(pbResponse); - } - - /** - * Stats collection with collection name - * @param collectionName the collection name - * @return stats collection response - */ - @Override - public StatsCollectionResponse statsCollection(String collectionName) { - if (!checkAvailable()) { - return new StatsCollectionResponse(Status.ErrorCode.CLIENT_NOT_CONNECTED); - } - - com.alibaba.proxima.be.grpc.CollectionName request = ProtoConverter.toPb(collectionName); - com.alibaba.proxima.be.grpc.StatsCollectionResponse pbResponse; - try { - pbResponse = blockingStub().statsCollection(request); - } catch (StatusRuntimeException e) { - return new StatsCollectionResponse(errorCode(e), e.getStatus().toString()); - } - - return ProtoConverter.fromPb(pbResponse); - } - - /** - * Write records for collection - * @param request write request included insert/update/delete operations - * @return Status - */ - @Override - public Status write(WriteRequest request) { - if (!checkAvailable()) { - return new Status(Status.ErrorCode.CLIENT_NOT_CONNECTED); - } - - this.validate(request); - - com.alibaba.proxima.be.grpc.WriteRequest pbRequest = ProtoConverter.toPb(request); - com.alibaba.proxima.be.grpc.Status pbResponse; - try { - pbResponse = blockingStub().write(pbRequest); - } catch (StatusRuntimeException e) { - return new Status(errorCode(e), e.getStatus().toString()); - } - - return ProtoConverter.fromPb(pbResponse); - } - - /** - * Query records with specified features - * @param request query request included querying featuress - * @return QueryResponse included query result - */ - @Override - public QueryResponse query(QueryRequest request) { - if (!checkAvailable()) { - return new QueryResponse(Status.ErrorCode.CLIENT_NOT_CONNECTED); - } - - this.validate(request); - - com.alibaba.proxima.be.grpc.QueryRequest pbRequest = ProtoConverter.toPb(request); - com.alibaba.proxima.be.grpc.QueryResponse pbResponse; - try { - pbResponse = blockingStub().query(pbRequest); - } catch (StatusRuntimeException e) { - return new QueryResponse(errorCode(e), e.getStatus().toString()); - } - - return ProtoConverter.fromPb(pbResponse); - } - - /** - * Get document by primary key - * @param request the GetDocumentRequest object included collection name and primary key - * @return GetDocumentResponse - */ - @Override - public GetDocumentResponse getDocumentByKey(GetDocumentRequest request) { - if (!checkAvailable()) { - return new GetDocumentResponse(Status.ErrorCode.CLIENT_NOT_CONNECTED); - } - - this.validate(request); - - com.alibaba.proxima.be.grpc.GetDocumentRequest pbRequest = ProtoConverter.toPb(request); - com.alibaba.proxima.be.grpc.GetDocumentResponse pbResponse; - try { - pbResponse = blockingStub().getDocumentByKey(pbRequest); - } catch (StatusRuntimeException e) { - return new GetDocumentResponse(errorCode(e), e.getStatus().toString()); - } - - return ProtoConverter.fromPb(pbResponse); - } - - private boolean checkAvailable() { - ConnectivityState state = this.channel.getState(false); - switch (state) { - case IDLE: - case READY: - case CONNECTING: - return true; - default: - return false; - } - } - - private void validate(CollectionConfig config) throws ProximaSEException { - if (config.getCollectionName() == null || config.getCollectionName().isEmpty()) { - throw new ProximaSEException("Collection name is empty."); - } - - List indexParamList = config.getIndexColumnParams(); - if (indexParamList == null || indexParamList.isEmpty()) { - throw new ProximaSEException("Index Column params is empty."); - } - for (IndexColumnParam indexParam : indexParamList) { - if (indexParam.getColumnName() == null || indexParam.getColumnName().isEmpty()) { - throw new ProximaSEException("Index column name is empty."); - } - if (indexParam.getIndexType() != IndexType.PROXIMA_GRAPH_INDEX) { - throw new ProximaSEException("Index type is invalid."); - } - if (indexParam.getDataType() == DataType.UNDEFINED) { - throw new ProximaSEException("Index data type is undefined."); - } - if (indexParam.getDimension() <= 0) { - throw new ProximaSEException("Index dimension should > 0"); - } - } - - DatabaseRepository dbRepo = config.getDatabaseRepository(); - if (dbRepo != null) { - if (dbRepo.getRepositoryName() == null || dbRepo.getRepositoryName().isEmpty()) { - throw new ProximaSEException("Repository name is empty."); - } - if (dbRepo.getConnectionUri() == null || dbRepo.getConnectionUri().isEmpty()) { - throw new ProximaSEException("Connection uri is empty."); - } - if (dbRepo.getTableName() == null || dbRepo.getTableName().isEmpty()) { - throw new ProximaSEException("Table name is empty."); - } - if (dbRepo.getUser() == null || dbRepo.getUser().isEmpty()) { - throw new ProximaSEException("User name is empty."); - } - if (dbRepo.getPassword() == null || dbRepo.getPassword().isEmpty()) { - throw new ProximaSEException("Password is empty."); - } - } - } - - private void validate(WriteRequest request) throws ProximaSEException { - if (request.getCollectionName() == null || request.getCollectionName().isEmpty()) { - throw new ProximaSEException("Collection name is empty."); - } - WriteRequest.RowMeta rowMeta = request.getRowMeta(); - if (rowMeta == null) { - throw new ProximaSEException("RowMeta is empty."); - } - if (rowMeta.getIndexColumnMetas() == null || rowMeta.getIndexColumnMetas().isEmpty()) { - throw new ProximaSEException("Index column metas is empty in RowMeta."); - } - - List rows = request.getRows(); - if (rows == null || rows.isEmpty()) { - throw new ProximaSEException("Rows is empty."); - } - for (WriteRequest.Row row : rows) { - if(row.getOperationType() != WriteRequest.OperationType.DELETE) { - if (row.getIndexValues() == null || row.getIndexValues().getValuesCount() == 0) { - throw new ProximaSEException("Index column values is empty in Row."); - } - } - } - } - - private void validate(QueryRequest request) throws ProximaSEException { - if (request.getQueryType() != QueryRequest.QueryType.KNN) { - throw new ProximaSEException("Query type is invalid."); - } - if (request.getCollectionName() == null || request.getCollectionName().isEmpty()) { - throw new ProximaSEException("Collection name is empty."); - } - QueryRequest.KnnQueryParam knnQueryParam = request.getKnnQueryParam(); - if (knnQueryParam == null) { - throw new ProximaSEException("Knn query param is empty."); - } - if (knnQueryParam.getColumnName() == null || knnQueryParam.getColumnName().isEmpty()) { - throw new ProximaSEException("Column name is empty in KnnQueryParam."); - } - if (knnQueryParam.getTopk() <= 0) { - throw new ProximaSEException("Topk should > 0 in KnnQueryParam"); - } - if ((knnQueryParam.getFeatures() == null || knnQueryParam.getFeatures().length == 0) && - (knnQueryParam.getMatrix() == null || knnQueryParam.getMatrix().length() == 0)) { - throw new ProximaSEException("Features is empty in KnnQueryParam"); - } - if (knnQueryParam.getBatchCount() <= 0) { - throw new ProximaSEException("Batch count should > 0 in KnnQueryParam"); - } - if (knnQueryParam.getDimension() <= 0) { - throw new ProximaSEException("Dimension should > 0 in KnnQueryParam"); - } - } - - private void validate(GetDocumentRequest request) throws ProximaSEException { - if (request.getCollectionName() == null || request.getCollectionName().isEmpty()) { - throw new ProximaSEException("Collection name is empty."); - } - } - - private ProximaServiceGrpc.ProximaServiceBlockingStub blockingStub() { - return this.blockingStub.withDeadlineAfter( - this.connectParam.getTimeout(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS); - } - - private void checkServerVersion() throws ProximaSEException { - String clientVersion = this.getClientVersion(); - if (clientVersion == null || clientVersion.isEmpty()) { - throw new ProximaSEException("Java SDK client version is empty."); - } - GetVersionResponse response = this.getVersion(); - if (!response.ok()) { - throw new ProximaSEException("Get server version failed: " + response.getStatus().getReason()); - } - String serverVersion = response.getVersion(); - - String[] clientArray = clientVersion.split("\\."); - String[] serverArray = serverVersion.split("\\."); - if (clientArray.length != 3) { - throw new ProximaSEException("Get client version failed."); - } - if (serverArray.length < 3) { - throw new ProximaSEException("Server version is invalid."); - } - if (clientArray[0].compareTo(serverArray[0]) != 0 || clientArray[1].compareTo(serverArray[1]) != 0) { - throw new ProximaSEException("Client and server version mismatched."); - } - } - - private Status.ErrorCode errorCode(StatusRuntimeException e) { - io.grpc.Status status = e.getStatus(); - if (status == null) { - return Status.ErrorCode.RPC_ERROR; - } - if (status.getCode() == io.grpc.Status.Code.DEADLINE_EXCEEDED) { - return Status.ErrorCode.RPC_TIMEOUT; - } else { - return Status.ErrorCode.RPC_ERROR; - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProximaSEException.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProximaSEException.java deleted file mode 100644 index dbb8d36..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProximaSEException.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Represents proxima be exception - */ - -package com.alibaba.proxima.be.client; - -/** - * Proxima Search Engine Exception - */ -public class ProximaSEException extends RuntimeException { - public ProximaSEException(String message) { - super(message); - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProximaSearchClient.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProximaSearchClient.java deleted file mode 100644 index c14ff2d..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/ProximaSearchClient.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Interface to describe proxima client interface and action. - * You can get more details usage from examples - */ - -package com.alibaba.proxima.be.client; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; -import java.util.function.Supplier; - -/** - * The Proxima Search Client Interface - */ -public interface ProximaSearchClient { - final String CLIENT_VERSION = new Supplier() { - @Override - public String get() { - Properties properties = new Properties(); - InputStream inputStream = ProximaSearchClient.class.getClassLoader() - .getResourceAsStream("proxima-be.properties"); - try { - properties.load(inputStream); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - inputStream.close(); - } catch (IOException e) { - } - } - return properties.getProperty("version"); - } - }.get(); - - /** - * Get proxima search client version - * @return String: client version - */ - default String getClientVersion() { - return this.CLIENT_VERSION; - } - - /** - * Get proxima server version - * @return GetVersionResponse - */ - GetVersionResponse getVersion(); - - /** - * Create collection with collection config - * @param collectionConfig the CollectionConfig object - * @return Status - */ - Status createCollection(CollectionConfig collectionConfig); - - /** - * Drop collection with colleciton name - * @param collectionName the collection name - * @return Status - */ - Status dropCollection(String collectionName); - - /** - * Describe collection with colleciton name - * @param collectionName the collection name - * @return DescribeCollectionResponse: describe collection response - */ - DescribeCollectionResponse describeCollection(String collectionName); - - /** - * List collections with list condition - * @param listCondition list collections condition - * @return ListCollectionsResponse: list collections response - */ - ListCollectionsResponse listCollections(ListCondition listCondition); - - // Stats collection with collection name - - /** - * Stats collection with collection name - * @param collectionName the collection name - * @return stats collection response - */ - StatsCollectionResponse statsCollection(String collectionName); - - /** - * Write records for collection - * @param request write request included insert/update/delete operations - * @return Status - */ - Status write(WriteRequest request); - - /** - * Query records with specified features - * @param request query request included querying featuress - * @return QueryResponse: included query result - */ - QueryResponse query(QueryRequest request); - - /** - * Get document by primary key - * @param request the GetDocumentRequest object included collection name and primary key - * @return GetDocumentResponse: document response - */ - GetDocumentResponse getDocumentByKey(GetDocumentRequest request); - - /** - * Close client - */ - void close(); - - /** - * Close client - * @param maxWaitSeconds max wait seconds when close client - */ - void close(int maxWaitSeconds); -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/QueryRequest.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/QueryRequest.java deleted file mode 100644 index c7e7514..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/QueryRequest.java +++ /dev/null @@ -1,442 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Contains the query information - */ - -package com.alibaba.proxima.be.client; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.FloatBuffer; -import java.util.HashMap; -import java.util.Map; - -/** - * Contains query information - */ -public class QueryRequest { - private final QueryType queryType; - private final String collectionName; - private final boolean debugMode; - private final KnnQueryParam knnQueryParam; - - private QueryRequest(Builder builder) { - this.queryType = builder.queryType; - this.collectionName = builder.collectionName; - this.debugMode = builder.debugMode; - this.knnQueryParam = builder.knnQueryParam; - } - - public QueryType getQueryType() { - return queryType; - } - - public String getCollectionName() { - return collectionName; - } - - public boolean isDebugMode() { - return debugMode; - } - - public KnnQueryParam getKnnQueryParam() { - return knnQueryParam; - } - - /** - * New QueryRequest builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for QueryRequest - */ - public static class Builder { - // required parameters - private String collectionName; - private KnnQueryParam knnQueryParam; - - // optional parameters - private QueryType queryType = QueryType.KNN; - private boolean debugMode = false; - - /** - * Empty constructor - */ - public Builder() { - } - - /** - * Constructor with collection name and query param - * @param collectionName collection name - * @param knnQueryParam knn query parameters - */ - public Builder(String collectionName, KnnQueryParam knnQueryParam) { - this.collectionName = collectionName; - this.knnQueryParam = knnQueryParam; - } - - /** - * Set query type - * @param queryType query type - * @return Builder - */ - public Builder withQueryType(QueryType queryType) { - this.queryType = queryType; - return this; - } - - /** - * Set collection name - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set debug mode - * @param debugMode debug mode, true means turnning the debug function - * @return Builder - */ - public Builder withDebugMode(boolean debugMode) { - this.debugMode = debugMode; - return this; - } - - /** - * Set knn query param - * @param knnQueryParam knn query parameters - * @return Builder - */ - public Builder withKnnQueryParam(KnnQueryParam knnQueryParam) { - this.knnQueryParam = knnQueryParam; - return this; - } - - /** - * Build QueryRequest object - * @return QueryRequest - */ - public QueryRequest build() { - return new QueryRequest(this); - } - } - - /** - * Contains the query parameters - */ - public static class KnnQueryParam { - private final String columnName; - private final int topk; - private final byte[] features; - private String matrix; - private final int batchCount; - private final int dimension; - private final DataType dataType; - private final float radius; - private final boolean isLinear; - private final Map extraParams; - - private KnnQueryParam(Builder builder) { - this.columnName = builder.columnName; - this.topk = builder.topk; - this.features = builder.features; - this.matrix = builder.matrix; - this.batchCount = builder.batchCount; - this.dimension = builder.dimension; - this.dataType = builder.dataType; - this.radius = builder.radius; - this.isLinear = builder.isLinear; - this.extraParams = builder.extraParams; - } - - public String getColumnName() { - return columnName; - } - - public int getTopk() { - return topk; - } - - public byte[] getFeatures() { - return features; - } - - public String getMatrix() { - return matrix; - } - - public int getBatchCount() { - return batchCount; - } - - public int getDimension() { - return dimension; - } - - public DataType getDataType() { - return dataType; - } - - public float getRadius() { - return radius; - } - - public boolean isLinear() { - return isLinear; - } - - public Map getExtraParams() { - return extraParams; - } - - /** - * New KnnQueryParam builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for KnnQueryParam - */ - public static class Builder { - // required parameters - private String columnName; - private byte[] features = null; - private String matrix = null; - - // optional parameters - private int topk = 100; - private int batchCount = 1; - private int dimension = 0; - private DataType dataType = DataType.UNDEFINED; - private float radius = 0.0f; - private boolean isLinear = false; - private Map extraParams = new HashMap<>(); - - /** - * Empty constructor - */ - public Builder() { - } - - /** - * Constructor with column name - * @param columnName index column name - */ - public Builder(String columnName) { - this.columnName = columnName; - } - - /** - * Set index column name - * @param columnName index column name - * @return Builder - */ - public Builder withColumnName(String columnName) { - this.columnName = columnName; - return this; - } - - /** - * Set topk - * @param topk return result number - * @return Builder - */ - public Builder withTopk(int topk) { - this.topk = topk; - return this; - } - - /** - * Set radius - * @param radius score threshold, result that score less than radius can be return - * @return Builder - */ - public Builder withRadius(float radius) { - this.radius = radius; - return this; - } - - // Set use linear - - /** - * Set use linear search flag - * @param linear use linear - * @return Builder - */ - public Builder withLinear(boolean linear) { - isLinear = linear; - return this; - } - - /** - * Set extra params - * @param extraParams extra parameters - * @return Builder - */ - public Builder withExtraParams(Map extraParams) { - this.extraParams = extraParams; - return this; - } - - /** - * Set bytes features - * @param features bytes features - * @param dataType data type - * @param dimension dimension - * @param batchCount query batch count - * @return Builder - */ - public Builder withFeatures(byte[] features, DataType dataType, int dimension, int batchCount) { - if (features == null || features.length == 0) { - return this; - } - - this.features = features; - - this.dataType = dataType; - this.dimension = dimension; - this.batchCount = batchCount; - - return this; - } - - /** - * Set features with json matrix - * @param jsonMatrix json format matrix - * @param dataType data type - * @param dimension dimension - * @param batchCount query batch count - * @return Builder - */ - public Builder withFeatures(String jsonMatrix, DataType dataType, int dimension, int batchCount) { - if (jsonMatrix == null || jsonMatrix.isEmpty()) { - return this; - } - this.matrix = jsonMatrix; - - this.dataType = dataType; - this.dimension = dimension; - this.batchCount = batchCount; - - return this; - } - - /** - * Set float type features - * @param features query features - * @return Builder - */ - public Builder withFeatures(float[] features) { - // pack float features - if (features == null || features.length == 0) { - return this; - } - - ByteBuffer bf = ByteBuffer.allocate(features.length * 4).order(ByteOrder.LITTLE_ENDIAN); - bf.asFloatBuffer().put(features); - this.features = bf.array(); - - this.dataType = DataType.VECTOR_FP32; - this.dimension = features.length; - this.batchCount = 1; - - return this; - } - - /** - * Set two dimension float type features - * @param features query features - * @return Builder - */ - public Builder withFeatures(float[][] features) { - if (features == null || features.length == 0) { - return this; - } - int dim = features[0].length; - for (int i = 0; i < features.length; ++i) { - if (features[i].length != dim) { - return this; - } - } - - ByteBuffer bf = ByteBuffer.allocate(features.length * dim * 4).order(ByteOrder.LITTLE_ENDIAN); - FloatBuffer floatBuffer = bf.asFloatBuffer(); - for (int i = 0; i < features.length; ++i) { - floatBuffer.put(features[i]); - } - this.features = bf.array(); - - this.dataType = DataType.VECTOR_FP32; - this.batchCount = features.length; - this.dimension = dim; - - return this; - } - - /** - * Add one extra parameter - * @param key extra parameter key - * @param value extra parameter value - * @return Builder - */ - public Builder addExtraParam(String key, String value) { - this.extraParams.put(key, value); - return this; - } - - /** - * Build KnnQueryParam object - * @return KnnQueryBuilder - */ - public KnnQueryParam build() { - return new KnnQueryParam(this); - } - } - } - - /** - * Query type - */ - public enum QueryType { - /** - * Knn query type - */ - KNN(0); - - private int value; - - QueryType(int value) { - this.value = value; - } - - public int getValue() { - return this.value; - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/QueryResponse.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/QueryResponse.java deleted file mode 100644 index ca4548d..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/QueryResponse.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief QueryResponse contains the query documents and status - */ - -package com.alibaba.proxima.be.client; - -import java.util.List; - -/** - * Contains query documents and status - */ -public class QueryResponse { - private Status status; - private long latencyUs; - private String debugInfo; - private List queryResults; - - public QueryResponse(Status status, long latencyMs, - String debugInfo, List queryResults) { - this.status = status; - this.latencyUs = latencyMs; - this.debugInfo = debugInfo; - this.queryResults = queryResults; - } - - public QueryResponse(Status.ErrorCode code) { - this.status = new Status(code); - this.latencyUs = 0; - this.debugInfo = null; - this.queryResults = null; - } - - public QueryResponse(Status.ErrorCode code, String reason) { - this.status = new Status(code, reason); - this.latencyUs = 0; - this.debugInfo = null; - this.queryResults = null; - } - - public Status getStatus() { - return status; - } - - public long getLatencyUs() { - return latencyUs; - } - - public String getDebugInfo() { - return debugInfo; - } - - public List getQueryResults() { - return queryResults; - } - - /** - * Get query result batch count - * @return int - */ - public int getQueryResultCount() { - if (this.queryResults != null) { - return this.queryResults.size(); - } - return 0; - } - - /** - * Get specified query result - * @param index query result index - * @return QueryResult - */ - public QueryResult getQueryResult(int index) { - return this.queryResults.get(index); - } - - /** - * Is query request success - * @return boolean - */ - public boolean ok() { - return this.status.ok(); - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/QueryResult.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/QueryResult.java deleted file mode 100644 index 28126d1..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/QueryResult.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Represents the result for one query - */ - -package com.alibaba.proxima.be.client; - -import java.util.ArrayList; -import java.util.List; - -/** - * Contains query result documents - */ -public class QueryResult { - private final List documents; - - private QueryResult(Builder builder) { - this.documents = builder.documents; - } - - public List getDocuments() { - return documents; - } - - /** - * Get query document count - * @return int - */ - public int getDocumentCount() { - if (this.documents != null) { - return this.documents.size(); - } - return 0; - } - - /** - * Get specified document - * @param index docucment index - * @return Document - */ - public Document getDocument(int index) { - if (index < documents.size()) { - return this.documents.get(index); - } - return null; - } - - /** - * New QueryResult builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for QueryResult - */ - public static class Builder { - private List documents = new ArrayList<>(); - - /** - * Empty constructor - */ - public Builder() { - } - - /** - * Set document list - * @param documents document list - * @return Builder - */ - public Builder withDocuments(List documents) { - this.documents = documents; - return this; - } - - /** - * Add one document - * @param document added document - * @return Builder - */ - public Builder addDocument(Document document) { - this.documents.add(document); - return this; - } - - /** - * Build QueryResult object - * @return QueryResult - */ - public QueryResult build() { - return new QueryResult(this); - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/StatsCollectionResponse.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/StatsCollectionResponse.java deleted file mode 100644 index 331e968..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/StatsCollectionResponse.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief StatsCollectionResponse contains the statistic info for collection - */ - -package com.alibaba.proxima.be.client; - -/** - * Contains statistic information for collection - */ -public class StatsCollectionResponse { - private Status status; - private CollectionStats collectionStats; - - /** - * Constructor with statuss and collection stats - * @param status status - * @param collectionStats collection stats - */ - public StatsCollectionResponse(Status status, CollectionStats collectionStats) { - this.status = status; - this.collectionStats = collectionStats; - } - - /** - * Constructor with error code - * @param code error code - */ - public StatsCollectionResponse(Status.ErrorCode code) { - this.status = new Status(code); - this.collectionStats = null; - } - - /** - * Constructor with code and reason - * @param code error code - * @param reason error message - */ - public StatsCollectionResponse(Status.ErrorCode code, String reason) { - this.status = new Status(code, reason); - this.collectionStats = null; - } - - public Status getStatus() { - return status; - } - - public CollectionStats getCollectionStats() { - return collectionStats; - } - - /** - * Is request success, true means success - * @return boolean - */ - public boolean ok() { - return this.status.ok(); - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/Status.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/Status.java deleted file mode 100644 index a86c1b6..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/Status.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Contains the code and reason - */ - -package com.alibaba.proxima.be.client; - -/** - * Status for response - */ -public class Status { - private final int code; - private final String reason; - - /** - * Constructor with int code and reason - * @param code code value from server - * @param reason error message - */ - public Status(int code, String reason) { - this.code = code; - this.reason = reason; - } - - /** - * Constructor with ErrorCode and reason - * @param code error code - * @param reason error message - */ - public Status(ErrorCode code, String reason) { - this.code = code.getCode(); - this.reason = reason; - } - - /** - * Constructor with error code - * @param code error code - */ - public Status(ErrorCode code) { - this.code = code.getCode(); - if (code == ErrorCode.CLIENT_NOT_CONNECTED) { - this.reason = "Client not connected to proxima search engine"; - } else if (code == ErrorCode.RPC_TIMEOUT) { - this.reason = "Rpc request timeout"; - } else if (code == ErrorCode.RPC_ERROR) { - this.reason = "Rpc error occurred"; - } else if (code == ErrorCode.UNKNOWN_ERROR) { - this.reason = "Unknown error occurred"; - } else { - this.reason = "Success"; - } - } - - public int getCode() { - return code; - } - - public String getReason() { - return reason; - } - - /** - * Is status normal - * @return boolean - */ - public boolean ok() { - return this.code == 0; - } - - /** - * Convert the Status to json string - * @return String - */ - public String toString() { - return "{ \"code\": " + String.valueOf(code) + ", \"reason\": \"" + reason + "\"}"; - } - - /** - * Java client side error - */ - public enum ErrorCode { - /** - * Success status - */ - SUCCESSS(0), - /** - * Rpc timeout - */ - RPC_TIMEOUT(10000), - /** - * Rpc call error - */ - RPC_ERROR(10001), - /** - * Client not connected - */ - CLIENT_NOT_CONNECTED(10002), - /** - * Unknown error - */ - UNKNOWN_ERROR(10003); - - private int code; - - ErrorCode(int code) { - this.code = code; - } - - public int getCode() { - return this.code; - } - } -} diff --git a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/WriteRequest.java b/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/WriteRequest.java deleted file mode 100644 index d3beb92..0000000 --- a/proxima-be-java-sdk/src/main/java/com/alibaba/proxima/be/client/WriteRequest.java +++ /dev/null @@ -1,662 +0,0 @@ -/** - * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. - * - * Licensed 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 - * - * 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. - - *

- * \author Hongqing.hu - * \date Mar 2021 - * \brief Contains the rows information for collection - */ - -package com.alibaba.proxima.be.client; - -import com.alibaba.proxima.be.grpc.GenericValue; -import com.alibaba.proxima.be.grpc.GenericValueList; -import com.google.protobuf.ByteString; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.List; - -/** - * Contains the write rows information - */ -public class WriteRequest { - private final String collectionName; - private final RowMeta rowMeta; - private final List rows; - private final String requestId; - private final long magicNumber; - - private WriteRequest(Builder builder) { - this.collectionName = builder.collectionName; - this.rowMeta = builder.rowMetaBuilder.build(); - this.rows = builder.rows; - this.requestId = builder.requestId; - this.magicNumber = builder.magicNumber; - } - - public String getCollectionName() { - return collectionName; - } - - public RowMeta getRowMeta() { - return rowMeta; - } - - public List getRows() { - return rows; - } - - public String getRequestId() { - return requestId; - } - - public long getMagicNumber() { - return magicNumber; - } - - /** - * New WriteRequest builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for WriteRequest - */ - public static class Builder { - // required parameters - private String collectionName; - private RowMeta.Builder rowMetaBuilder = RowMeta.newBuilder(); - private List rows = new ArrayList<>(); - - // optional parameters - private String requestId = ""; - private long magicNumber = 0; - - /** - * Constructor without parameters - */ - public Builder() { - } - - /** - * Set collection name - * @param collectionName collection name - * @return Builder - */ - public Builder withCollectionName(String collectionName) { - this.collectionName = collectionName; - return this; - } - - /** - * Set row list - * @param rows write row list - * @return Builder - */ - public Builder withRows(List rows) { - this.rows = rows; - return this; - } - - /** - * Set Request id - * @param requestId request id - * @return Builder - */ - public Builder withRequestId(String requestId) { - this.requestId = requestId; - return this; - } - - /** - * Set magic number - * @param magicNumber magic number - * @return Builder - */ - public Builder withMagicNumber(long magicNumber) { - this.magicNumber = magicNumber; - return this; - } - - /** - * Set forward column list - * @param forwardColumnList forward column list - * @return Builder - */ - public Builder withForwardColumnList(List forwardColumnList) { - for (String columnName : forwardColumnList) { - this.rowMetaBuilder.addForwardColumnName(columnName); - } - return this; - } - - /** - * Set index column meta list - * @param indexColumnMetaList index column meta list - * @return Builder - */ - public Builder withIndexColumnMetaList(List indexColumnMetaList) { - this.rowMetaBuilder.withIndexColumnMetas(indexColumnMetaList); - return this; - } - - /** - * Add one index column meta information - * @param columnName index column name - * @param dataType index data type - * @param dimension index dimension - * @return Builder - */ - public Builder addIndexColumnMeta(String columnName, DataType dataType, int dimension) { - this.rowMetaBuilder.addIndexColumnMeta( - new IndexColumnMeta.Builder(columnName, dataType, dimension).build()); - return this; - } - - /** - * Add one forward column - * @param columnName forward column name - * @return Builder - */ - public Builder addForwardColumn(String columnName) { - this.rowMetaBuilder.addForwardColumnName(columnName); - return this; - } - - /** - * Add one row - * @param row write row information - * @return Builder - */ - public Builder addRow(Row row) { - this.rows.add(row); - return this; - } - - /** - * Build WriteRequest object - * @return WriteRequest - */ - public WriteRequest build() { - return new WriteRequest(this); - } - } - - /** - * Document operation type - */ - public enum OperationType { - /** - * Insert record - */ - INSERT(0), - /** - * Update record - */ - UPDATE(1), - /** - * Delete record - */ - DELETE(2); - - private int value; - - OperationType(int value) { - this.value = value; - } - - public int getValue() { - return this.value; - } - } - - /** - * Contains index and forward writing information - */ - public static class Row { - private final long primaryKey; - private final OperationType operationType; - private final GenericValueList indexValues; - private final GenericValueList forwardValues; - private final LsnContext lsnContext; - - private Row(Builder builder) { - this.primaryKey = builder.primaryKey; - this.operationType = builder.operationType; - this.indexValues = builder.indexColumnBuilder.build(); - this.forwardValues = builder.forwardColumnBuilder.build(); - this.lsnContext = builder.lsnContext; - } - - public long getPrimaryKey() { - return primaryKey; - } - - public OperationType getOperationType() { - return operationType; - } - - public GenericValueList getIndexValues() { - return indexValues; - } - - public GenericValueList getForwardValues() { - return forwardValues; - } - - public LsnContext getLsnContext() { - return lsnContext; - } - - /** - * New row builder object - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Builder for Row - */ - public static class Builder { - // required parameters - private long primaryKey; - private OperationType operationType; - private GenericValueList.Builder indexColumnBuilder = GenericValueList.newBuilder(); - // optional parameters - private GenericValueList.Builder forwardColumnBuilder = GenericValueList.newBuilder(); - private LsnContext lsnContext = null; - - /** - * Empty constructor - */ - public Builder() { - } - - /** - * Constructor with primary key and operation type - * @param primaryKey primary key - * @param operationType operation type - */ - public Builder(long primaryKey, OperationType operationType) { - this.primaryKey = primaryKey; - this.operationType = operationType; - } - - /** - * Set primary key - * @param primaryKey primary key - * @return Builder - */ - public Builder withPrimaryKey(long primaryKey) { - this.primaryKey = primaryKey; - return this; - } - - /** - * Set operation type - * @param operationType operation type - * @return Builder - */ - public Builder withOperationType(OperationType operationType) { - this.operationType = operationType; - return this; - } - - /** - * Set lsn context - * @param lsnContext lsn context information - * @return Builder - */ - public Builder withLsnContext(LsnContext lsnContext) { - this.lsnContext = lsnContext; - return this; - } - - /** - * Add string type index column value - * @param indexValue string index column value - * @return Builder - */ - public Builder addIndexValue(String indexValue) { - indexColumnBuilder.addValues( - GenericValue.newBuilder().setStringValue(indexValue).build() - ); - return this; - } - - /** - * Add bytes type index column value - * @param indexValue bytes index column value - * @return Builder - */ - public Builder addIndexValue(byte[] indexValue) { - indexColumnBuilder.addValues( - GenericValue.newBuilder().setBytesValue(ByteString.copyFrom(indexValue)) - ); - return this; - } - - /** - * Add float type index column value - * @param indexValue float index column value - * @return Builder - */ - public Builder addIndexValue(float[] indexValue) { - if (indexValue == null || indexValue.length == 0) { - return this; - } - - ByteBuffer bf = ByteBuffer.allocate(indexValue.length * 4).order(ByteOrder.LITTLE_ENDIAN); - bf.asFloatBuffer().put(indexValue); - indexColumnBuilder.addValues( - GenericValue.newBuilder().setBytesValue(ByteString.copyFrom(bf.array()))); - - return this; - } - - /** - * Add byte type forward column value - * @param forwardValue bytes forward column value - * @return Builder - */ - public Builder addForwardValue(byte[] forwardValue) { - forwardColumnBuilder.addValues( - GenericValue.newBuilder().setBytesValue(ByteString.copyFrom(forwardValue)) - ); - return this; - } - - /** - * Add string type forward column value - * @param forwardValuey string forward value - * @return Builder - */ - public Builder addForwardValue(String forwardValuey) { - forwardColumnBuilder.addValues( - GenericValue.newBuilder().setStringValue(forwardValuey) - ); - return this; - } - - /** - * Add boolean type forward column value - * @param forwardValuey boolean forward value - * @return Builder - */ - public Builder addForwardValue(boolean forwardValuey) { - forwardColumnBuilder.addValues( - GenericValue.newBuilder().setBoolValue(forwardValuey) - ); - return this; - } - - /** - * Add int type forward column value - * @param forwardValuey int forward value - * @return Builder - */ - public Builder addForwardValue(int forwardValuey) { - forwardColumnBuilder.addValues( - GenericValue.newBuilder().setInt32Value(forwardValuey) - ); - return this; - } - - /** - * Add long type forward column value - * @param forwardValuey long forward value - * @return Builder - */ - public Builder addForwardValue(long forwardValuey) { - forwardColumnBuilder.addValues( - GenericValue.newBuilder().setInt64Value(forwardValuey) - ); - return this; - } - - /** - * Add float type forward column value - * @param forwardValuey float forward value - * @return Builder - */ - public Builder addForwardValue(float forwardValuey) { - forwardColumnBuilder.addValues( - GenericValue.newBuilder().setFloatValue(forwardValuey) - ); - return this; - } - - /** - * Add double type forward column value - * @param forwardValuey double forward value - * @return Builder - */ - public Builder addForwardValue(double forwardValuey) { - forwardColumnBuilder.addValues( - GenericValue.newBuilder().setDoubleValue(forwardValuey) - ); - return this; - } - - /** - * Build Row object - * @return Row - */ - public Row build() { - return new Row(this); - } - } - } - - /** - * Contains the index column information - */ - public static class IndexColumnMeta { - private final String columnName; - private final DataType dataType; - private final int dimension; - - private IndexColumnMeta(Builder builder) { - this.columnName = builder.columnName; - this.dataType = builder.dataType; - this.dimension = builder.dimension; - } - - public String getColumnName() { - return columnName; - } - - public DataType getDataType() { - return dataType; - } - - public int getDimension() { - return dimension; - } - - /** - * New IndexColumnMeta builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** Builder for IndexColumnMeta */ - public static class Builder { - // required parameters - private String columnName; - private DataType dataType; - private int dimension; - - /** - * Empty constructor - */ - public Builder() { - } - - /** - * Constructor with parameters - * @param columnName index column name - * @param dataType index data type - * @param dimension index dimension - */ - public Builder(String columnName, DataType dataType, int dimension) { - this.columnName = columnName; - this.dataType = dataType; - this.dimension = dimension; - } - - /** - * Set column name - * @param columnName index column name - * @return Builder - */ - public Builder withColumnName(String columnName) { - this.columnName = columnName; - return this; - } - - /** - * Set data type - * @param dataType index data type - * @return Builder - */ - public Builder withDataType(DataType dataType) { - this.dataType = dataType; - return this; - } - - /** - * Set dimension - * @param dimension index dimension - * @return Builder - */ - public Builder withDimension(int dimension) { - this.dimension = dimension; - return this; - } - - /** - * Build IndexColumnMeta object - * @return IndexColumnMeta - */ - public IndexColumnMeta build() { - return new IndexColumnMeta(this); - } - } - } - - /** - * Contains index and forward metas - */ - public static class RowMeta { - private final List indexColumnMetas; - private final List forwardColumnNames; - - private RowMeta(Builder builder) { - this.indexColumnMetas = builder.indexColumnMetas; - this.forwardColumnNames = builder.forwardColumnNames; - } - - public List getIndexColumnMetas() { - return indexColumnMetas; - } - - public List getForwardColumnNames() { - return forwardColumnNames; - } - - /** - * New RowMeta builder - * @return Builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** Builder for RowMeta */ - public static class Builder { - // required parameters - private List indexColumnMetas = new ArrayList<>(); - - // optional parameters - private List forwardColumnNames = new ArrayList<>(); - - /** - * Empty constructor - */ - public Builder() { - } - - /** - * Set index column meta list - * @param indexColumnMetas index column meta list - * @return Builder - */ - public Builder withIndexColumnMetas(List indexColumnMetas) { - this.indexColumnMetas = indexColumnMetas; - return this; - } - - /** - * Set forward column name list - * @param forwardColumnNames forward column name list - * @return Builder - */ - public Builder withForwardColumnNames(List forwardColumnNames) { - this.forwardColumnNames = forwardColumnNames; - return this; - } - - /** - * Add single index column meta - * @param indexColumnMeta index column meta - * @return Builder - */ - public Builder addIndexColumnMeta(IndexColumnMeta indexColumnMeta) { - this.indexColumnMetas.add(indexColumnMeta); - return this; - } - - /** - * Add single forward column name - * @param forwardColumnName forward column name - * @return Builder - */ - public Builder addForwardColumnName(String forwardColumnName) { - this.forwardColumnNames.add(forwardColumnName); - return this; - } - - /** - * Build RowMeta object - * @return RowMeta - */ - public RowMeta build() { - return new RowMeta(this); - } - - } - } - -} diff --git a/proxima-be-java-sdk/src/main/proto/common.proto b/proxima-be-java-sdk/src/main/proto/common.proto deleted file mode 100644 index 4f5986c..0000000 --- a/proxima-be-java-sdk/src/main/proto/common.proto +++ /dev/null @@ -1,145 +0,0 @@ -/** - * Copyright (C) The Software Authors. All rights reserved. - - * \file common.proto - * \author Hechong.xyf - * \date Oct 2020 - * \version 1.0.0 - * \brief Common definition for bilin engine - */ - -syntax = "proto3"; - -option java_package = "com.alibaba.proxima.be.grpc"; -option java_multiple_files = true; -option java_outer_classname = "ProximaCommonProto"; - -package proxima.be.proto; - -// The Go package name, refers to https://developers.google.com/protocol-buffers/docs/reference/go-generated#package -option go_package = "proxima/be/proto"; - -/*! Union of Generic Value - */ -message GenericValue { - oneof value_oneof { - bytes bytes_value = 1; - string string_value = 2; - bool bool_value = 3; - int32 int32_value = 4; - int64 int64_value = 5; - uint32 uint32_value = 6; - uint64 uint64_value = 7; - float float_value = 8; - double double_value = 9; - }; -}; - -/*! Message of Generic Value List - */ -message GenericValueList { - repeated GenericValue values = 1; -}; - -/*! Message of Generic Value Meta - */ -message GenericValueMeta { - /*! Types of Field - */ - enum FieldType { - FT_BYTES = 0; // bytes - FT_STRING = 1; // string - FT_BOOL = 2; // bool - FT_INT32 = 3; // int32 - FT_INT64 = 4; // int64 - FT_UINT32 = 5; // uint32 - FT_UINT64 = 6; // uint64 - FT_FLOAT = 7; // float - FT_DOUBLE = 8; // double float - }; - - string field_name = 1; - FieldType field_type = 2; -}; - -/*! Message of Generic Key-Value Pair - */ -message GenericKeyValue { - string key = 1; - GenericValue value = 2; -}; - -/*! Message of IndexParameter, which used to customize index, and query - */ -message KeyValuePair { - string key = 1; - string value = 2; -} - -/*! Types of Operation - */ -enum OperationType { - OP_INSERT = 0; // Insert Operation - OP_UPDATE = 1; // Update Operation - OP_DELETE = 2; // Delete Operation -}; - -/*! Types of Feature (same as Proxima) - */ -enum FeatureType { - FT_UNDEFINED = 0; // Undefined - FT_BINARY32 = 1; // 32-bits Binary - FT_BINARY64 = 2; // 64-bits Binary - FT_FP16 = 3; // 16-bits Float Number - FT_FP32 = 4; // 32-bits Float Number - FT_FP64 = 5; // 64-bits Float Number - FT_INT8 = 6; // 8-bits Integer - FT_INT16 = 7; // 16-bits Integer - FT_INT4 = 8; // 4-bits Integer -}; - -/*! Types of Index - */ -enum IndexType { - IT_UNDEFINED = 0; // Undefined - IT_PROXIMA_GRAPH_INDEX = 1; // Proxima Graph Index -}; - -enum DataType { - DT_UNDEFINED = 0; - DT_BINARY = 1; - DT_STRING = 2; - DT_BOOL = 3; - DT_INT32 = 4; - DT_INT64 = 5; - DT_UINT32 = 6; - DT_UINT64 = 7; - DT_FLOAT = 8; - DT_DOUBLE = 9; - - DT_VECTOR_BINARY32 = 20; - DT_VECTOR_BINARY64 = 21; - DT_VECTOR_FP16 = 22; - DT_VECTOR_FP32 = 23; - DT_VECTOR_FP64 = 24; - DT_VECTOR_INT4 = 25; - DT_VECTOR_INT8 = 26; - DT_VECTOR_INT16 = 27; -} - -//! Common Response -message CommonResponse { - int32 code = 1; - string reason = 2; -}; - -message Status { - int32 code = 1; - string reason = 2; -} - -//! Common Http Request for admin -message HttpRequest {}; - -//! Common Http Response for admin -message HttpResponse {}; diff --git a/proxima-be-java-sdk/src/main/proto/proxima_be.proto b/proxima-be-java-sdk/src/main/proto/proxima_be.proto deleted file mode 100644 index 0f45385..0000000 --- a/proxima-be-java-sdk/src/main/proto/proxima_be.proto +++ /dev/null @@ -1,302 +0,0 @@ -syntax = "proto3"; -import "common.proto"; -package proxima.be.proto; - -option java_package = "com.alibaba.proxima.be.grpc"; -option java_multiple_files = true; -option java_outer_classname = "ProximaSeProto"; - -// CC options -option cc_generic_services = true; - -// The Go package name, refers to https://developers.google.com/protocol-buffers/docs/reference/go-generated#package -option go_package = "proxima/be/proto"; - -message CollectionConfig { - message IndexColumnParam { - string column_name = 1; - IndexType index_type = 2; - DataType data_type = 3; - uint32 dimension = 4; - repeated KeyValuePair extra_params = 5; //optional - } - - message RepositoryConfig { - enum RepositoryType { - RT_DATABASE = 0; - } - - message Database { - string connection_uri = 1; - string table_name = 2; - string user = 3; - string password = 4; - } - - RepositoryType repository_type = 1; - string repository_name = 2; - oneof entity{ - Database database = 3; - } - } - - string collection_name = 1; - uint64 max_docs_per_segment = 2; - repeated string forward_column_names = 3; - repeated IndexColumnParam index_column_params = 4; - RepositoryConfig repository_config = 5; //optional -} - -message CollectionName { - string collection_name = 1; -} - -message LsnContext { - uint64 lsn = 1; - string context = 2; -} - -message CollectionInfo { - enum CollectionStatus { - CS_INITIALIZED = 0; - CS_SERVING = 1; - CS_DROPPED = 2; - } - - // static collection config - CollectionConfig config = 1; - - // variable collection status - CollectionStatus status = 2; - string uuid = 3; - LsnContext latest_lsn_context = 4; - uint64 magic_number = 5; -} - -message DescribeCollectionResponse { - Status status = 1; - CollectionInfo collection = 2; -}; - -message ListCondition { - string repository_name = 1; // optional -} - -message ListCollectionsResponse { - Status status = 1; - repeated CollectionInfo collections = 2; -}; - -message CollectionStats { - message SegmentStats { - enum SegmentState { - SS_CREATED = 0; - SS_WRITING = 1; - SS_DUMPING = 2; - SS_COMPACTING = 3; - SS_PERSIST = 4; - } - uint32 segment_id = 1; - SegmentState state = 2; - uint64 doc_count = 3; - uint64 index_file_count = 4; - uint64 index_file_size = 5; - uint64 min_doc_id = 6; - uint64 max_doc_id = 7; - uint64 min_primary_key = 8; - uint64 max_primary_key = 9; - uint64 min_timestamp = 10; - uint64 max_timestamp = 11; - uint64 min_lsn = 12; - uint64 max_lsn = 13; - string segment_path = 14; - } - - string collection_name = 1; - string collection_path = 2; - uint64 total_doc_count = 3; - uint64 total_segment_count = 4; - uint64 total_index_file_count = 5; - uint64 total_index_file_size = 6; - repeated SegmentStats segment_stats = 7; -} - -message StatsCollectionResponse { - Status status = 1; - CollectionStats collection_stats = 2; -}; - - -message WriteRequest { - message Row { - uint64 primary_key = 1; - OperationType operation_type = 2; - GenericValueList forward_column_values = 3; - GenericValueList index_column_values = 4; - LsnContext lsn_context = 5; // optional - } - - message IndexColumnMeta { - string column_name = 1; - DataType data_type = 2; - uint32 dimension = 3; - } - - message RowMeta { - repeated string forward_column_names = 1; - repeated IndexColumnMeta index_column_metas = 2; - } - - string collection_name = 1; - RowMeta rowMeta = 2; - repeated Row rows = 3; - string request_id = 4; // optional - uint64 magic_number = 5; // optional -} - -message Document { - uint64 primary_key = 1; - float score = 2; - repeated GenericKeyValue forward_column_values = 3; -}; - -message QueryRequest { - enum QueryType { - QT_KNN = 0; - } - - message KnnQueryParam { - string column_name = 1; - uint32 topk = 2; - oneof features_value { - bytes features = 3; - string matrix = 4; - } - uint32 batch_count = 5; - uint32 dimension = 6; - DataType data_type = 7; - float radius = 8; // optional - bool is_linear = 9; // optional - repeated KeyValuePair extra_params = 10; // optional - } - - string collection_name = 1; - QueryType query_type = 2; - bool debug_mode = 3; - - oneof query_param { - KnnQueryParam knn_param = 4; - }; -} - -message QueryResponse { - message Result{ - repeated Document documents = 1; - }; - - Status status = 1; - string debug_info = 2; - uint64 latency_us = 3; - repeated Result results = 4; -} - -message GetDocumentRequest { - string collection_name = 1; - uint64 primary_key = 2; - bool debug_mode = 3; -} - -message GetDocumentResponse { - Status status = 1; - string debug_info = 2; - Document document = 3; -} - -message GetVersionRequest { -} - -message GetVersionResponse { - Status status = 1; - string version = 2; -} - -//! GRPC service -service ProximaService { - // Create a collection - rpc create_collection(CollectionConfig) returns (Status); - - // Drop a collection - rpc drop_collection(CollectionName) returns (Status); - - // Get information of a collection - rpc describe_collection(CollectionName) returns (DescribeCollectionResponse); - - // Get all collection information - rpc list_collections(ListCondition) returns (ListCollectionsResponse); - - // Get collection statstics - rpc stats_collection(CollectionName) returns (StatsCollectionResponse); - - // Write records - rpc write(WriteRequest) returns (Status); - - // Knn query records - rpc query(QueryRequest) returns (QueryResponse); - - // Get document information by primary key - rpc get_document_by_key(GetDocumentRequest) returns (GetDocumentResponse); - - // Get server version - rpc get_version(GetVersionRequest) returns (GetVersionResponse); -} - -//! Restful APIs of ProximaService for management of proxima be -service HttpProximaService { - //! Collection management APIS - // 1. Create Collection - // Http: POST /v1/collection/{collection} - // You can use the create collection API to add a new collection to an Proxima BE server. When creating an - // index, you need specify the CollectionConfig as json string attached to the body - // 2. Get Collection - // HTTP: GET /{collection} - // Returns information about one collection named by Path Param ${collection}. - // 3. Delete Collection - // HTTP: DEL /{collection} - // Deletes an existing collection named by Path Param ${collection} - // 4. Update Collection - // HTTP: PUT /{collection}, supported later - // - rpc collection(HttpRequest) returns (HttpResponse); - - //! Retrieve Stat of Collection - // HTTP: GET /v1/collection/{collection}/stat - // - rpc stats_collection(HttpRequest) returns (HttpResponse); - - //! Write records to collection - // HTTP: POST /v1/collection/{collection}/index - // - rpc write(HttpRequest) returns (HttpResponse); - - //! Query documents on collection - // HTTP: POST /v1/collection/{collection}/query - // - rpc query(HttpRequest) returns (HttpResponse); - - //! Write records to collection - // HTTP: GET /v1/collection/{collection}/doc?key={primary_key} - // - rpc get_document_by_key(HttpRequest) returns (HttpResponse); - - //! List Collections - // HTTP: GET /v1/collections?repository={repo} - // Returns information about collections. Query param ${repo} specified collection should have been attached - // repository named by ${repo} - // - rpc list_collections(HttpRequest) returns (HttpResponse); - - //! Get server version - // HTTP: GET /version - // Returns version string - rpc get_version(HttpRequest) returns (HttpResponse); -} diff --git a/proxima-be-java-sdk/src/main/resources/log4j2.xml b/proxima-be-java-sdk/src/main/resources/log4j2.xml deleted file mode 100644 index 26727ae..0000000 --- a/proxima-be-java-sdk/src/main/resources/log4j2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/proxima-be-java-sdk/src/main/resources/proxima-be.properties b/proxima-be-java-sdk/src/main/resources/proxima-be.properties deleted file mode 100644 index 951752f..0000000 --- a/proxima-be-java-sdk/src/main/resources/proxima-be.properties +++ /dev/null @@ -1,3 +0,0 @@ -groupId=${project.groupId} -artifactId=${project.artifactId} -version=${project.version}