in scripts/glue_script/run_redshift_benchmark.py [0:0]
def rs_select(self, sql, path,type,runs):
# 执行查询
try:
conn = self._pool.connection()
cursor = conn.cursor()
cursor.execute("set enable_result_cache_for_session to %s;" %self.result_cache)
startTime = datetime.datetime.now()
cursor.execute(sql)
result = cursor.fetchall()
endTime = datetime.datetime.now()
costSeconds = (endTime - startTime).seconds
costMicroSeconds = (endTime - startTime).microseconds
costTime = round(costSeconds+costMicroSeconds/1000000,2)
# Record the result to dataframe and log
# columns=['query','round','testType','startTime','endTime','elapseSeconds']
self.result_summary=self.result_summary.append(pd.Series([self.test_name,path,runs,type,startTime,endTime,costTime],index=['testName','query','round','testType','startTime','endTime','elapseSeconds']),ignore_index=True)
self.root.info('QUERY SUCCESS: script %s success and take %s seconds.'%(path,costTime))
except Exception as e:
self.root.error('ERROR: execute {0} causes error'.format(path))
self.result_summary=self.result_summary.append(pd.Series([self.test_name,path,runs,type,'error','error',0.0],index=['testName','query','round','testType','startTime','endTime','elapseSeconds']),ignore_index=True)
finally:
cursor.close()
conn.close()