Browse Source

fix can not query or filter negative int64 value (#400)

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 1 year ago
parent
commit
3c68419020

+ 4 - 4
client/src/components/advancedSearch/utils.ts

@@ -37,10 +37,10 @@ export const formatValue = (value: string, type: string, operator: string) => {
 export const checkValue = (data: any): boolean => {
   let isLegal = false;
 
-  const regInt = /^\d+$/;
-  const regFloat = /^\d+\.\d+$/;
-  const regIntInterval = /^\[\d+(,\d+)*\]$/;
-  const regFloatInterval = /^\[\d+\.\d+(,\d+\.\d+)*\]$/;
+  const regInt = /^-?\d+$/;
+  const regFloat = /^-?\d+\.\d+$/;
+  const regIntInterval = /^\[-?\d+(,-?\d+)*\]$/;
+  const regFloatInterval = /^\[-?\d+\.\d+(,-?\d+\.\d+)*\]$/;
   const isIn = data.operator === 'in';
 
   switch (data.type) {

+ 2 - 1
client/src/consts/default.ts

@@ -1,4 +1,5 @@
 export const DEFAULT_ATTU_MAX_CAPACITY = 64;
 export const DEFAULT_ATTU_VARCHAR_MAX_LENGTH = 32;
 export const DEFAULT_ATTU_ELEMENT_TYPE = 4; // int32
-export const DEFAULT_ATTU_DIM = 128;
+export const DEFAULT_ATTU_DIM = 128;
+export const MIN_INT64 = `-9223372036854775807`; // safe int64 min value

+ 9 - 4
client/src/hooks/Query.ts

@@ -1,5 +1,10 @@
 import { useState, useRef, useEffect } from 'react';
-import { DataTypeStringEnum, DYNAMIC_FIELD, LOAD_STATE } from '@/consts';
+import {
+  DataTypeStringEnum,
+  DYNAMIC_FIELD,
+  LOAD_STATE,
+  MIN_INT64,
+} from '@/consts';
 import { Collection } from '@/http';
 
 export const useQuery = (params: {
@@ -13,7 +18,7 @@ export const useQuery = (params: {
     fields: [],
     primaryKey: { value: '', type: DataTypeStringEnum.Int64 },
     loaded: false,
-    data: null
+    data: null,
   });
   const [consistencyLevel, setConsistencyLevel] = useState<string>('Bounded');
   const [currentPage, setCurrentPage] = useState<number>(0);
@@ -40,7 +45,7 @@ export const useQuery = (params: {
     let condition = '';
     if (!cache) {
       const defaultValue =
-        primaryKey.type === DataTypeStringEnum.VarChar ? "''" : '0';
+        primaryKey.type === DataTypeStringEnum.VarChar ? "''" : `${MIN_INT64}`;
       condition = `${primaryKey.value} > ${defaultValue}`;
     } else {
       const { firstPKId, lastPKId } = cache;
@@ -137,7 +142,7 @@ export const useQuery = (params: {
       fields: nameList as any[],
       primaryKey: { value: primaryKey['name'], type: primaryKey['fieldType'] },
       loaded: collection.state === LOAD_STATE.LoadStateLoaded,
-      data: collection
+      data: collection,
     });
   };
 

+ 8 - 2
server/src/utils/Helper.ts

@@ -23,8 +23,14 @@ export const makeRandomId = (length: number): string =>
     .join('');
 
 export const makeDynamicBool = () => Math.random() > 0.5;
-export const makeRandomInt = (max: number) => Math.floor(Math.random() * max);
-export const makeFloat = () => Math.random();
+export const makeRandomInt = (max: number, allowNegative: boolean = true) => {
+  const value = Math.floor(Math.random() * max);
+  return allowNegative && Math.random() < 0.5 ? -value : value;
+};
+export const makeFloat = (allowNegative: boolean = true) => {
+  const value = Math.random();
+  return allowNegative && Math.random() < 0.5 ? -value : value;
+};
 
 export const genDataByType = (field: FieldSchema): any => {
   const { data_type, type_params, element_type } = field;