Example #1
0
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:
    QueryResult
  """

    # Create a client object to talk to impalad
    exec_result = QueryResult(query, query_config=query_config)
    plugin_runner = query_config.plugin_runner
    (success, client) = establish_beeswax_connection(query.query_str,
                                                     query_config)
    if not success: return exec_result
    # We need to issue a use database here.
    if query.db:
        use_query = 'use %s' % query.db
        client.execute(use_query)
    # 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)
Example #2
0
def create_exec_result(time_taken, result_data):
    exec_result = QueryResult()
    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
Example #3
0
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 = QueryResult(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 __init__(self, name, query, func, config, exit_on_error):
     self.exec_func = func
     self.exec_config = config
     self.query = query
     self.exit_on_error = exit_on_error
     self.executor_name = name
     self._result = QueryResult(query, query_config=self.exec_config)