def test_is_to_temp_table_lowercase(self): # preconditions query_1 = self.query_1.lower() query_2 = self.query_2.lower() source_query = self.source_name_query.lower() # test self.assertTrue( sql_wrangle.is_to_temp_table(query_1), "failed with lower case. function is not case insensitive") self.assertTrue( sql_wrangle.is_to_temp_table(query_2), "failed with lower case. function is not case insensitive") self.assertFalse( sql_wrangle.is_to_temp_table(source_query), "failed with lower case. function is not case insensitive")
def test_get_run_analysis_commands(self): # pre-conditions cmd_iter = achilles._get_run_analysis_commands(self.hpo_id) commands = list(cmd_iter) # test self.assertEqual(len(commands), self.achilles_analysis_count) for command in commands: is_temp = sql_wrangle.is_to_temp_table(command) self.assertFalse(is_temp, command)
def run_heel_analysis_job(command): """ Runs command (query) and waits for job completion :param command: query to run :return: None """ if sql_wrangle.is_to_temp_table(command): logging.info('Running achilles heel temp query %s' % command) table_id = sql_wrangle.get_temp_table_name(command) query = sql_wrangle.get_temp_table_query(command) job_result = bq_utils.query(query, destination_table_id=table_id) else: logging.info('Running achilles heel load query %s' % command) job_result = bq_utils.query(command) job_id = job_result['jobReference']['jobId'] incomplete_jobs = bq_utils.wait_on_jobs([job_id]) if len(incomplete_jobs) > 0: logging.info('Job id %s taking too long' % job_id) raise RuntimeError('Job id %s taking too long' % job_id)