def query_process_by_key_words(parm): wildcard = fill_wildcard(parm.get('key_words')) start = parm.get('start') end = parm.get('end') log.warn("%s %s %s", wildcard, start, end) return client.excute_sql( "SELECT pname FROM record WHERE pname LIKE '%s' AND timestamp BETWEEN '%s' AND '%s' GROUP BY pname" % (wildcard, start, end))
def query_range(): parm = request.args.to_dict() processfilter = parm.get('processfilter') wildcard = '' if processfilter is not '': wildcard = re.sub(',', "','", "'" + processfilter + "'") log.warn(wildcard) start = parm.get('start') now = time.time() if start is None: start = now - 300 end = parm.get('end') if end is None: end = now return DataProcessor.query(start, end, wildcard)
def list_all(self): conn = PySqlTemplate.data_source.get_conn() cur = conn.cursor() log.warn('_params: %s', self.__params) log.warn('__statement: %s', self.__statement) cur.execute(self.__statement, self.__params if self.__params else {}) cols = [item[0] for item in cur.description] log.warn(','.join(cols)) res = cur.fetchall() cur.close() PySqlTemplate.data_source.close_conn() return [list(e) if len(cols) > 1 else e[0] for e in res]
def init_index_from_conf(path): conf = util.load_json(path) res = create(conf['index'], body=conf['body'], force=conf['force']) log.warn(res)
def excute_sql(sql, format='csv'): log.warn(sql) query = {"query": sql, "fetch_size": 10000} return re.sub('\r', '', es.sql.query(query, format=format))
def query_process_by_key_words(parm): key_words = parm.get('key_words') log.warn(key_words) data = select_process_from_record_by_key_words('%'+key_words+'%') data.insert(0, 'pname') return '\n'.join(data)