def create_exec_result(time_taken, result_data, query): exec_result = HiveQueryResult(query) if result_data: LOG.debug('Data:\n%s\n' % result_data) exec_result.data = result_data exec_result.time_taken = time_taken exec_result.success = True return exec_result
def create_exec_result(time_taken, result_data): exec_result = HiveQueryResult() if result_data: LOG.debug('Data:\n%s\n' % result_data) exec_result.data = result_data exec_result.time_taken = time_taken exec_result.success = True return exec_result
def run_query_capture_results(cmd, query, exit_on_error): """ Runs the given query command and returns the execution result. Takes in a match function that is used to parse stderr/stdout to extract the results. """ exec_result = HiveQueryResult(query) start_time = datetime.now() try: rc, stdout, stderr = exec_process(cmd) except Exception, e: LOG.error('Error while executing query command: %s' % e) exec_result.query_error = str(e) # TODO: Should probably save the start time and query string for failed queries. return exec_result
def run_query_capture_results(cmd, query, exit_on_error): """ Runs the given query command and returns the execution result. Takes in a match function that is used to parse stderr/stdout to extract the results. """ exec_result = HiveQueryResult(query) start_time = datetime.now() try: rc, stdout, stderr = exec_process(cmd) except Exception, e: LOG.error('Error while executing query command: %s' % e) exec_result.query_error = str(e) # TODO: Should probably save the start time and query string for failed queries. return exec_result
def execute_using_hive_hs2(query, query_config): exec_result = HiveQueryResult(query, query_config=query_config) plugin_runner = query_config.plugin_runner cursor = getattr(threading.current_thread(), 'cursor', None) if cursor is None: cursor = get_hs2_hive_cursor(query_config.hiveserver, user=query_config.user, database=query.db, use_kerberos=query_config.use_kerberos, execOptions=query_config.exec_options) threading.current_thread().cursor = cursor if cursor is None: return exec_result if plugin_runner: plugin_runner.run_plugins_pre(scope="Query") try: exec_result.start_time, start = datetime.now(), time() cursor.execute(query.query_str) exec_result.data = cursor.fetchall() exec_result.time_taken = time() - start exec_result.success = True except Exception as e: LOG.error(str(e)) exec_result.query_error = str(e) finally: if plugin_runner: plugin_runner.run_plugins_post(scope="Query") return exec_result
def execute_using_hive_hs2(query, query_config): exec_result = HiveQueryResult(query, query_config=query_config) plugin_runner = query_config.plugin_runner cursor = getattr(threading.current_thread(), 'cursor', None) if cursor is None: cursor = get_hs2_hive_cursor(query_config.hiveserver, user=query_config.user, database=query.db, use_kerberos=query_config.use_kerberos, execOptions=query_config.exec_options) threading.current_thread().cursor = cursor if cursor is None: return exec_result if plugin_runner: plugin_runner.run_plugins_pre(scope="Query") try: exec_result.start_time, start = datetime.now(), time() cursor.execute(query.query_str) exec_result.data = cursor.fetchall() exec_result.time_taken = time() - start exec_result.success = True except Exception as e: LOG.error(str(e)) exec_result.query_error = str(e) finally: if plugin_runner: plugin_runner.run_plugins_post(scope="Query") return exec_result