我有一个代码管道,我使用 Pyhive 将数据插入数据库。
from pyhive import hive
def save_postprocess_data(postprocess_data):
conn = hive.Connection(host="hostname", port=10000, username="username")
curr = conn.cursor()
insert = ""
for i in range(postprocess_data.shape[0]):
insert = insert + ",('%s','%d', '%d', '%s','%d','%s', '%.2f', '%s','%s','%d','%s')" % (postprocess_data.iloc[i,0],postprocess_data.iloc[i,1],postprocess_data.iloc[i,2],postprocess_data.iloc[i,3],postprocess_data.iloc[i,4],postprocess_data.iloc[i,5 ],postprocess_data.iloc[i,6],postprocess_data.iloc[i,7],postprocess_data.iloc[i,8], postprocess_data.iloc[i,9],postprocess_data.iloc[i,10])
insert_query = "insert into table table_name PARTITION (date) values"+ insert[1:]
curr.execute(insert_query)
conn.close()
return None
而且,我什至不使用记录器就将整个查询打印在应用程序日志上
12/17/2018 07:59:21 AM USE `default`
12/17/2018 11:55:03 AM USE `default`
12/17/2018 11:55:03 AM insert into table table_name PARTITION (date) values("HUGE LIST OF VALUES")
我有以下记录器配置
logging.basicConfig(filename=root_dir+'/application.log',format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p',level=logging.INFO)
问题是我有大约 30M 条记录需要插入,并且记录器中充满了来自查询的值。
我不想记录整个查询,只插入以下内容
logging.info("query successfully inserted %d values into the table",no_of_records)