Browse Source

fix the error of float cast to double (#886)

Signed-off-by: lentitude2tk <xushuang.hu@zilliz.com>
xushuang.hu 1 year ago
parent
commit
ae9ba7b83f
1 changed files with 13 additions and 9 deletions
  1. 13 9
      src/main/java/io/milvus/orm/iterator/SearchIterator.java

+ 13 - 9
src/main/java/io/milvus/orm/iterator/SearchIterator.java

@@ -54,7 +54,7 @@ public class SearchIterator {
     private int cacheId;
     private boolean initSuccess;
     private int returnedCount;
-    private double width;
+    private float width;
     private float tailBand;
 
     private List<Object> filteredIds;
@@ -140,8 +140,8 @@ public class SearchIterator {
 
     private void checkRmRangeSearchParameters() {
         if (params.containsKey(RADIUS) && params.containsKey(RANGE_FILTER)) {
-            float radius = (float) params.get(RADIUS);
-            float rangeFilter = (float) params.get(RANGE_FILTER);
+            float radius = getFloatValue(RADIUS);
+            float rangeFilter = getFloatValue(RANGE_FILTER);
             if (metricsPositiveRelated(metricType) && radius <= rangeFilter) {
                 String msg = String.format("for metrics:%s, radius must be larger than range_filter, please adjust your parameter", metricType);
                 ExceptionUtils.throwUnExpectedException(msg);
@@ -298,7 +298,7 @@ public class SearchIterator {
 
         if (width == 0.0) {
             // enable a minimum value for width to avoid radius and range_filter equal error
-            width = 0.05;
+            width = 0.05f;
         }
     }
 
@@ -386,16 +386,16 @@ public class SearchIterator {
         });
 
         if (metricsPositiveRelated(metricType)) {
-            double nextRadius = tailBand + width * coefficient;
-            if (params.containsKey(RADIUS) && nextRadius > (double) params.get(RADIUS)) {
-                nextParams.put(RADIUS, params.get(RADIUS));
+            float nextRadius = tailBand + width * coefficient;
+            if (params.containsKey(RADIUS) && nextRadius > getFloatValue(RADIUS)) {
+                nextParams.put(RADIUS, getFloatValue(RADIUS));
             } else {
                 nextParams.put(RADIUS, nextRadius);
             }
         } else {
             double nextRadius = tailBand - width * coefficient;
-            if (params.containsKey(RADIUS) && nextRadius < (double) params.get(RADIUS)) {
-                nextParams.put(RADIUS, params.get(RADIUS));
+            if (params.containsKey(RADIUS) && nextRadius < getFloatValue(RADIUS)) {
+                nextParams.put(RADIUS, getFloatValue(RADIUS));
             } else {
                 nextParams.put(RADIUS, nextRadius);
             }
@@ -457,4 +457,8 @@ public class SearchIterator {
         DecimalFormat df = new DecimalFormat("0.0");
         return df.format(value);
     }
+
+    private float getFloatValue(String key) {
+        return ((Double) params.get(key)).floatValue();
+    }
 }