Selaa lähdekoodia

fix search param offset not avaliable bug (#415)

Signed-off-by: “yelusion” <xun.huang@zilliz.com>
yelusion 2 vuotta sitten
vanhempi
commit
5f4b699438

+ 42 - 21
pom.xml

@@ -70,6 +70,27 @@
         <commons-collections4.version>4.3</commons-collections4.version>
         <commons-collections4.version>4.3</commons-collections4.version>
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
         <maven.compiler.target>1.8</maven.compiler.target>
+        <versio.maven.deploy.plugin>2.8.2</versio.maven.deploy.plugin>
+        <versio.maven.source.plugin>3.2.1</versio.maven.source.plugin>
+        <javax.annotation.version>1.2</javax.annotation.version>
+        <commons.text.version>1.6</commons.text.version>
+        <slf4j.api.version>1.7.30</slf4j.api.version>
+        <log4j.slf4j.version>2.17.1</log4j.slf4j.version>
+        <junit.version>4.13.1</junit.version>
+        <junit.jupiter.version>5.7.0</junit.jupiter.version>
+        <lombok.version>1.18.22</lombok.version>
+        <okhttp.version>3.14.9</okhttp.version>
+        <plexus.version>3.0.20</plexus.version>
+        <maven.source.plugin.version>3.1.0</maven.source.plugin.version>
+        <maven.javadoc.plugin.version>3.1.1</maven.javadoc.plugin.version>
+        <os.maven.plugin.version>1.6.2</os.maven.plugin.version>
+        <maven.release.plugin.version>2.5.3</maven.release.plugin.version>
+        <protobuf.maven.plugin.version>0.6.1</protobuf.maven.plugin.version>
+        <maven.enforcer.plugin.version>3.0.0-M2</maven.enforcer.plugin.version>
+        <maven.surefire.plugin.version>2.19.1</maven.surefire.plugin.version>
+        <junit.platform.version>1.1.0</junit.platform.version>
+        <junit.jupiter.engine.version>5.1.0</junit.jupiter.engine.version>
+        <jackson.version>2.10.1</jackson.version>
     </properties>
     </properties>
 
 
     <dependencyManagement>
     <dependencyManagement>
@@ -104,7 +125,7 @@
         <dependency>
         <dependency>
             <groupId>javax.annotation</groupId>
             <groupId>javax.annotation</groupId>
             <artifactId>javax.annotation-api</artifactId>
             <artifactId>javax.annotation-api</artifactId>
-            <version>1.2</version>
+            <version>${javax.annotation.version}</version>
             <scope>provided</scope> <!-- not needed at runtime -->
             <scope>provided</scope> <!-- not needed at runtime -->
         </dependency>
         </dependency>
         <dependency>
         <dependency>
@@ -120,7 +141,7 @@
         <dependency>
         <dependency>
             <groupId>org.apache.commons</groupId>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-text</artifactId>
             <artifactId>commons-text</artifactId>
-            <version>1.10.0</version>
+            <version>${commons.text.version}</version>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>org.apache.commons</groupId>
             <groupId>org.apache.commons</groupId>
@@ -128,47 +149,47 @@
             <version>${commons-collections4.version}</version>
             <version>${commons-collections4.version}</version>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
-            <groupId>org.json</groupId>
-            <artifactId>json</artifactId>
-            <version>20190722</version>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+            <version>${jackson.version}</version>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <artifactId>slf4j-api</artifactId>
-            <version>1.7.30</version>
+            <version>${slf4j.api.version}</version>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>org.apache.logging.log4j</groupId>
             <groupId>org.apache.logging.log4j</groupId>
             <artifactId>log4j-slf4j-impl</artifactId>
             <artifactId>log4j-slf4j-impl</artifactId>
-            <version>2.17.1</version>
+            <version>${log4j.slf4j.version}</version>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>junit</groupId>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <artifactId>junit</artifactId>
-            <version>4.13.1</version>
+            <version>${junit.version}</version>
             <scope>test</scope>
             <scope>test</scope>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>org.junit.jupiter</groupId>
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter-api</artifactId>
             <artifactId>junit-jupiter-api</artifactId>
-            <version>5.7.0</version>
+            <version>${junit.jupiter.version}</version>
             <scope>test</scope>
             <scope>test</scope>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>org.projectlombok</groupId>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
             <artifactId>lombok</artifactId>
-            <version>1.18.22</version>
+            <version>${lombok.version}</version>
             <scope>provided</scope>
             <scope>provided</scope>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>com.squareup.okhttp3</groupId>
             <groupId>com.squareup.okhttp3</groupId>
             <artifactId>okhttp</artifactId>
             <artifactId>okhttp</artifactId>
-            <version>3.14.9</version>
+            <version>${okhttp.version}</version>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>org.codehaus.plexus</groupId>
             <groupId>org.codehaus.plexus</groupId>
             <artifactId>plexus-utils</artifactId>
             <artifactId>plexus-utils</artifactId>
-            <version>3.0.20</version>
+            <version>${plexus.version}</version>
         </dependency>
         </dependency>
     </dependencies>
     </dependencies>
 
 
@@ -180,7 +201,7 @@
                     <plugin>
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-source-plugin</artifactId>
                         <artifactId>maven-source-plugin</artifactId>
-                        <version>3.1.0</version>
+                        <version>${maven.source.plugin.version}</version>
                         <executions>
                         <executions>
                             <execution>
                             <execution>
                                 <id>attach-sources</id>
                                 <id>attach-sources</id>
@@ -193,7 +214,7 @@
                     <plugin>
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-javadoc-plugin</artifactId>
                         <artifactId>maven-javadoc-plugin</artifactId>
-                        <version>3.1.1</version>
+                        <version>${maven.javadoc.plugin.version}</version>
                         <configuration>
                         <configuration>
                             <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
                             <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
                         </configuration>
                         </configuration>
@@ -236,7 +257,7 @@
             <extension>
             <extension>
                 <groupId>kr.motd.maven</groupId>
                 <groupId>kr.motd.maven</groupId>
                 <artifactId>os-maven-plugin</artifactId>
                 <artifactId>os-maven-plugin</artifactId>
-                <version>1.6.2</version>
+                <version>${os.maven.plugin.version}</version>
             </extension>
             </extension>
         </extensions>
         </extensions>
         <plugins>
         <plugins>
@@ -254,7 +275,7 @@
             <plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-release-plugin</artifactId>
                 <artifactId>maven-release-plugin</artifactId>
-                <version>2.5.3</version>
+                <version>${maven.release.plugin.version}</version>
                 <configuration>
                 <configuration>
                     <autoVersionSubmodules>true</autoVersionSubmodules>
                     <autoVersionSubmodules>true</autoVersionSubmodules>
                     <useReleaseProfile>false</useReleaseProfile>
                     <useReleaseProfile>false</useReleaseProfile>
@@ -265,7 +286,7 @@
             <plugin>
             <plugin>
                 <groupId>org.xolstice.maven.plugins</groupId>
                 <groupId>org.xolstice.maven.plugins</groupId>
                 <artifactId>protobuf-maven-plugin</artifactId>
                 <artifactId>protobuf-maven-plugin</artifactId>
-                <version>0.6.1</version>
+                <version>${protobuf.maven.plugin.version}</version>
                 <configuration>
                 <configuration>
                     <protoSourceRoot>src/main/milvus-proto/proto</protoSourceRoot>
                     <protoSourceRoot>src/main/milvus-proto/proto</protoSourceRoot>
                     <protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
                     <protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
@@ -284,7 +305,7 @@
             <plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-enforcer-plugin</artifactId>
                 <artifactId>maven-enforcer-plugin</artifactId>
-                <version>3.0.0-M2</version>
+                <version>${maven.enforcer.plugin.version}</version>
                 <executions>
                 <executions>
                     <execution>
                     <execution>
                         <id>enforce</id>
                         <id>enforce</id>
@@ -305,7 +326,7 @@
             <plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <artifactId>maven-surefire-plugin</artifactId>
-                <version>2.19.1</version>
+                <version>${maven.surefire.plugin.version}</version>
                 <configuration>
                 <configuration>
                     <skipTests>false</skipTests>
                     <skipTests>false</skipTests>
                 </configuration>
                 </configuration>
@@ -313,12 +334,12 @@
                     <dependency>
                     <dependency>
                         <groupId>org.junit.platform</groupId>
                         <groupId>org.junit.platform</groupId>
                         <artifactId>junit-platform-surefire-provider</artifactId>
                         <artifactId>junit-platform-surefire-provider</artifactId>
-                        <version>1.1.0</version>
+                        <version>${junit.platform.version}</version>
                     </dependency>
                     </dependency>
                     <dependency>
                     <dependency>
                         <groupId>org.junit.jupiter</groupId>
                         <groupId>org.junit.jupiter</groupId>
                         <artifactId>junit-jupiter-engine</artifactId>
                         <artifactId>junit-jupiter-engine</artifactId>
-                        <version>5.1.0</version>
+                        <version>${junit.jupiter.engine.version}</version>
                     </dependency>
                     </dependency>
                 </dependencies>
                 </dependencies>
             </plugin>
             </plugin>

+ 1 - 0
src/main/java/io/milvus/common/constant/MilvusClientConstant.java

@@ -11,4 +11,5 @@ public class MilvusClientConstant {
         public final static String COLON = ":";
         public final static String COLON = ":";
         public final static String DOUBLE_SLASH = "//";
         public final static String DOUBLE_SLASH = "//";
     }
     }
