def test_prepare_template(self): pig = "sh echo $DATE;" task_id = TEST_TASK_ID operator = PigOperator(pig=pig, task_id=task_id) operator.prepare_template() self.assertEqual(pig, operator.pig) # converts when pigparams_jinja_translate = true operator = PigOperator(pig=pig, task_id=task_id, pigparams_jinja_translate=True) operator.prepare_template() self.assertEqual("sh echo {{ DATE }};", operator.pig)
def test_on_kill(self, mock_kill, mock_rul_cli): operator = PigOperator(pig=PIG, task_id=TEST_TASK_ID) operator.execute(context=TEST_CONTEXT_ID) operator.on_kill() mock_rul_cli.assert_called() mock_kill.assert_called()
def test_execute(self, mock_run_cli): pig_opts = "-x mapreduce" operator = PigOperator(pig=PIG, pig_opts=pig_opts, task_id=TEST_TASK_ID) operator.execute(context=TEST_CONTEXT_ID) mock_run_cli.assert_called_once_with(pig=PIG, pig_opts=pig_opts)
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. """Example DAG demonstrating the usage of the PigOperator.""" from airflow.models import DAG from airflow.providers.apache.pig.operators.pig import PigOperator from airflow.utils.dates import days_ago args = { 'owner': 'airflow', 'start_date': days_ago(2), } dag = DAG(dag_id='example_pig_operator', default_args=args, schedule_interval=None, tags=['example']) run_this = PigOperator( task_id="run_example_pig_script", pig="ls /;", pig_opts="-x local", dag=dag, )
def test_execute_default_pig_opts_to_none(self, mock_run_cli): operator = PigOperator(pig=PIG, task_id=TEST_TASK_ID) operator.execute(context=TEST_CONTEXT_ID) mock_run_cli.assert_called_once_with(pig=PIG, pig_opts=None)