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 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 #3
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 #4
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 #5
0
def create_exec_result(time_taken, result_data):
  # TODO: Either don't require a query string as an arg, or plumb it through here
  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 #6
0
def create_exec_result(time_taken, result_data):
    # TODO: Either don't require a query string as an arg, or plumb it through here
    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 #7
0
def run_query_capture_results(cmd, query, query_result_parse_function, 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 = execute_shell_cmd(cmd)
  except Exception, e:
    LOG.error('Error while executing query command: %s' % e)
    exec_result.query_error = str(e)
    return exec_result
Example #8
0
def run_query_capture_results(cmd, query, query_result_parse_function,
                              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 = execute_shell_cmd(cmd)
    except Exception, e:
        LOG.error('Error while executing query command: %s' % e)
        exec_result.query_error = str(e)
        return exec_result
Example #9
0
 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)