+
 }
 }

+ 64 - 0
src/main/java/io/milvus/common/utils/JacksonUtils.java

@@ -0,0 +1,64 @@
+package io.milvus.common.utils;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class JacksonUtils {
+
+    private static final ObjectMapper objectMapper;
+
+    static {
+        objectMapper = new ObjectMapper();
+        objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+    }
+
+    public static <T> T fromJson(String jsonStr, TypeReference<T> typeRef) {
+        try {
+            return objectMapper.readValue(jsonStr, typeRef);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("json deserialization error, e=", e);
+        }
+    }
+
+    public static <T> T fromJson(String jsonStr, Class<T> type) {
+        try {
+            return objectMapper.readValue(jsonStr, type);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("json deserialization error, e=", e);
+        }
+    }
+
+    public static <T> T fromJson(byte[] bytes, TypeReference<T> typeRef) {
+        try {
+            return objectMapper.readValue(bytes, typeRef);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("json deserialization error, e=", e);
+        }
+    }
+
+    public static <T> T fromJson(byte[] bytes, Class<T> type) {
+        try {
+            return objectMapper.readValue(bytes, type);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("json deserialization error, e=", e);
+        }
+    }
+
+    public static String toJsonString(Object obj) {
+        try {
+            return objectMapper.writeValueAsString(obj);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("json serialization error, e=", e);
+        }
+    }
+
+    public static byte[] toJsonByte(Object obj) {
+        try {
+            return objectMapper.writeValueAsBytes(obj);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("json serialization error, e=", e);
+        }
+    }
+
+}

