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.
(cmd, query)
| 221 | |
| 222 | |
| 223 | def run_query_capture_results(cmd, query): |
| 224 | """ |
| 225 | Runs the given query command and returns the execution result. |
| 226 | |
| 227 | Takes in a match function that is used to parse stderr/stdout to extract the results. |
| 228 | """ |
| 229 | exec_result = HiveQueryResult(query) |
| 230 | start_time = datetime.now() |
| 231 | try: |
| 232 | rc, stdout, stderr = exec_process(cmd) |
| 233 | except Exception as e: |
| 234 | LOG.error('Error while executing query command: %s' % e) |
| 235 | exec_result.query_error = str(e) |
| 236 | # TODO: Should probably save the start time and query string for failed queries. |
| 237 | return exec_result |
| 238 | if rc != 0: |
| 239 | msg = ('Command returned with an error:\n' |
| 240 | 'rc: %d\n' |
| 241 | 'STDERR:\n%s' |
| 242 | 'STDOUT:\n%s' |
| 243 | % (rc, stderr, stdout)) |
| 244 | LOG.error(msg) |
| 245 | exec_result.query_error = msg |
| 246 | return exec_result |
| 247 | # The command completed |
| 248 | exec_result = parse_jdbc_query_results(stdout, query) |
| 249 | exec_result.query = query |
| 250 | exec_result.start_time = start_time |
| 251 | return exec_result |
no test coverage detected