1717import apijson .JSONResponse ;
1818import apijson .NotNull ;
1919import apijson .RequestMethod ;
20+ import apijson .StringUtil ;
2021import apijson .orm .AbstractParser ;
2122import apijson .orm .SQLConfig ;
2223import com .alibaba .fastjson .JSONObject ;
2324import io .milvus .client .MilvusServiceClient ;
2425import io .milvus .grpc .MutationResult ;
2526import io .milvus .param .ConnectParam ;
2627import io .milvus .param .R ;
27- import io .milvus .param .credential .UpdateCredentialParam ;
2828import io .milvus .param .dml .DeleteParam ;
2929import io .milvus .param .dml .InsertParam ;
3030import org .datayoo .moql .RecordSet ;
5151public class MilvusUtil {
5252 public static final String TAG = "MilvusUtil" ;
5353
54- public static <T > JSONObject execute (@ NotNull SQLConfig <T > config , boolean unknownType ) throws Exception {
54+ public static <T > JSONObject execute (@ NotNull SQLConfig <T > config , String sql , boolean unknownType ) throws Exception {
5555 if (RequestMethod .isQueryMethod (config .getMethod ())) {
56- List <JSONObject > list = executeQuery (config , unknownType );
56+ List <JSONObject > list = executeQuery (config , sql , unknownType );
5757 JSONObject result = list == null || list .isEmpty () ? null : list .get (0 );
5858 if (result == null ) {
5959 result = new JSONObject (true );
@@ -66,7 +66,7 @@ public static <T> JSONObject execute(@NotNull SQLConfig<T> config, boolean unkno
6666 return result ;
6767 }
6868
69- return executeUpdate (config , null );
69+ return executeUpdate (config , sql );
7070 }
7171
7272 public static <T > int execUpdate (SQLConfig <T > config , String sql ) throws Exception {
@@ -184,7 +184,7 @@ else if (method == RequestMethod.DELETE) {
184184 return result ;
185185 }
186186
187- public static <T > List <JSONObject > executeQuery (@ NotNull SQLConfig <T > config , boolean unknownType ) throws Exception {
187+ public static <T > List <JSONObject > executeQuery (@ NotNull SQLConfig <T > config , String sql , boolean unknownType ) throws Exception {
188188 // 构建Milvus客户端
189189 MilvusServiceClient milvusClient = new MilvusServiceClient (
190190 ConnectParam .newBuilder ().withUri (config .getDBUri ()).build ()
@@ -194,14 +194,13 @@ public static <T> List<JSONObject> executeQuery(@NotNull SQLConfig<T> config, bo
194194 查询语句含义:从book集合中筛选数据,并返回col1,col2两个列。筛选条件为,当数据的col3列值为4,col4列值为'a','b','c'中的任意一
195195 个,且vec向量字段采用'L2'类型匹配,值为'[[1.0, 2.0, 3.0],[1.1,2.1,3.1]]'。另外,采用强一致性级别在10个单元内进行检索,取第11到第15,5条命中记录。
196196 */
197- String sql = config .getSQL (false ); //
198197// String sql = "select id,userId,momentId,content,date from Comment where vMatch(vec, 'L2', '[[1]]') and consistencyLevel('STRONG') limit 1,1";
199198
200199
201200 // 使用Milvus客户端创建Milvus查询器
202201 MilvusQuerier milvusQuerier = new MilvusQuerier (milvusClient );
203202 // 使用查询器执行sql语句,并返回查询结果
204- RecordSet recordSet = milvusQuerier .query (sql );
203+ RecordSet recordSet = milvusQuerier .query (StringUtil . isEmpty ( sql ) ? config . getSQL ( false ) : sql );
205204
206205// int count = recordSet == null ? 0 : recordSet.getRecordsCount();
207206 List <Map <String , Object >> list = recordSet == null ? null : recordSet .getRecordsAsMaps ();
0 commit comments