+ 1 - 0
src/main/java/io/milvus/param/Constant.java

@@ -40,6 +40,7 @@ public class Constant {
     public static final String IMPORT_COLLECTION = "collection";
     public static final String IMPORT_COLLECTION = "collection";
     public static final String IMPORT_PARTITION = "partition";
     public static final String IMPORT_PARTITION = "partition";
     public static final String DEFAULT_INDEX_NAME = "";
     public static final String DEFAULT_INDEX_NAME = "";
+    public final static String OFFSET = "offset";
 
 
     // max value for waiting loading collection/partition interval, unit: millisecond
     // max value for waiting loading collection/partition interval, unit: millisecond
     public static final Long MAX_WAITING_LOADING_INTERVAL = 2000L;
     public static final Long MAX_WAITING_LOADING_INTERVAL = 2000L;

+ 8 - 0
src/main/java/io/milvus/param/ParamUtils.java

@@ -2,6 +2,7 @@ package io.milvus.param;
 
 
 import com.google.protobuf.ByteString;
 import com.google.protobuf.ByteString;
 import io.milvus.common.clientenum.ConsistencyLevelEnum;
 import io.milvus.common.clientenum.ConsistencyLevelEnum;
+import io.milvus.common.utils.JacksonUtils;
 import io.milvus.exception.IllegalResponseException;
 import io.milvus.exception.IllegalResponseException;
 import io.milvus.exception.ParamException;
 import io.milvus.exception.ParamException;
 import io.milvus.grpc.*;
 import io.milvus.grpc.*;
@@ -292,6 +293,13 @@ public class ParamUtils {
                                 .build());
                                 .build());
 
 
         if (null != requestParam.getParams() && !requestParam.getParams().isEmpty()) {
         if (null != requestParam.getParams() && !requestParam.getParams().isEmpty()) {
+            Map<String, Object> paramMap = JacksonUtils.fromJson(requestParam.getParams(),Map.class);
+            String offset = paramMap.getOrDefault(Constant.OFFSET, 0).toString();
+            builder.addSearchParams(
+                    KeyValuePair.newBuilder()
+                            .setKey(Constant.OFFSET)
+                            .setValue(offset)
+                            .build());
             builder.addSearchParams(
             builder.addSearchParams(
                     KeyValuePair.newBuilder()
                     KeyValuePair.newBuilder()
                             .setKey(Constant.PARAMS)
                             .setKey(Constant.PARAMS)