瀏覽代碼

修改用正则替换日期

xueyiming 1 天之前
父節點
當前提交
2cfa897125
共有 1 個文件被更改,包括 5 次插入11 次删除
  1. 5 11
      ad/pai_flow_operator.py

+ 5 - 11
ad/pai_flow_operator.py

@@ -17,6 +17,7 @@ from alibabacloud_paiflow20210202.client import Client as PAIFlow20210202Client
 from datetime import datetime, timedelta
 from odps import ODPS
 from ad_monitor_util import _monitor
+import re
 
 target_names = {
     '样本shuffle',
@@ -153,17 +154,10 @@ def get_train_data_list(date_begin):
 def update_data_date_range(old_str, date_begin='20250320'):
     date_list = get_train_data_list(date_begin)
     train_list = ["'" + item + "'" for item in date_list]
-    result = ','.join(train_list)
-    start_index = old_str.find('where dt in (')
-    if start_index != -1:
-        equal_sign_index = start_index + len('where dt in (')
-        # 找到下一个双引号的位置
-        next_quote_index = old_str.find(')', equal_sign_index)
-        if next_quote_index != -1:
-            # 进行替换
-            new_value = old_str[:equal_sign_index] + result + old_str[next_quote_index:]
-            return new_value
-    return None
+    result = f"in ({','.join(train_list)})"
+    pattern = r"in\s*\(\s*'[^']+'\s*(?:,\s*'[^']+'\s*)*\)"
+    new_value = re.sub(pattern, result, old_str, flags=re.IGNORECASE)
+    return new_value
 
 
 def compare_timestamp_with_today_start(time_str):