@@ -137,7 +137,6 @@ func (d *exptTurnResultFilterDAOImpl) buildQueryConditions(ctx context.Context,
137137
138138 d .buildMainTableConditions (cond , & whereSQL , & args )
139139 d .buildMapFieldConditions (cond , & whereSQL , & args )
140- d .buildItemSnapshotConditions (cond , & joinSQL , & args )
141140 d .buildKeywordSearchConditions (ctx , cond , & keywordCond , & args )
142141
143142 return joinSQL , whereSQL , keywordCond , args
@@ -226,19 +225,19 @@ func (d *exptTurnResultFilterDAOImpl) buildMapFieldConditions(cond *ExptTurnResu
226225 switch f .Op {
227226 case "=" :
228227 // 删除 mapContains 条件
229- * whereSQL += fmt .Sprintf (" AND etrf.eval_target_data{ '%s'} = ?" , f .Key )
228+ * whereSQL += fmt .Sprintf (" AND etrf.eval_target_data[ '%s'] = ?" , f .Key )
230229 * args = append (* args , f .Values [0 ])
231230 case "LIKE" :
232231 // 删除 mapContains 条件
233- * whereSQL += fmt .Sprintf (" AND etrf.eval_target_data{ '%s'} LIKE ?" , f .Key )
232+ * whereSQL += fmt .Sprintf (" AND etrf.eval_target_data[ '%s'] LIKE ?" , f .Key )
234233 * args = append (* args , "%" + escapeSpecialChars (fmt .Sprintf ("%v" , f .Values [0 ]))+ "%" )
235234 case "NOT LIKE" :
236235 // 删除 mapContains 条件
237- * whereSQL += fmt .Sprintf (" AND etrf.eval_target_data{ '%s'} NOT LIKE ?" , f .Key )
236+ * whereSQL += fmt .Sprintf (" AND etrf.eval_target_data[ '%s'] NOT LIKE ?" , f .Key )
238237 * args = append (* args , "%" + escapeSpecialChars (fmt .Sprintf ("%v" , f .Values [0 ]))+ "%" )
239238 case "!=" :
240239 // 删除 mapContains 条件
241- * whereSQL += fmt .Sprintf (" AND etrf.eval_target_data{ '%s'} !=?" , f .Key )
240+ * whereSQL += fmt .Sprintf (" AND etrf.eval_target_data[ '%s'] !=?" , f .Key )
242241 * args = append (* args , f .Values [0 ])
243242 }
244243 }
@@ -251,7 +250,7 @@ func (d *exptTurnResultFilterDAOImpl) buildMapFieldConditions(cond *ExptTurnResu
251250 continue
252251 }
253252 // 删除 mapContains 条件
254- * whereSQL += fmt .Sprintf (" AND abs(etrf.evaluator_score{ '%s'} - ?) < %g" , f .Key , floatEpsilon )
253+ * whereSQL += fmt .Sprintf (" AND abs(etrf.evaluator_score[ '%s'] - ?) < %g" , f .Key , floatEpsilon )
255254 * args = append (* args , floatValue )
256255 case ">" , ">=" , "<" , "<=" , "!=" :
257256 floatValue , err := strconv .ParseFloat (fmt .Sprintf ("%v" , f .Values [0 ]), 64 )
@@ -260,7 +259,7 @@ func (d *exptTurnResultFilterDAOImpl) buildMapFieldConditions(cond *ExptTurnResu
260259 continue
261260 }
262261 // 删除 mapContains 条件
263- * whereSQL += fmt .Sprintf (" AND etrf.evaluator_score{ '%s'} %s ?" , f .Key , f .Op )
262+ * whereSQL += fmt .Sprintf (" AND etrf.evaluator_score[ '%s'] %s ?" , f .Key , f .Op )
264263 * args = append (* args , floatValue )
265264 case "BETWEEN" :
266265 floatValue1 , err1 := strconv .ParseFloat (fmt .Sprintf ("%v" , f .Values [0 ]), 64 )
@@ -270,7 +269,7 @@ func (d *exptTurnResultFilterDAOImpl) buildMapFieldConditions(cond *ExptTurnResu
270269 continue
271270 }
272271 // 删除 mapContains 条件
273- * whereSQL += fmt .Sprintf (" AND etrf.evaluator_score{ '%s'} BETWEEN ? AND ?" , f .Key )
272+ * whereSQL += fmt .Sprintf (" AND etrf.evaluator_score[ '%s'] BETWEEN ? AND ?" , f .Key )
274273 * args = append (* args , floatValue1 , floatValue2 )
275274 }
276275 }
@@ -283,7 +282,7 @@ func (d *exptTurnResultFilterDAOImpl) buildMapFieldConditions(cond *ExptTurnResu
283282 continue
284283 }
285284 // 删除 mapContains 条件
286- * whereSQL += fmt .Sprintf (" AND abs(etrf.annotation_float{ '%s'} - ?) < %g" , f .Key , floatEpsilon )
285+ * whereSQL += fmt .Sprintf (" AND abs(etrf.annotation_float[ '%s'] - ?) < %g" , f .Key , floatEpsilon )
287286 * args = append (* args , floatValue )
288287 case ">" , ">=" , "<" , "<=" , "!=" :
289288 floatValue , err := strconv .ParseFloat (fmt .Sprintf ("%v" , f .Values [0 ]), 64 )
@@ -292,7 +291,7 @@ func (d *exptTurnResultFilterDAOImpl) buildMapFieldConditions(cond *ExptTurnResu
292291 continue
293292 }
294293 // 删除 mapContains 条件
295- * whereSQL += fmt .Sprintf (" AND etrf.annotation_float{ '%s'} %s ?" , f .Key , f .Op )
294+ * whereSQL += fmt .Sprintf (" AND etrf.annotation_float[ '%s'] %s ?" , f .Key , f .Op )
296295 * args = append (* args , floatValue )
297296 case "BETWEEN" :
298297 floatValue1 , err1 := strconv .ParseFloat (fmt .Sprintf ("%v" , f .Values [0 ]), 64 )
@@ -302,7 +301,7 @@ func (d *exptTurnResultFilterDAOImpl) buildMapFieldConditions(cond *ExptTurnResu
302301 continue
303302 }
304303 // 删除 mapContains 条件
305- * whereSQL += fmt .Sprintf (" AND etrf.annotation_float{ '%s'} BETWEEN ? AND ?" , f .Key )
304+ * whereSQL += fmt .Sprintf (" AND etrf.annotation_float[ '%s'] BETWEEN ? AND ?" , f .Key )
306305 * args = append (* args , floatValue1 , floatValue2 )
307306 }
308307 }
@@ -311,141 +310,34 @@ func (d *exptTurnResultFilterDAOImpl) buildMapFieldConditions(cond *ExptTurnResu
311310 switch f .Op {
312311 case "=" :
313312 // 删除 mapContains 条件
314- * whereSQL += fmt .Sprintf (" AND etrf.annotation_string{ '%s'} = ?" , f .Key )
313+ * whereSQL += fmt .Sprintf (" AND etrf.annotation_string[ '%s'] = ?" , f .Key )
315314 * args = append (* args , f .Values [0 ])
316315 case "LIKE" :
317316 // 删除 mapContains 条件
318- * whereSQL += fmt .Sprintf (" AND etrf.annotation_string{ '%s'} LIKE ?" , f .Key )
317+ * whereSQL += fmt .Sprintf (" AND etrf.annotation_string[ '%s'] LIKE ?" , f .Key )
319318 * args = append (* args , "%" + escapeSpecialChars (fmt .Sprintf ("%v" , f .Values [0 ]))+ "%" )
320319 case "NOT LIKE" :
321320 // 删除 mapContains 条件
322- * whereSQL += fmt .Sprintf (" AND etrf.annotation_string{ '%s'} NOT LIKE ?" , f .Key )
321+ * whereSQL += fmt .Sprintf (" AND etrf.annotation_string[ '%s'] NOT LIKE ?" , f .Key )
323322 * args = append (* args , "%" + escapeSpecialChars (fmt .Sprintf ("%v" , f .Values [0 ]))+ "%" )
324323 case "!=" :
325324 // 删除 mapContains 条件
326- * whereSQL += fmt .Sprintf (" AND etrf.annotation_string{ '%s'} !=?" , f .Key )
325+ * whereSQL += fmt .Sprintf (" AND etrf.annotation_string[ '%s'] !=?" , f .Key )
327326 * args = append (* args , f .Values [0 ])
328327
329328 // tag_value_id
330329 case "in" , "IN" :
331330 //*whereSQL += " AND etrf.annotation_string IN ?"
332- * whereSQL += fmt .Sprintf (" AND etrf.annotation_string{ '%s'} IN ?" , f .Key )
331+ * whereSQL += fmt .Sprintf (" AND etrf.annotation_string[ '%s'] IN ?" , f .Key )
333332 * args = append (* args , f .Values )
334333 case "NOT IN" :
335334 //*whereSQL += " AND etrf.annotation_string NOT IN?"
336- * whereSQL += fmt .Sprintf (" AND etrf.annotation_string{ '%s'} NOT IN ?" , f .Key )
335+ * whereSQL += fmt .Sprintf (" AND etrf.annotation_string[ '%s'] NOT IN ?" , f .Key )
337336 * args = append (* args , f .Values )
338337 }
339338 }
340339}
341340
342- // buildItemSnapshotConditions 构建联表条件
343- func (d * exptTurnResultFilterDAOImpl ) buildItemSnapshotConditions (cond * ExptTurnResultFilterQueryCond , joinSQL * string , args * []interface {}) {
344- if cond .ItemSnapshotCond == nil {
345- return
346- }
347- for _ , f := range cond .ItemSnapshotCond .FloatMapFilters {
348- switch f .Op {
349- case "=" :
350- floatValue , err := strconv .ParseFloat (fmt .Sprintf ("%v" , f .Values [0 ]), 64 )
351- if err != nil {
352- logs .CtxError (context .Background (), "Parse float value failed: %v" , err )
353- continue
354- }
355- // 删除 mapContains 条件
356- * joinSQL += fmt .Sprintf (" AND abs(dis.float_map{'%s'} - ?) < %g" , f .Key , floatEpsilon )
357- * args = append (* args , floatValue )
358- case ">" , ">=" , "<" , "<=" , "!=" :
359- floatValue , err := strconv .ParseFloat (fmt .Sprintf ("%v" , f .Values [0 ]), 64 )
360- if err != nil {
361- logs .CtxError (context .Background (), "Parse float value failed: %v" , err )
362- continue
363- }
364- // 删除 mapContains 条件
365- * joinSQL += fmt .Sprintf (" AND dis.float_map{'%s'} %s ?" , f .Key , f .Op )
366- * args = append (* args , floatValue )
367- case "BETWEEN" :
368- floatValue1 , err1 := strconv .ParseFloat (fmt .Sprintf ("%v" , f .Values [0 ]), 64 )
369- floatValue2 , err2 := strconv .ParseFloat (fmt .Sprintf ("%v" , f .Values [1 ]), 64 )
370- if err1 != nil || err2 != nil {
371- logs .CtxError (context .Background (), "Parse float value failed: %v, %v" , err1 , err2 )
372- continue
373- }
374- // 删除 mapContains 条件
375- * joinSQL += fmt .Sprintf (" AND dis.float_map{'%s'} BETWEEN ? AND ?" , f .Key )
376- * args = append (* args , floatValue1 , floatValue2 )
377- }
378- }
379- // int_map
380- for _ , f := range cond .ItemSnapshotCond .IntMapFilters {
381- switch f .Op {
382- case "=" , ">" , ">=" , "<" , "<=" , "!=" :
383- // 删除 mapContains 条件
384- * joinSQL += fmt .Sprintf (" AND dis.int_map{'%s'} %s ?" , f .Key , f .Op )
385- * args = append (* args , f .Values [0 ])
386- case "BETWEEN" :
387- // 删除 mapContains 条件
388- * joinSQL += fmt .Sprintf (" AND dis.int_map{'%s'} BETWEEN ? AND ?" , f .Key )
389- * args = append (* args , f .Values [0 ], f .Values [1 ])
390- }
391- }
392- // 处理 BoolMapFilters
393- for _ , f := range cond .ItemSnapshotCond .BoolMapFilters {
394- switch f .Op {
395- case "=" :
396- boolValue , err := strconv .ParseBool (fmt .Sprintf ("%v" , f .Values [0 ]))
397- if err != nil {
398- logs .CtxError (context .Background (), "Parse bool value failed: %v" , err )
399- continue
400- }
401- intBoolValue := 0
402- if boolValue {
403- intBoolValue = 1
404- }
405- // 删除 mapContains 条件
406- * joinSQL += fmt .Sprintf (" AND dis.bool_map{'%s'} = ?" , f .Key )
407- * args = append (* args , intBoolValue )
408- case "!=" :
409- boolValue , err := strconv .ParseBool (fmt .Sprintf ("%v" , f .Values [0 ]))
410- if err != nil {
411- logs .CtxError (context .Background (), "Parse bool value failed: %v" , err )
412- continue
413- }
414- intBoolValue := 0
415- if boolValue {
416- intBoolValue = 1
417- }
418- // 删除 mapContains 条件
419- * joinSQL += fmt .Sprintf (" AND dis.bool_map{'%s'} != ?" , f .Key )
420- * args = append (* args , intBoolValue )
421- default :
422- logs .CtxWarn (context .Background (), "Unsupported operator %s for BoolMapFilters" , f .Op )
423- }
424- }
425-
426- // string_map
427- for _ , f := range cond .ItemSnapshotCond .StringMapFilters {
428- switch f .Op {
429- case "LIKE" :
430- // 删除 mapContains 条件
431- * joinSQL += fmt .Sprintf (" AND dis.string_map{'%s'} LIKE ?" , f .Key )
432- * args = append (* args , "%" + escapeSpecialChars (fmt .Sprintf ("%v" , f .Values [0 ]))+ "%" )
433- case "=" :
434- // 删除 mapContains 条件
435- * joinSQL += fmt .Sprintf (" AND dis.string_map{'%s'} = ?" , f .Key )
436- * args = append (* args , f .Values [0 ])
437- case "NOT LIKE" :
438- // 删除 mapContains 条件
439- * joinSQL += fmt .Sprintf (" AND dis.string_map{'%s'} NOT LIKE ?" , f .Key )
440- * args = append (* args , "%" + escapeSpecialChars (fmt .Sprintf ("%v" , f .Values [0 ]))+ "%" )
441- case "!=" :
442- // 删除 mapContains 条件
443- * joinSQL += fmt .Sprintf (" AND dis.string_map{'%s'}!=?" , f .Key )
444- * args = append (* args , f .Values [0 ])
445- }
446- }
447- }
448-
449341// buildKeywordSearchConditions 构建全文搜索条件
450342func (d * exptTurnResultFilterDAOImpl ) buildKeywordSearchConditions (ctx context.Context , cond * ExptTurnResultFilterQueryCond , keywordCond * string , args * []interface {}) {
451343 if cond .KeywordSearch == nil || cond .KeywordSearch .Keyword == nil {
@@ -463,74 +355,18 @@ func (d *exptTurnResultFilterDAOImpl) buildKeywordSearchConditions(ctx context.C
463355 for _ , f := range cond .KeywordSearch .EvalTargetDataFilters {
464356 * keywordCond += " OR "
465357 // 删除 mapContains 条件
466- * keywordCond += fmt .Sprintf ("etrf.eval_target_data{ '%s'} LIKE ?" , f .Key )
358+ * keywordCond += fmt .Sprintf ("etrf.eval_target_data[ '%s'] LIKE ?" , f .Key )
467359 * args = append (* args , "%" + escapeSpecialChars (kw )+ "%" )
468360 }
469361 }
470362
471- // 处理 ItemSnapshotFilter
472- if cond .KeywordSearch .ItemSnapshotFilter != nil {
473- // float_map
474- for _ , f := range cond .KeywordSearch .ItemSnapshotFilter .FloatMapFilters {
475- floatValue , err := strconv .ParseFloat (kw , 64 )
476- if err != nil {
477- logs .CtxInfo (ctx , "Parse float value failed in keyword search: %v" , err )
478- continue
479- }
480- // 删除 mapContains 条件
481- * keywordCond += " OR "
482- * keywordCond += fmt .Sprintf ("abs(dis.float_map{'%s'} - ?) < %g" , f .Key , floatEpsilon )
483- * args = append (* args , floatValue )
484- }
485- // int_map
486- for _ , f := range cond .KeywordSearch .ItemSnapshotFilter .IntMapFilters {
487- intValue , err := strconv .ParseInt (kw , 10 , 64 )
488- if err != nil {
489- logs .CtxInfo (ctx , "Parse int value failed in keyword search: %v" , err )
490- continue
491- }
492- // 删除 mapContains 条件
493- * keywordCond += " OR "
494- * keywordCond += fmt .Sprintf ("dis.int_map{'%s'} = ?" , f .Key )
495- * args = append (* args , intValue )
496- }
497- // string_map
498- for _ , f := range cond .KeywordSearch .ItemSnapshotFilter .StringMapFilters {
499- * keywordCond += " OR "
500- // 删除 mapContains 条件
501- * keywordCond += fmt .Sprintf ("dis.string_map{'%s'} LIKE ?" , f .Key )
502- * args = append (* args , "%" + escapeSpecialChars (kw )+ "%" )
503- }
504- // bool_map
505- boolVal := 0
506- switch kw {
507- case "true" :
508- boolVal = 1
509- case "false" :
510- boolVal = 0
511- }
512- if kw == "true" || kw == "false" {
513- for _ , f := range cond .KeywordSearch .ItemSnapshotFilter .BoolMapFilters {
514- * keywordCond += " OR "
515- // 删除 mapContains 条件
516- * keywordCond += fmt .Sprintf ("dis.bool_map{'%s'} = %d" , f .Key , boolVal )
517- }
518- }
519- }
520-
521363 * keywordCond += ")"
522364}
523365
524366// buildBaseSQL 构建基础SQL语句
525367func (d * exptTurnResultFilterDAOImpl ) buildBaseSQL (ctx context.Context , joinSQL , whereSQL , keywordCond , evalSetSyncCkDate string , args * []interface {}) string {
526- tableName := d .configer .GetCKDBName (ctx ).ExptTurnResultFilterDBName
527- sql := "SELECT etrf.item_id, etrf.status FROM " + d .configer .GetCKDBName (ctx ).ExptTurnResultFilterDBName + "." + tableName + " etrf"
528- if joinSQL != "" || keywordCond != "" {
529- sql += " INNER JOIN " + d .configer .GetCKDBName (ctx ).DatasetItemsSnapshotDBName + ".dataset_item_snapshot dis ON etrf.eval_set_version_id = dis.version_id AND etrf.item_id = dis.item_id"
530- }
531-
368+ sql := "SELECT etrf.item_id, etrf.status FROM " + d .configer .GetCKDBName (ctx ).ExptTurnResultFilterDBName + ".expt_turn_result_filter etrf"
532369 sql += " WHERE 1=1"
533-
534370 if joinSQL != "" || keywordCond != "" {
535371 sql += " And dis.sync_ck_date = ?"
536372 // 将 evalSetSyncCkDate 插入到 args 切片的第一个位置
@@ -652,7 +488,6 @@ func (d *exptTurnResultFilterDAOImpl) GetByExptIDItemIDs(ctx context.Context, sp
652488}
653489
654490func (d * exptTurnResultFilterDAOImpl ) buildGetByExptIDItemIDsSQL (ctx context.Context , spaceID , exptID , createdDate string , itemIDs []string ) (string , []interface {}) {
655- tableName := d .configer .GetCKDBName (ctx ).ExptTurnResultFilterDBName
656491 sql := "SELECT " +
657492 "etrf.space_id, " +
658493 "etrf.expt_id, " +
@@ -662,19 +497,19 @@ func (d *exptTurnResultFilterDAOImpl) buildGetByExptIDItemIDsSQL(ctx context.Con
662497 "etrf.status, " +
663498 "etrf.eval_set_version_id, " +
664499 "etrf.created_date, " +
665- "etrf.eval_target_data{ 'actual_output'} as actual_output, " +
666- "etrf.evaluator_score{ 'key1'} as evaluator_score_key_1, " +
667- "etrf.evaluator_score{ 'key2'} as evaluator_score_key_2, " +
668- "etrf.evaluator_score{ 'key3'} as evaluator_score_key_3, " +
669- "etrf.evaluator_score{ 'key4'} as evaluator_score_key_4, " +
670- "etrf.evaluator_score{ 'key5'} as evaluator_score_key_5, " +
671- "etrf.evaluator_score{ 'key6'} as evaluator_score_key_6, " +
672- "etrf.evaluator_score{ 'key7'} as evaluator_score_key_7, " +
673- "etrf.evaluator_score{ 'key8'} as evaluator_score_key_8, " +
674- "etrf.evaluator_score{ 'key9'} as evaluator_score_key_9, " +
675- "etrf.evaluator_score{ 'key10'} as evaluator_score_key_10, " +
500+ "etrf.eval_target_data[ 'actual_output'] as actual_output, " +
501+ "etrf.evaluator_score[ 'key1'] as evaluator_score_key_1, " +
502+ "etrf.evaluator_score[ 'key2'] as evaluator_score_key_2, " +
503+ "etrf.evaluator_score[ 'key3'] as evaluator_score_key_3, " +
504+ "etrf.evaluator_score[ 'key4'] as evaluator_score_key_4, " +
505+ "etrf.evaluator_score[ 'key5'] as evaluator_score_key_5, " +
506+ "etrf.evaluator_score[ 'key6'] as evaluator_score_key_6, " +
507+ "etrf.evaluator_score[ 'key7'] as evaluator_score_key_7, " +
508+ "etrf.evaluator_score[ 'key8'] as evaluator_score_key_8, " +
509+ "etrf.evaluator_score[ 'key9'] as evaluator_score_key_9, " +
510+ "etrf.evaluator_score[ 'key10'] as evaluator_score_key_10, " +
676511 "etrf.evaluator_score_corrected " +
677- "FROM " + d .configer .GetCKDBName (ctx ).ExptTurnResultFilterDBName + "." + tableName + " etrf " +
512+ "FROM " + d .configer .GetCKDBName (ctx ).ExptTurnResultFilterDBName + ".expt_turn_result_filter" + " etrf " +
678513 "WHERE etrf.space_id = ? AND etrf.expt_id = ? AND etrf.created_date =?"
679514 if len (itemIDs ) > 0 {
680515 sql += " AND etrf.item_id IN (?)"
@@ -683,4 +518,4 @@ func (d *exptTurnResultFilterDAOImpl) buildGetByExptIDItemIDsSQL(ctx context.Con
683518 args := []interface {}{spaceID , exptID , createdDate , itemIDs }
684519 logs .CtxInfo (ctx , "GetByExptID sql: %v, args: %v" , sql , args )
685520 return sql , args
686- }
521+ }
0 commit comments