mirror of
https://gitee.com/open-visual/face-search.git
synced 2025-06-10 19:19:56 +08:00
update:fix vector engine
This commit is contained in:
parent
4f9b624590
commit
74cad35d80
@ -9,7 +9,6 @@
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>face-search-util</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -1,215 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.milvus</groupId>
|
||||
<artifactId>milvus-java-sdk</artifactId>
|
||||
<version>2.0.0</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<grpc.version>1.36.0</grpc.version>
|
||||
<protobuf.version>3.12.0</protobuf.version>
|
||||
<protoc.version>3.12.0</protoc.version>
|
||||
<commons-collections4.version>4.3</commons-collections4.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-bom</artifactId>
|
||||
<version>${grpc.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-netty-shaded</artifactId>
|
||||
<version>${grpc.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-protobuf</artifactId>
|
||||
<version>${grpc.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-stub</artifactId>
|
||||
<version>${grpc.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
<version>1.2</version>
|
||||
<scope>provided</scope> <!-- not needed at runtime -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-testing</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java-util</artifactId>
|
||||
<version>${protobuf.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>${commons-collections4.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20190722</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.30</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.7.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>kr.motd.maven</groupId>
|
||||
<artifactId>os-maven-plugin</artifactId>
|
||||
<version>1.6.2</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>1.6.8</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<serverId>ossrh</serverId>
|
||||
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
|
||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5.3</version>
|
||||
<configuration>
|
||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
<useReleaseProfile>false</useReleaseProfile>
|
||||
<releaseProfiles>release</releaseProfiles>
|
||||
<goals>deploy</goals>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.xolstice.maven.plugins</groupId>
|
||||
<artifactId>protobuf-maven-plugin</artifactId>
|
||||
<version>0.6.1</version>
|
||||
<configuration>
|
||||
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
|
||||
<pluginId>grpc-java</pluginId>
|
||||
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>compile-custom</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0-M2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce</id>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireUpperBoundDeps/>
|
||||
</rules>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- JUnit5 tests are not running with maven 3.6.x
|
||||
https://dzone.com/articles/why-your-junit-5-tests-are-not-running-under-maven
|
||||
-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
<configuration>
|
||||
<skipTests>false</skipTests>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -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 <code>query/search</code> 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 <code>int</code> 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 <code>long</code> 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<Float> 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<List<Float>>
|
||||
* binary vector field return List<ByteBuffer>
|
||||
* int64 field return List<Long>
|
||||
* boolean field return List<Boolean>
|
||||
*
|
||||
* Throws {@link IllegalResponseException} if the field type is illegal.
|
||||
*
|
||||
* @return <code>List<?></?></code>
|
||||
*/
|
||||
public List<?> getFieldData() throws IllegalResponseException {
|
||||
DataType dt = fieldData.getType();
|
||||
switch (dt) {
|
||||
case FloatVector: {
|
||||
int dim = getDim();
|
||||
System.out.println(fieldData.getVectors().getFloatVector().getDataCount());
|
||||
List<Float> 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<List<Float>> 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<ByteBuffer> 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");
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <code>getCollectionStatistics</code> 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 <code>int</code> dimension of the vector field
|
||||
*/
|
||||
public long GetRowCount() throws NumberFormatException {
|
||||
List<KeyValuePair> stats = stat.getStatsList();
|
||||
for (KeyValuePair kv : stats) {
|
||||
if (kv.getKey().compareTo("row_count") == 0) {
|
||||
return Long.parseLong(kv.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -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 <code>insert</code> interface.
|
||||
*/
|
||||
public class InsertResultWrapper {
|
||||
private final MutationResult result;
|
||||
|
||||
public InsertResultWrapper(@NonNull MutationResult result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get inserted count.
|
||||
*
|
||||
* @return <code>int</code> 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 <code>List<Long></code> id array returned by insert interface
|
||||
*/
|
||||
public List<Long> 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 <code>List<String></code> id array returned by insert interface
|
||||
*/
|
||||
public List<String> 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()");
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <code>query</code> 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 <code>FieldDataWrapper</code>
|
||||
*/
|
||||
public FieldDataWrapper getFieldWrapper(@NonNull String fieldName) throws ParamException {
|
||||
List<FieldData> 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");
|
||||
}
|
||||
}
|
@ -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 <code>search</code> 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 <code>FieldDataWrapper</code>
|
||||
*/
|
||||
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 <code>List<IDScore></code> id-score pairs returned by search interface
|
||||
*/
|
||||
public List<IDScore> GetIDScore(int indexOfTarget) throws ParamException, IllegalResponseException {
|
||||
List<Long> 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> 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 <code>search</code> 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 + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -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<Boolean> hasCollection(HasCollectionParam requestParam);
|
||||
|
||||
/**
|
||||
* Create a collection in Milvus.
|
||||
*
|
||||
* @param requestParam {@link CreateCollectionParam}
|
||||
* @return {status:result code, data:RpcStatus{msg: result message}}
|
||||
*/
|
||||
R<RpcStatus> 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<RpcStatus> dropCollection(DropCollectionParam requestParam);
|
||||
|
||||
/**
|
||||
* Load collection to cache before search/query.
|
||||
*
|
||||
* @param requestParam {@link LoadCollectionParam}
|
||||
* @return {status:result code, data:RpcStatus{msg: result message}}
|
||||
*/
|
||||
R<RpcStatus> 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<RpcStatus> 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<DescribeCollectionResponse> describeCollection(DescribeCollectionParam requestParam);
|
||||
|
||||
/**
|
||||
* Show the statistics information of a collection.
|
||||
*
|
||||
* @param requestParam {@link GetCollectionStatisticsParam}
|
||||
* @return {status:result code, data: GetCollectionStatisticsResponse{status,stats}}
|
||||
*/
|
||||
R<GetCollectionStatisticsResponse> 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<ShowCollectionsResponse> 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<FlushResponse> flush(FlushParam requestParam);
|
||||
|
||||
/**
|
||||
* Create a partition in a collection.
|
||||
*
|
||||
* @param requestParam {@link CreatePartitionParam}
|
||||
* @return {status:result code, data:RpcStatus{msg: result message}}
|
||||
*/
|
||||
R<RpcStatus> 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<RpcStatus> 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<Boolean> hasPartition(HasPartitionParam requestParam);
|
||||
|
||||
/**
|
||||
* Load a partition into cache.
|
||||
*
|
||||
* @param requestParam {@link LoadPartitionsParam}
|
||||
* @return {status:result code, data:RpcStatus{msg: result message}}
|
||||
*/
|
||||
R<RpcStatus> loadPartitions(LoadPartitionsParam requestParam);
|
||||
|
||||
/**
|
||||
* Release a partition from cache.
|
||||
*
|
||||
* @param requestParam {@link ReleasePartitionsParam}
|
||||
* @return {status:result code, data:RpcStatus{msg: result message}}
|
||||
*/
|
||||
R<RpcStatus> releasePartitions(ReleasePartitionsParam requestParam);
|
||||
|
||||
/**
|
||||
* Show the statistics information of a partition.
|
||||
*
|
||||
* @param requestParam {@link GetPartitionStatisticsParam}
|
||||
* @return {status:result code,data:GetPartitionStatisticsResponse{status,stats}}
|
||||
*/
|
||||
R<GetPartitionStatisticsResponse> 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<ShowPartitionsResponse> 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<RpcStatus> createAlias(CreateAliasParam requestParam);
|
||||
|
||||
/**
|
||||
* Drop an alias.
|
||||
*
|
||||
* @param requestParam {@link DropAliasParam}
|
||||
* @return {status:result code, data:RpcStatus{msg: result message}}
|
||||
*/
|
||||
R<RpcStatus> dropAlias(DropAliasParam requestParam);
|
||||
|
||||
/**
|
||||
* Alter alias from a collection to another.
|
||||
*
|
||||
* @param requestParam {@link AlterAliasParam}
|
||||
* @return {status:result code, data:RpcStatus{msg: result message}}
|
||||
*/
|
||||
R<RpcStatus> 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<RpcStatus> createIndex(CreateIndexParam requestParam);
|
||||
|
||||
/**
|
||||
* Drop an index.
|
||||
*
|
||||
* @param requestParam {@link DropIndexParam}
|
||||
* @return {status:result code, data:RpcStatus{msg: result message}}
|
||||
*/
|
||||
R<RpcStatus> 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<DescribeIndexResponse> 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<GetIndexStateResponse> 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<GetIndexBuildProgressResponse> 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<MutationResult> 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<MutationResult> 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<SearchResults> 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<QueryResults> query(QueryParam requestParam);
|
||||
|
||||
/**
|
||||
* Calculate distance between specified vectors.
|
||||
*
|
||||
* @param requestParam {@link CalcDistanceParam}
|
||||
* @return {status:result code, data: CalcDistanceResults{distances}}
|
||||
*/
|
||||
R<CalcDistanceResults> 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<GetMetricsResponse> 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<GetPersistentSegmentInfoResponse> 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<GetQuerySegmentInfoResponse> 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<RpcStatus> loadBalance(LoadBalanceParam requestParam);
|
||||
|
||||
/**
|
||||
* Get compaction action state by id.
|
||||
*
|
||||
* @param requestParam {@link GetCompactionStateParam}
|
||||
* @return {status:result code, data:GetCompactionStateResponse{status,info}}
|
||||
*/
|
||||
R<GetCompactionStateResponse> getCompactionState(GetCompactionStateParam requestParam);
|
||||
|
||||
/**
|
||||
* Ask server to perform a compaction action.
|
||||
*
|
||||
* @param requestParam {@link ManualCompactionParam}
|
||||
* @return {status:result code, data:ManualCompactionResponse{status,info}}
|
||||
*/
|
||||
R<ManualCompactionResponse> manualCompaction(ManualCompactionParam requestParam);
|
||||
|
||||
/**
|
||||
* Get compaction action state with its plan.
|
||||
*
|
||||
* @param requestParam {@link GetCompactionPlansParam}
|
||||
* @return {status:result code, data:GetCompactionPlansResponse{status,info}}
|
||||
*/
|
||||
R<GetCompactionPlansResponse> getCompactionStateWithPlans(GetCompactionPlansParam requestParam);
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
@ -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 <code>search</code>/<code>search</code>/<code>loadCollection</code> 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());
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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 <code>ConnectParam</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withIdleTimeout(long idleTimeout, @NonNull TimeUnit timeUnit) {
|
||||
this.idleTimeoutMs = timeUnit.toMillis(idleTimeout);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>ConnectParam</code> instance.
|
||||
*
|
||||
* @return <code>ShowCollectionsParam</code>
|
||||
*/
|
||||
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 <code>String</code> by <code>ConnectParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConnectParam{" +
|
||||
"host='" + host + '\'' +
|
||||
", port='" + port +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
@ -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 <a href="https://milvus.io/docs/v2.0.0/index_selection.md">Index Types</a>
|
||||
*/
|
||||
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,
|
||||
;
|
||||
}
|
@ -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 <a href="https://milvus.io/docs/v2.0.0/metric.md">Similarity Metrics</a>
|
||||
*/
|
||||
public enum MetricType {
|
||||
INVALID,
|
||||
L2,
|
||||
IP,
|
||||
// Only supported for binary vectors
|
||||
HAMMING,
|
||||
JACCARD,
|
||||
TANIMOTO,
|
||||
SUBSTRUCTURE,
|
||||
SUPERSTRUCTURE,
|
||||
;
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@ -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<T> {
|
||||
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 <code>R</code>
|
||||
*/
|
||||
public static <T> R<T> failed(Exception exception) {
|
||||
R<T> 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 <code>R</code>
|
||||
*/
|
||||
public static <T> R<T> failed(ErrorCode errorCode, String msg) {
|
||||
R<T> 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 <code>R</code>
|
||||
*/
|
||||
public static <T> R<T> failed(Status statusCode, String msg) {
|
||||
R<T> r = new R<>();
|
||||
r.setStatus(statusCode.getCode());
|
||||
r.setException(new Exception(msg));
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Direct return a succeed status.
|
||||
*
|
||||
* @return <code>R</code>
|
||||
*/
|
||||
public static <T> R<T> success() {
|
||||
R<T> r = new R<>();
|
||||
r.setStatus(Status.Success.getCode());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a succeed rpc response object.
|
||||
*
|
||||
* @param data rpc response object
|
||||
* @return <code>R</code>
|
||||
*/
|
||||
public static <T> R<T> success(T data) {
|
||||
R<T> 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<Status> search =
|
||||
Arrays.stream(values()).filter(status -> status.code == val).findFirst();
|
||||
return search.orElse(Unknown);
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>R</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (exception != null) {
|
||||
return "R{" +
|
||||
"exception=" + ExceptionUtils.getMessage(exception) +
|
||||
", status=" + status +
|
||||
", data=" + data +
|
||||
'}';
|
||||
} else {
|
||||
return "R{" +
|
||||
"status=" + status +
|
||||
", data=" + data +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <code>String</code> by <code>RpcStatus</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RpcStatus{" +
|
||||
"msg='" + getMsg() + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>alterAlias</code> 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 <code>AlterAliasParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withAlias(@NonNull String alias) {
|
||||
this.alias = alias;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>AlterAliasParam</code> instance.
|
||||
*
|
||||
* @return <code>AlterAliasParam</code>
|
||||
*/
|
||||
public AlterAliasParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
ParamUtils.CheckNullEmptyString(alias, "Alias");
|
||||
|
||||
return new AlterAliasParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>AlterAliasParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AlterAliasParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", alias='" + alias + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>createAlias</code> 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 <code>CreateAliasParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withAlias(@NonNull String alias) {
|
||||
this.alias = alias;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>CreateAliasParam</code> instance.
|
||||
*
|
||||
* @return <code>CreateAliasParam</code>
|
||||
*/
|
||||
public CreateAliasParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
ParamUtils.CheckNullEmptyString(alias, "Alias");
|
||||
|
||||
return new CreateAliasParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>CreateAliasParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CreateAliasParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", alias='" + alias + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>dropAlias</code> 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 <code>DropAliasParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withAlias(@NonNull String alias) {
|
||||
this.alias = alias;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>DropAliasParam</code> instance.
|
||||
*
|
||||
* @return <code>DropAliasParam</code>
|
||||
*/
|
||||
public DropAliasParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(alias, "Alias");
|
||||
|
||||
return new DropAliasParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>DropAliasParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DropAliasParam{" +
|
||||
", alias='" + alias + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>createCollection</code> interface.
|
||||
*/
|
||||
@Getter
|
||||
public class CreateCollectionParam {
|
||||
private final String collectionName;
|
||||
private final int shardsNum;
|
||||
private final String description;
|
||||
private final List<FieldType> 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 <code>CreateCollectionParam</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private String collectionName;
|
||||
private int shardsNum = 2;
|
||||
private String description = "";
|
||||
private final List<FieldType> fieldTypes = new ArrayList<>();
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set collection name. Collection name cannot be empty or null.
|
||||
*
|
||||
* @param collectionName collection name
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>List</code> of <code>FieldType</code>
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withFieldTypes(@NonNull List<FieldType> fieldTypes) {
|
||||
this.fieldTypes.addAll(fieldTypes);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a field schema.
|
||||
* @see FieldType
|
||||
*
|
||||
* @param fieldType a <code>FieldType</code> object
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder addFieldType(@NonNull FieldType fieldType) {
|
||||
this.fieldTypes.add(fieldType);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>CreateCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>CreateCollectionParam</code>
|
||||
*/
|
||||
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 <code>String</code> by <code>CreateCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CreateCollectionParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", shardsNum=" + shardsNum +
|
||||
", description='" + description + '\'' +
|
||||
", field count=" + fieldTypes.size() +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>describeCollection</code> 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 <code>DescribeCollectionParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionName(@NonNull String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>DescribeCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>DescribeCollectionParam</code>
|
||||
*/
|
||||
public DescribeCollectionParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
|
||||
return new DescribeCollectionParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>DescribeCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DescribeCollectionParam{" +
|
||||
"collectionName='" + collectionName + '\'' + '}';
|
||||
}
|
||||
}
|
@ -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 <code>dropCollection</code> 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 <code>DropCollectionParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionName(@NonNull String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>DropCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>DropCollectionParam</code>
|
||||
*/
|
||||
public DropCollectionParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
|
||||
return new DropCollectionParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>DropCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DropCollectionParam{" +
|
||||
"collectionName='" + collectionName + '\'' + '}';
|
||||
}
|
||||
}
|
@ -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<String,String> 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 <code>FieldType</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private String name;
|
||||
private boolean primaryKey = false;
|
||||
private String description = "";
|
||||
private DataType dataType;
|
||||
private final Map<String,String> 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 <code>Long</code> data type as primary key.
|
||||
*
|
||||
* @param primaryKey true is primary key, false is not
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withDescription(@NonNull String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set data type for field.
|
||||
*
|
||||
* @param dataType data type of the field
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withTypeParams(@NonNull Map<String, String> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withAutoID(boolean autoID) {
|
||||
this.autoID = autoID;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>FieldType</code> instance.
|
||||
*
|
||||
* @return <code>FieldType</code>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <code>flush</code> interface.
|
||||
* Note that the flush interface is not exposed currently.
|
||||
*/
|
||||
@Getter
|
||||
public class FlushParam {
|
||||
private final List<String> 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 <code>FlushParam</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private final List<String> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionNames(@NonNull List<String> collectionNames) {
|
||||
this.collectionNames.addAll(collectionNames);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a collections to be flushed.
|
||||
*
|
||||
* @param collectionName name of the collections
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Boolean.TRUE</code> is sync mode, Bollean.FALSE is not
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withSyncFlushWaitingTimeout(@NonNull Long seconds) {
|
||||
this.syncFlushWaitingTimeout = seconds;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>FlushParam</code> instance.
|
||||
*
|
||||
* @return <code>FlushParam</code>
|
||||
*/
|
||||
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 <code>String</code> by <code>FlushParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FlushParam{" +
|
||||
"collectionNames='" + collectionNames + '\'' +
|
||||
", syncFlush=" + syncFlush.toString() +
|
||||
", syncFlushWaitingInterval=" + syncFlushWaitingInterval +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>getCollectionStatistics</code> 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 <code>GetCollectionStatisticsParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionName(@NonNull String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Require a flush action before retrieving collection statistics.
|
||||
*
|
||||
* @param flush <code>Boolean.TRUE</code> require a flush action
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withFlush(@NonNull Boolean flush) {
|
||||
this.flushCollection = flush;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>GetCollectionStatisticsParam</code> instance.
|
||||
*
|
||||
* @return <code>GetCollectionStatisticsParam</code>
|
||||
*/
|
||||
public GetCollectionStatisticsParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
|
||||
return new GetCollectionStatisticsParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>GetCollectionStatisticsParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetCollectionStatisticsParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
" flush=" + flushCollection +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>hasCollection</code> 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 <code>HasCollectionParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionName(@NonNull String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>HasCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>HasCollectionParam</code>
|
||||
*/
|
||||
public HasCollectionParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
|
||||
return new HasCollectionParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>HasCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HasCollectionParam{" +
|
||||
"collectionName='" + collectionName + '\'' + '}';
|
||||
}
|
||||
}
|
@ -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 <code>loadCollection</code> 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 <code>LoadCollectionParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Boolean.TRUE</code> is sync mode, Boolean.FALSE is not
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withSyncLoadWaitingTimeout(@NonNull Long seconds) {
|
||||
this.syncLoadWaitingTimeout = seconds;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>LoadCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>LoadCollectionParam</code>
|
||||
*/
|
||||
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 <code>String</code> by <code>LoadCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LoadCollectionParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", syncLoad=" + syncLoad +
|
||||
", syncLoadWaitingInterval=" + syncLoadWaitingInterval +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>releaseCollection</code> 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 <code>ReleaseCollectionParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionName(@NonNull String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>ReleaseCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>ReleaseCollectionParam</code>
|
||||
*/
|
||||
public ReleaseCollectionParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
|
||||
return new ReleaseCollectionParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>ReleaseCollectionParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ReleaseCollectionParam{" +
|
||||
"collectionName='" + collectionName + '\'' + '}';
|
||||
}
|
||||
}
|
@ -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 <code>showCollections</code> interface.
|
||||
*/
|
||||
@Getter
|
||||
public class ShowCollectionsParam {
|
||||
private final List<String> 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 <code>ShowCollectionsParam</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private final List<String> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionNames(@NonNull List<String> collectionNames) {
|
||||
collectionNames.forEach(this::addCollectionName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a collection name, name cannot be empty or null.
|
||||
*
|
||||
* @param collectionName collection name
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder addCollectionName(@NonNull String collectionName) {
|
||||
if (!this.collectionNames.contains(collectionName)) {
|
||||
this.collectionNames.add(collectionName);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>ShowCollectionsParam</code> instance.
|
||||
*
|
||||
* @return <code>ShowCollectionsParam</code>
|
||||
*/
|
||||
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 <code>String</code> by <code>ShowCollectionsParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ShowCollectionsParam{" +
|
||||
"collectionNames='" + collectionNames.toString() + '\'' +
|
||||
", showType=" + showType.toString() +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package io.milvus.param.control;
|
||||
|
||||
import io.milvus.exception.ParamException;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
/**
|
||||
* Parameters for <code>getCompactionStateWithPlans</code> interface.
|
||||
*
|
||||
* @see <a href="https://wiki.lfaidata.foundation/display/MIL/MEP+16+--+Compaction">Metric function design</a>
|
||||
*/
|
||||
@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 <code>String</code> by <code>GetCompactionPlansParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetCompactionPlansParam{" +
|
||||
"compactionID='" + compactionID + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for <code>GetCompactionPlansParam</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private Long compactionID;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set compaction action id to get plans.
|
||||
*
|
||||
* @param compactionID compaction action id
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withCompactionID(@NonNull Long compactionID) {
|
||||
this.compactionID = compactionID;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>GetCompactionPlansParam</code> instance.
|
||||
*
|
||||
* @return <code>GetCompactionPlansParam</code>
|
||||
*/
|
||||
public GetCompactionPlansParam build() throws ParamException {
|
||||
return new GetCompactionPlansParam(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package io.milvus.param.control;
|
||||
|
||||
import io.milvus.exception.ParamException;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
|
||||
/**
|
||||
* Parameters for <code>getCompactionState</code> interface.
|
||||
*
|
||||
* @see <a href="https://wiki.lfaidata.foundation/display/MIL/MEP+16+--+Compaction">Metric function design</a>
|
||||
*/
|
||||
@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 <code>String</code> by <code>GetCompactionStateParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetCompactionStateParam{" +
|
||||
"compactionID='" + compactionID + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for <code>GetCompactionStateParam</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private Long compactionID;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set compaction action id to get state.
|
||||
*
|
||||
* @param compactionID compaction action id
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withCompactionID(@NonNull Long compactionID) {
|
||||
this.compactionID = compactionID;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>GetCompactionStateParam</code> instance.
|
||||
*
|
||||
* @return <code>GetCompactionStateParam</code>
|
||||
*/
|
||||
public GetCompactionStateParam build() throws ParamException {
|
||||
return new GetCompactionStateParam(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <code>getMetric</code> 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 <code>GetMetricsParam</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private String request;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request in json format to retrieve metric information from server.
|
||||
* @see <a href="https://wiki.lfaidata.foundation/display/MIL/MEP+8+--+Add+metrics+for+proxy">Metric function design</a>
|
||||
*
|
||||
* @param request request string in json format
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withRequest(@NonNull String request) {
|
||||
this.request = request;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>GetMetricsParam</code> instance.
|
||||
*
|
||||
* @return <code>GetMetricsParam</code>
|
||||
*/
|
||||
public GetMetricsParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(request, "Request string");
|
||||
|
||||
// TODO: check the request string is json format
|
||||
|
||||
return new GetMetricsParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>GetMetricsParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetMetricsParam{" +
|
||||
"request='" + request + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>getPersistentSegmentInfo</code> 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 <code>GetPersistentSegmentInfoParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionName(@NonNull String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>GetPersistentSegmentInfoParam</code> instance.
|
||||
*
|
||||
* @return <code>GetPersistentSegmentInfoParam</code>
|
||||
*/
|
||||
public GetPersistentSegmentInfoParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
|
||||
return new GetPersistentSegmentInfoParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>GetPersistentSegmentInfoParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetPersistentSegmentInfoParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>getQuerySegmentInfo</code> 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 <code>GetPersistentSegmentInfoParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionName(@NonNull String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>GetQuerySegmentInfoParam</code> instance.
|
||||
*
|
||||
* @return <code>GetQuerySegmentInfoParam</code>
|
||||
*/
|
||||
public GetQuerySegmentInfoParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
|
||||
return new GetQuerySegmentInfoParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>GetQuerySegmentInfoParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetQuerySegmentInfoParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>loadBalance</code> interface.
|
||||
*
|
||||
* @see <a href="https://wiki.lfaidata.foundation/display/MIL/MEP+17+--+Support+handoff+and+load+balance+segment+on+query+nodes">Handoff and load balance</a>
|
||||
*/
|
||||
@Getter
|
||||
public class LoadBalanceParam {
|
||||
private final Long srcNodeID;
|
||||
private final List<Long> destNodeIDs;
|
||||
private final List<Long> 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 <code>String</code> by <code>LoadBalanceParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LoadBalanceParam{" +
|
||||
"srcNodeID='" + srcNodeID + '\'' +
|
||||
"destNodeIDs='" + destNodeIDs.toString() + '\'' +
|
||||
"segmentIDs='" + segmentIDs.toString() + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for <code>LoadBalanceParam</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private final List<Long> destNodeIDs = new ArrayList<>();
|
||||
private final List<Long> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withDestinationNodeID(@NonNull List<Long> destNodeIDs) {
|
||||
destNodeIDs.forEach(this::addDestinationNodeID);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a sealed segments id to be balanced.
|
||||
*
|
||||
* @param segmentID sealed segment id
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withSegmentIDs(@NonNull List<Long> segmentIDs) {
|
||||
segmentIDs.forEach(this::addSegmentID);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>LoadBalanceParam</code> instance.
|
||||
*
|
||||
* @return <code>LoadBalanceParam</code>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package io.milvus.param.control;
|
||||
|
||||
import io.milvus.exception.ParamException;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
/**
|
||||
* Parameters for <code>manualCompaction</code> interface.
|
||||
*
|
||||
* @see <a href="https://wiki.lfaidata.foundation/display/MIL/MEP+16+--+Compaction">Metric function design</a>
|
||||
*/
|
||||
@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 <code>String</code> by <code>ManualCompactionParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ManualCompactionParam{" +
|
||||
"collectionID='" + collectionID + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for <code>ManualCompactionParam</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private Long collectionID;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask server to compact a collection.
|
||||
*
|
||||
* @param collectionID target collection id
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionID(@NonNull Long collectionID) {
|
||||
this.collectionID = collectionID;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>ManualCompactionParam</code> instance.
|
||||
*
|
||||
* @return <code>ManualCompactionParam</code>
|
||||
*/
|
||||
public ManualCompactionParam build() throws ParamException {
|
||||
return new ManualCompactionParam(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <code>calcDistance</code> interface.
|
||||
* Note that currently only support float vectors calculation.
|
||||
*/
|
||||
@Getter
|
||||
public class CalcDistanceParam {
|
||||
private final List<List<Float>> vectorsLeft;
|
||||
private final List<List<Float>> 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 <code>CalcDistanceParam</code> class.
|
||||
*/
|
||||
public static class Builder {
|
||||
private List<List<Float>> vectorsLeft;
|
||||
private List<List<Float>> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withVectorsLeft(@NonNull List<List<Float>> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withVectorsRight(@NonNull List<List<Float>> vectors) {
|
||||
this.vectorsRight = vectors;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set metric type of calculation. Note that currently only support L2 and IP.
|
||||
*
|
||||
* @param metricType metric type
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withMetricType(MetricType metricType) {
|
||||
this.metricType = metricType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>CalcDistanceParam</code> instance.
|
||||
*
|
||||
* @return <code>CalcDistanceParam</code>
|
||||
*/
|
||||
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<Float> 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<Float> vector : vectorsRight) {
|
||||
if (vector.size() != count) {
|
||||
throw new ParamException("Right vector's dimension must be equal");
|
||||
}
|
||||
}
|
||||
|
||||
return new CalcDistanceParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>CalcDistanceParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CalcDistanceParam{ left vector count:" + vectorsLeft.size() +
|
||||
" right vector count:" + vectorsRight.size() +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>delete</code> 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 <code>DeleteParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionName(@NonNull String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Set partition name.
|
||||
*
|
||||
* @param partitionName partition name
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withPartitionName(@NonNull String partitionName) {
|
||||
this.partitionName = partitionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set expr to filter out entities to be deleted.
|
||||
* @see <a href="https://milvus.io/docs/v2.0.0/boolean.md">Boolean Expression Rules</a>
|
||||
*
|
||||
* @param expr filtering expression
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withExpr(@NonNull String expr) {
|
||||
this.expr = expr;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>DeleteParam</code> instance.
|
||||
*
|
||||
* @return <code>DeleteParam</code>
|
||||
*/
|
||||
public DeleteParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
ParamUtils.CheckNullEmptyString(expr, "Expression");
|
||||
|
||||
return new DeleteParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>DeleteParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeleteParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", partitionName='" + partitionName + '\'' +
|
||||
", expr='" + expr + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>insert</code> interface.
|
||||
*/
|
||||
@Getter
|
||||
public class InsertParam {
|
||||
private final List<Field> 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 <code>InsertParam</code> class.
|
||||
*/
|
||||
public static class Builder {
|
||||
private String collectionName;
|
||||
private String partitionName = "_default";
|
||||
private List<Field> fields;
|
||||
private int rowCount;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set collection name. Collection name cannot be empty or null.
|
||||
*
|
||||
* @param collectionName collection name
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionName(@NonNull String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Set partition name.
|
||||
*
|
||||
* @param partitionName partition name
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withFields(@NonNull List<Field> fields) {
|
||||
this.fields = fields;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>InsertParam</code> instance.
|
||||
*
|
||||
* @return <code>InsertParam</code>
|
||||
*/
|
||||
@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<Float>");
|
||||
}
|
||||
|
||||
List<?> temp = (List<?>)obj;
|
||||
for (Object v : temp) {
|
||||
if (!(v instanceof Float)) {
|
||||
throw new ParamException("Float vector's value type must be Float");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Float> first = (List<Float>) values.get(0);
|
||||
int dim = first.size();
|
||||
for (int i = 1; i < values.size(); ++i) {
|
||||
List<Float> temp = (List<Float>) 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 <code>String</code> by <code>InsertParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@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<Integer>, List<Long>...
|
||||
* if dataType is FloatVector: values is List<List<Float>>
|
||||
* if dataType is BinaryVector: values is List<ByteBuffer>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <code>query</code> interface.
|
||||
*/
|
||||
@Getter
|
||||
public class QueryParam {
|
||||
private final String collectionName;
|
||||
private final List<String> partitionNames;
|
||||
private final List<String> 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 <code>QueryParam</code> class.
|
||||
*/
|
||||
public static class Builder {
|
||||
private String collectionName;
|
||||
private List<String> partitionNames = Lists.newArrayList();
|
||||
private List<String> outFields = new ArrayList<>();
|
||||
private String expr = "";
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set collection name. Collection name cannot be empty or null.
|
||||
*
|
||||
* @param collectionName collection name
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withPartitionNames(@NonNull List<String> partitionNames) {
|
||||
this.partitionNames = partitionNames;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Specify output fields.
|
||||
*
|
||||
* @param outFields output fields
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withOutFields(@NonNull List<String> outFields) {
|
||||
this.outFields = outFields;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set expression to filter out entities to be queried.
|
||||
* @see <a href="https://milvus.io/docs/v2.0.0/boolean.md">Boolean Expression Rules</a>
|
||||
*
|
||||
* @param expr filtering expression
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withExpr(@NonNull String expr) {
|
||||
this.expr = expr;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>QueryParam</code> instance.
|
||||
*
|
||||
* @return <code>QueryParam</code>
|
||||
*/
|
||||
public QueryParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
ParamUtils.CheckNullEmptyString(expr, "Expression");
|
||||
|
||||
return new QueryParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>QueryParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "QueryParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", partitionNames='" + partitionNames.toString() + '\'' +
|
||||
", expr='" + expr + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>search</code> interface.
|
||||
*/
|
||||
@Getter
|
||||
public class SearchParam {
|
||||
private final String collectionName;
|
||||
private final List<String> partitionNames;
|
||||
private final String metricType;
|
||||
private final String vectorFieldName;
|
||||
private final int topK;
|
||||
private final String expr;
|
||||
private final List<String> 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 <code>SearchParam</code> class.
|
||||
*/
|
||||
public static class Builder {
|
||||
private String collectionName;
|
||||
private List<String> partitionNames = Lists.newArrayList();
|
||||
private MetricType metricType = MetricType.L2;
|
||||
private String vectorFieldName;
|
||||
private Integer topK;
|
||||
private String expr = "";
|
||||
private List<String> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withPartitionNames(@NonNull List<String> partitionNames) {
|
||||
this.partitionNames = partitionNames;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set metric type of ANN searching.
|
||||
*
|
||||
* @param metricType metric type
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withVectorFieldName(@NonNull String vectorFieldName) {
|
||||
this.vectorFieldName = vectorFieldName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set topK value of ANN search.
|
||||
*
|
||||
* @param topK topK value
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withTopK(@NonNull Integer topK) {
|
||||
this.topK = topK;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Set expression to filter out entities before searching.
|
||||
* @see <a href="https://milvus.io/docs/v2.0.0/boolean.md">Boolean Expression Rules</a>
|
||||
*
|
||||
* @param expr filtering expression
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withExpr(@NonNull String expr) {
|
||||
this.expr = expr;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Specify output fields.
|
||||
*
|
||||
* @param outFields output fields
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withOutFields(@NonNull List<String> outFields) {
|
||||
this.outFields = outFields;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set target vectors.
|
||||
*
|
||||
* @param vectors list of target vectors
|
||||
* If vector type is FloatVector: vectors is List<List<Float>>
|
||||
* If vector type is BinaryVector: vectors is List<ByteBuffer>
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <a href="https://milvus.io/docs/v2.0.0/index_selection.md">Index Selection</a>
|
||||
*
|
||||
* @param params extra parameters in json format
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withParams(@NonNull String params) {
|
||||
this.params = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>SearchParam</code> instance.
|
||||
*
|
||||
* @return <code>SearchParam</code>
|
||||
*/
|
||||
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<Float>");
|
||||
}
|
||||
|
||||
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<Float> or ByteBuffer");
|
||||
}
|
||||
|
||||
return new SearchParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>SearchParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>createIndex</code> interface.
|
||||
*/
|
||||
@Getter
|
||||
public class CreateIndexParam {
|
||||
private final String collectionName;
|
||||
private final String fieldName;
|
||||
private final Map<String, String> 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 <code>CreateIndexParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withFieldName(@NonNull String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set index type of the index.
|
||||
*
|
||||
* @param indexType index type
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder withIndexType(@NonNull IndexType indexType) {
|
||||
this.indexType = indexType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set metric type of the index.
|
||||
*
|
||||
* @param metricType metric type
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <a href="https://milvus.io/docs/v2.0.0/index_selection.md">Index Selection</a>
|
||||
*
|
||||
* @param extraParam extra parameters in json format
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Boolean.TRUE</code> is sync mode, Boolean.FALSE is not
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withSyncWaitingTimeout(@NonNull Long seconds) {
|
||||
this.syncWaitingTimeout = seconds;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>CreateIndexParam</code> instance.
|
||||
*
|
||||
* @return <code>CreateIndexParam</code>
|
||||
*/
|
||||
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 <code>String</code> by <code>CreateIndexParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CreateIndexParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", fieldName='" + fieldName + '\'' +
|
||||
", params='" + extraParam.toString() + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>describeIndex</code> 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 <code>DescribeIndexParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withFieldName(@NonNull String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>DescribeIndexParam</code> instance.
|
||||
*
|
||||
* @return <code>DescribeIndexParam</code>
|
||||
*/
|
||||
public DescribeIndexParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
ParamUtils.CheckNullEmptyString(fieldName, "Field name");
|
||||
|
||||
return new DescribeIndexParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>DescribeIndexParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DescribeIndexParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", fieldName='" + fieldName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>dropIndex</code> 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 <code>DropIndexParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withFieldName(@NonNull String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>DropIndexParam</code> instance.
|
||||
*
|
||||
* @return <code>DropIndexParam</code>
|
||||
*/
|
||||
public DropIndexParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
ParamUtils.CheckNullEmptyString(fieldName, "Field name");
|
||||
|
||||
return new DropIndexParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>DropIndexParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DropIndexParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", fieldName='" + fieldName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>getIndexBuildProgress</code> 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 <code>GetIndexBuildProgressParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withCollectionName(@NonNull String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>GetIndexBuildProgressParam</code> instance.
|
||||
*
|
||||
* @return <code>GetIndexBuildProgressParam</code>
|
||||
*/
|
||||
public GetIndexBuildProgressParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
|
||||
return new GetIndexBuildProgressParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>GetIndexBuildProgressParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetIndexBuildProgressParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>getIndexState</code> 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 <code>GetIndexStateParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withFieldName(@NonNull String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>GetIndexStateParam</code> instance.
|
||||
*
|
||||
* @return <code>GetIndexStateParam</code>
|
||||
*/
|
||||
public GetIndexStateParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
ParamUtils.CheckNullEmptyString(fieldName, "Field name");
|
||||
|
||||
return new GetIndexStateParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>GetIndexStateParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetIndexStateParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", fieldName='" + fieldName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>createPartition</code> 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 <code>CreatePartitionParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withPartitionName(@NonNull String partitionName) {
|
||||
this.partitionName = partitionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>CreatePartitionParam</code> instance.
|
||||
*
|
||||
* @return <code>CreatePartitionParam</code>
|
||||
*/
|
||||
public CreatePartitionParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
ParamUtils.CheckNullEmptyString(partitionName, "Partition name");
|
||||
|
||||
return new CreatePartitionParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>CreatePartitionParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CreatePartitionParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", partitionName='" + partitionName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>dropPartition</code> 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 <code>DropPartitionParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withPartitionName(@NonNull String partitionName) {
|
||||
this.partitionName = partitionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>DropPartitionParam</code> instance.
|
||||
*
|
||||
* @return <code>DropPartitionParam</code>
|
||||
*/
|
||||
public DropPartitionParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
ParamUtils.CheckNullEmptyString(partitionName, "Partition name");
|
||||
|
||||
return new DropPartitionParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>DropPartitionParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DropPartitionParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", partitionName='" + partitionName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>getPartitionStatistics</code> 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 <code>GetPartitionStatisticsParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withPartitionName(@NonNull String partitionName) {
|
||||
this.partitionName = partitionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>GetPartitionStatisticsParam</code> instance.
|
||||
*
|
||||
* @return <code>GetPartitionStatisticsParam</code>
|
||||
*/
|
||||
public GetPartitionStatisticsParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
ParamUtils.CheckNullEmptyString(partitionName, "Partition name");
|
||||
|
||||
return new GetPartitionStatisticsParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>GetPartitionStatisticsParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetPartitionStatisticsParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", partitionName='" + partitionName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>hasPartition</code> 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 <code>HasPartitionParam</code> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withPartitionName(@NonNull String partitionName) {
|
||||
this.partitionName = partitionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>HasPartitionParam</code> instance.
|
||||
*
|
||||
* @return <code>HasPartitionParam</code>
|
||||
*/
|
||||
public HasPartitionParam build() throws ParamException {
|
||||
ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
|
||||
ParamUtils.CheckNullEmptyString(partitionName, "Partition name");
|
||||
|
||||
return new HasPartitionParam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>String</code> by <code>HasPartitionParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HasPartitionParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", partitionName='" + partitionName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>loadPartition</code> interface.
|
||||
*/
|
||||
@Getter
|
||||
public class LoadPartitionsParam {
|
||||
private final String collectionName;
|
||||
private final List<String> 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 <code>LoadPartitionsParam</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private String collectionName;
|
||||
private final List<String> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withPartitionNames(@NonNull List<String> partitionNames) {
|
||||
partitionNames.forEach(this::addPartitionName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a partition name. Partition name cannot be empty or null.
|
||||
*
|
||||
* @param partitionName partition name
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Boolean.TRUE</code> is sync mode, Boolean.FALSE is not
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withSyncLoadWaitingTimeout(@NonNull Long seconds) {
|
||||
this.syncLoadWaitingTimeout = seconds;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>LoadPartitionsParam</code> instance.
|
||||
*
|
||||
* @return <code>LoadPartitionsParam</code>
|
||||
*/
|
||||
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 <code>String</code> by <code>LoadPartitionsParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LoadPartitionsParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", partitionName='" + partitionNames.toString() + '\'' +
|
||||
", syncLoad=" + syncLoad +
|
||||
", syncLoadWaitingInterval=" + syncLoadWaitingInterval +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>releasePartition</code> interface.
|
||||
*/
|
||||
@Getter
|
||||
public class ReleasePartitionsParam {
|
||||
private final String collectionName;
|
||||
private final List<String> partitionNames;
|
||||
|
||||
private ReleasePartitionsParam(@NonNull Builder builder) {
|
||||
this.collectionName = builder.collectionName;
|
||||
this.partitionNames = builder.partitionNames;
|
||||
}
|
||||
|
||||
public static Builder newBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for <code>ReleasePartitionsParam</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private String collectionName;
|
||||
private final List<String> partitionNames = new ArrayList<>();
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set collection name. Collection name cannot be empty or null.
|
||||
*
|
||||
* @param collectionName collection name
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withPartitionNames(@NonNull List<String> partitionNames) {
|
||||
partitionNames.forEach(this::addPartitionName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a partition name. Partition name cannot be empty or null.
|
||||
*
|
||||
* @param partitionName partition name
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder addPartitionName(@NonNull String partitionName) {
|
||||
if (!this.partitionNames.contains(partitionName)) {
|
||||
this.partitionNames.add(partitionName);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>ReleasePartitionsParam</code> instance.
|
||||
*
|
||||
* @return <code>ReleasePartitionsParam</code>
|
||||
*/
|
||||
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 <code>String</code> by <code>ReleasePartitionsParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ReleasePartitionsParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", partitionNames='" + partitionNames.toString() + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 <code>showPartition</code> interface.
|
||||
*/
|
||||
@Getter
|
||||
public class ShowPartitionsParam {
|
||||
private final String collectionName;
|
||||
private final List<String> 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 <code>ShowPartitionsParam</code> class.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private String collectionName;
|
||||
private List<String> 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 <code>Builder</code>
|
||||
*/
|
||||
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 <code>Builder</code>
|
||||
*/
|
||||
public Builder withPartitionNames(@NonNull List<String> partitionNames) {
|
||||
partitionNames.forEach(this::addPartitionName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a partition name. Partition name cannot be empty or null.
|
||||
*
|
||||
* @param partitionName partition name
|
||||
* @return <code>Builder</code>
|
||||
*/
|
||||
public Builder addPartitionName(@NonNull String partitionName) {
|
||||
if (!this.partitionNames.contains(partitionName)) {
|
||||
this.partitionNames.add(partitionName);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify parameters and create a new <code>ShowPartitionsParam</code> instance.
|
||||
*
|
||||
* @return <code>ShowPartitionsParam</code>
|
||||
*/
|
||||
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 <code>String</code> by <code>ShowPartitionsParam</code> instance.
|
||||
*
|
||||
* @return <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ShowPartitionsParam{" +
|
||||
"collectionName='" + collectionName + '\'' +
|
||||
", partitionNames='" + partitionNames.toString() + '\'' +
|
||||
", showType=" + showType.toString() +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
@ -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<string, schema.LongArray> 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) {}
|
||||
}
|
@ -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;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%highlight{%d{yyyy-MM-dd HH:mm:ss} %C %M %n%p: %m%n}{STYLE=Logback}"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="INFO">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
@ -1,3 +0,0 @@
|
||||
groupId=${project.groupId}
|
||||
artifactId=${project.artifactId}
|
||||
version=${project.version}
|
1
pom.xml
1
pom.xml
@ -59,7 +59,6 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openpnp</groupId>
|
||||
<artifactId>opencv</artifactId>
|
||||
|
@ -1,127 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.alibaba.proxima</groupId>
|
||||
<artifactId>proxima-be-java-sdk</artifactId>
|
||||
<version>0.2.0</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-netty-shaded</artifactId>
|
||||
<version>1.36.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-stub</artifactId>
|
||||
<version>1.36.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-protobuf</artifactId>
|
||||
<version>1.36.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>21.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>3.14.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.30</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>kr.motd.maven</groupId>
|
||||
<artifactId>os-maven-plugin</artifactId>
|
||||
<version>1.6.2</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.xolstice.maven.plugins</groupId>
|
||||
<artifactId>protobuf-maven-plugin</artifactId>
|
||||
<version>0.6.1</version>
|
||||
<configuration>
|
||||
<protocArtifact>com.google.protobuf:protoc:3.14.0:exe:${os.detected.classifier}</protocArtifact>
|
||||
<pluginId>grpc-java</pluginId>
|
||||
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.36.0:exe:${os.detected.classifier}</pluginArtifact>
|
||||
<clearOutputDirectory>false</clearOutputDirectory>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>compile-custom</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<configuration>
|
||||
<skipSource>true</skipSource>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>*.proto</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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<String> forwardColumnNames;
|
||||
private final List<IndexColumnParam> 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<String> getForwardColumnNames() {
|
||||
return forwardColumnNames;
|
||||
}
|
||||
|
||||
public List<IndexColumnParam> 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<IndexColumnParam> indexColumnParams = new ArrayList<>();
|
||||
|
||||
// Optional parameters
|
||||
private long maxDocsPerSegment = 0;
|
||||
private List<String> 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<IndexColumnParam> 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<String> 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<IndexColumnParam> 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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> 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<SegmentStats> 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> 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<SegmentStats> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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();
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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<String, ForwardValue> 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<String, ForwardValue> 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<String> 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<String, ForwardValue> 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<String, ForwardValue> forwardColumnMap) {
|
||||
this.forwardColumnMap = forwardColumnMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
// Build Document object
|
||||
public Document build() {
|
||||
return new Document(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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;
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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();
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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<String, String> 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<String, String> 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<String, String> 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<String, String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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<CollectionInfo> collections;
|
||||
|
||||
// Constructor
|
||||
|
||||
/**
|
||||
* Constructor with status and collections
|
||||
* @param status status
|
||||
* @param collections collection list
|
||||
*/
|
||||
public ListCollectionsResponse(Status status, List<CollectionInfo> 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();
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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<IndexColumnParam> indexParams = config.getIndexColumnParams();
|
||||
List<com.alibaba.proxima.be.grpc.CollectionConfig.IndexColumnParam> indexParamList = new ArrayList<>();
|
||||
for (IndexColumnParam indexParam : indexParams) {
|
||||
Map<String, String> extraParams = indexParam.getExtraParams();
|
||||
List<KeyValuePair> extraParamList = new ArrayList<>();
|
||||
for (Map.Entry<String, String> 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<CollectionInfo> 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<KeyValuePair> extraParamList = new ArrayList<>();
|
||||
Map<String, String> extraParams = queryParam.getExtraParams();
|
||||
for (Map.Entry<String, String> 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<com.alibaba.proxima.be.grpc.WriteRequest.IndexColumnMeta> indexColumnMetaList = new ArrayList<>();
|
||||
List<WriteRequest.IndexColumnMeta> 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<com.alibaba.proxima.be.grpc.WriteRequest.Row> toPb(List<WriteRequest.Row> rows) {
|
||||
List<com.alibaba.proxima.be.grpc.WriteRequest.Row> 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<QueryResult> fromPb(List<com.alibaba.proxima.be.grpc.QueryResponse.Result> pbResults) {
|
||||
List<QueryResult> 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<String, Document.ForwardValue> 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<com.alibaba.proxima.be.grpc.CollectionConfig.IndexColumnParam> columnParams =
|
||||
config.getIndexColumnParamsList();
|
||||
List<IndexColumnParam> 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<String, String> 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());
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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<IndexColumnParam> 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<WriteRequest.Row> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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);
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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<String>() {
|
||||
@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);
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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<String, String> 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<String, String> 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<String, String> 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<String, String> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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<QueryResult> queryResults;
|
||||
|
||||
public QueryResponse(Status status, long latencyMs,
|
||||
String debugInfo, List<QueryResult> 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<QueryResult> 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();
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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<Document> documents;
|
||||
|
||||
private QueryResult(Builder builder) {
|
||||
this.documents = builder.documents;
|
||||
}
|
||||
|
||||
public List<Document> 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<Document> documents = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Empty constructor
|
||||
*/
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set document list
|
||||
* @param documents document list
|
||||
* @return Builder
|
||||
*/
|
||||
public Builder withDocuments(List<Document> 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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();
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
||||
* <p>
|
||||
* \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<Row> 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<Row> 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<Row> 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<Row> 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<String> 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<IndexColumnMeta> 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<IndexColumnMeta> indexColumnMetas;
|
||||
private final List<String> forwardColumnNames;
|
||||
|
||||
private RowMeta(Builder builder) {
|
||||
this.indexColumnMetas = builder.indexColumnMetas;
|
||||
this.forwardColumnNames = builder.forwardColumnNames;
|
||||
}
|
||||
|
||||
public List<IndexColumnMeta> getIndexColumnMetas() {
|
||||
return indexColumnMetas;
|
||||
}
|
||||
|
||||
public List<String> 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<IndexColumnMeta> indexColumnMetas = new ArrayList<>();
|
||||
|
||||
// optional parameters
|
||||
private List<String> forwardColumnNames = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Empty constructor
|
||||
*/
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set index column meta list
|
||||
* @param indexColumnMetas index column meta list
|
||||
* @return Builder
|
||||
*/
|
||||
public Builder withIndexColumnMetas(List<IndexColumnMeta> indexColumnMetas) {
|
||||
this.indexColumnMetas = indexColumnMetas;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set forward column name list
|
||||
* @param forwardColumnNames forward column name list
|
||||
* @return Builder
|
||||
*/
|
||||
public Builder withForwardColumnNames(List<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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 {};
|
@ -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);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level [%l] - %msg%n" />
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="INFO">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
@ -1,3 +0,0 @@
|
||||
groupId=${project.groupId}
|
||||
artifactId=${project.artifactId}
|
||||
version=${project.version}
|
Loading…
x
Reference in New Issue
Block a user