def test_run_commands_from_string_without_param_substitution(self): _test_id = str(uuid.uuid4()) _output_dir = "/tmp/data_{}".format(_test_id) _input_dir = self.copy_file_from_local(self.temp_file("hello,world,world", ".txt")) commands = "A = load '{}' using PigStorage(',');".format(_input_dir) commands += "B = foreach A generate \$0 as id;" commands += "STORE B into '{}';".format(_output_dir) try: _pig = Pig.load_commands_from_string(commands) _result = _pig.run() _result.if_failed_raise(AssertionError("test_run_commands_from_string failed")) self.assertTrue(HDFS(_output_dir).exists(), "Cannot find job output") finally: self.delete_file_in_hdfs(_input_dir) self.delete_file_in_hdfs(_output_dir)
def test_run_commands_from_string_without_param_substitution(self): _test_id = str(uuid.uuid4()) _output_dir = "/tmp/data_{}".format(_test_id) _input_dir = self.copy_file_from_local( self.temp_file("hello,world,world", ".txt")) commands = "A = load '{}' using PigStorage(',');".format(_input_dir) commands += "B = foreach A generate \$0 as id;" commands += "STORE B into '{}';".format(_output_dir) try: _pig = Pig.load_commands_from_string(commands) _result = _pig.run() _result.if_failed_raise( AssertionError("test_run_commands_from_string failed")) self.assertTrue( HDFS(_output_dir).exists(), "Cannot find job output") finally: self.delete_file_in_hdfs(_input_dir) self.delete_file_in_hdfs(_output_dir)
def test_run_script_from_string(self): Pig.load_commands_from_string( commands="ls /", command_executor=mock_executor('pig -e "ls /"')).run()