Skip to content

Commit 106a470

Browse files
committed
新增支持 SQLAuto-智能零代码自动化测试 SQL 的数据库工具
https://github.com/TommyLemon/SQLAuto
1 parent dad1862 commit 106a470

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/main/java/apijson/milvus/MilvusUtil.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
import apijson.JSONResponse;
1818
import apijson.NotNull;
1919
import apijson.RequestMethod;
20+
import apijson.StringUtil;
2021
import apijson.orm.AbstractParser;
2122
import apijson.orm.SQLConfig;
2223
import com.alibaba.fastjson.JSONObject;
2324
import io.milvus.client.MilvusServiceClient;
2425
import io.milvus.grpc.MutationResult;
2526
import io.milvus.param.ConnectParam;
2627
import io.milvus.param.R;
27-
import io.milvus.param.credential.UpdateCredentialParam;
2828
import io.milvus.param.dml.DeleteParam;
2929
import io.milvus.param.dml.InsertParam;
3030
import org.datayoo.moql.RecordSet;
@@ -51,9 +51,9 @@
5151
public 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

Comments
 (0)