def execute_using_impala_beeswax(query, query_config): """Executes a query using beeswax. A new client is created per query, then destroyed. Args: query (str): string containing the query to be executed. query_config (QueryExecConfig) Returns: ImpalaQueryResult """ # Create a client object to talk to impalad exec_result = ImpalaQueryResult(query, query_config=query_config) plugin_runner = query_config.plugin_runner client = establish_beeswax_connection(query_config) if client is None: return exec_result # We need to issue a use database here. if query.db: client.execute("use {0}".format(query.db)) # create a map for query options and the query names to send to the plugin context = build_context(query, query_config) if plugin_runner: plugin_runner.run_plugins_pre(context=context, scope="Query") result = ImpalaBeeswaxResult() try: result = client.execute(query.query_str) except Exception, e: LOG.error(e) exec_result.query_error = str(e)
def execute_using_impala_hs2(query, query_config): """Executes a sql query against Impala using the hs2 interface. Args: query: Query query_config: ImpalaHS2Config Returns: ImpalaQueryResult """ exec_result = ImpalaQueryResult(query, query_config=query_config) plugin_runner = query_config.plugin_runner cursor = get_hs2_impala_cursor(query_config.impalad, use_kerberos=query_config.use_kerberos, database=query.db) 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.runtime_profile = cursor.get_profile() exec_result.exec_summary = str(cursor.get_summary()) exec_result.success = True except Exception as e: LOG.error(str(e)) exec_result.query_error = str(e) finally: cursor.close() if plugin_runner: plugin_runner.run_plugins_post(scope="Query") return exec_result