From 836cd0fd2fd27bcdc7ecdb2272f45ccaf40fa0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=AF=85?= Date: Mon, 9 Jan 2023 10:23:38 +0000 Subject: [PATCH] =?UTF-8?q?python2=E7=89=88=E6=9C=AC=E7=9A=84sql=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8C=E6=AD=A5=E8=87=AA=E5=8A=A8=E5=8C=96=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sql文件同步自动化检测方案/sqlFilesAutoDetect.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Clickhouse最新全量建表语句/sql文件同步自动化检测方案/sqlFilesAutoDetect.py diff --git a/Clickhouse最新全量建表语句/sql文件同步自动化检测方案/sqlFilesAutoDetect.py b/Clickhouse最新全量建表语句/sql文件同步自动化检测方案/sqlFilesAutoDetect.py new file mode 100644 index 0000000..371cdde --- /dev/null +++ b/Clickhouse最新全量建表语句/sql文件同步自动化检测方案/sqlFilesAutoDetect.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 - +import os + +newSqlFilePath = "Clickhouse_TSG_建表语句_new.sql" #新表文件路径 +oldSqlFilePath = "Clickhouse_TSG_建表语句_old.sql" #旧表文件路径 + +shellCommand1 = "diff "+newSqlFilePath +" "+oldSqlFilePath#shell命令 +shellCommand2 = "diff "+oldSqlFilePath +" "+newSqlFilePath#shell命令,左右表位置互换,可能有不同的对比结果 +shellCommand = [shellCommand1,shellCommand2] + +for s in range(0,len(shellCommand)): + print shellCommand[s]+":" + re = os.popen(shellCommand[s]).readlines() + result = [] + isRight= False #未出现右箭头 + keyWord = ["PRIMARY"] #不能要的关键字 + isKeyWord = False #表示当前列表未出现关键字 + for i in range(0, len(re)): # 由于原始结果需要转换编码,所以循环转为utf8编码并且去除\n换行 + res = re[i].strip('\n') + for j in range(0,len(keyWord)): + if str(res).find(keyWord[j]) != -1: + isKeyWord = True # 表示res出现关键字 + if isRight == False and str(res).find(">", 0, 1) == 0: + isRight = True + result.append(res) + elif isRight == True and str(res).find(">",0,1) == -1 : + if isKeyWord ==False: + print result + result = [] + result.append(res) + isRight = False + isKeyWord = False + else: + result.append(res) + if i == len(re) -1 : + if isKeyWord == False: + print result + print "" + + + + + + +