You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support a JoinPythonOperator to Work with the BranchPythonOperator Already Supported #167
Currently, in our QA environment, our Spark job has been split into 2 steps, let's call them A and C. In our PROD environment however, it is still one step, A. I don't want to maintain 2 different DAGs, one for PROD and one for QA. Instead, I would like to leverage both Variables and the new BranchPythonOperator.
Specifically, I have a new Variable called ENV with values of QA or PROD. I would like the PythonBranchOperator to execute A-->B-->C-->D-->E in QA and A-->B-->D-->E in PROD. I would like to make step C optional based on ENV.
My DAG is below:
I tried to leverage the new BranchPythonOperator for this, but it doesn't work. The reason is that the DAG is not allowed to rejoin after a branch. Once one leg of the branch is taken, all downstream descendants are marked as skipped. However, if the DAG rejoins, then this is not the case.
changed the title [-]Need the possibility of skipping a BashOperator at Execution Time[/-][+]Need the Ability to skip a BashOperator at Execution Time[/+]on Jul 23, 2015
changed the title [-]Need the Ability to skip a BashOperator at Execution Time[/-][+]Need the Ability to skip a BashOperator at Execution Time Based on Airflow Read-Only Variable Values[/+]on Jul 23, 2015
changed the title [-]Need the Ability to skip a BashOperator at Execution Time Based on Airflow Read-Only Variable Values[/-][+]Need the Ability to Optionally Execute a (Bash) Operator based on a Read-only Variable Value[/+]on Jul 23, 2015
We've been doing this for skipping tasks before a certain date for instance as in {% if ds >= '2015-01-01' %}
A more generic way could be (not a feature yet) to pass a skip_and_succeed param that expects a callable that receives the context object and skips and succeeds if the callable returns True. It may look something like this:
# Operator : Read the parquet data and generate aggregate data
optional_aggregation_templated_command = """
{% if params.ENV == "EP_PROD" %}
echo "Skipping Aggregation in Prod Env"
{% else %}
ssh -i ~/.ssh/id_rsa_spark [email protected] '. /root/.bash_profile; /root/run_aggregation.sh {{ macros.ds_format(macros.ds_add(ds, -3), '%Y-%m-%d', '%s') }} {{ execution_date.strftime('%s') }}'
{% endif %}
"""
aggregate_data_spark_job = BashOperator(
task_id='aggregate_data_spark_job',
execution_timeout=timedelta(hours=3),
bash_command=optional_aggregation_templated_command,
params={'ENV': ENV},
dag=dag)
aggregate_data_spark_job.set_upstream(generate_new_parquet_files_spark_job)
It's a handy solution, but I guess I was thinking of the more general problem of handling branched flows that need to be joined later. Branching is a great feature, but with branching often comes joining. The legs of the branch could be different lengths. Currently, you set all descendants to "Skipped", but perhaps the code can be changed to set only those descendants to Skipped that do not join with a Non-skipped branch. In other words, we would need to set descendants to skipped until we come across a node that has multiple parents and one of those parents is not skipped.
changed the title [-]Need the Ability to Optionally Execute a (Bash) Operator based on a Read-only Variable Value[/-][+]Support a JoinPythonOperator to Parallel the BranchPythonOperator Already Supported[/+]on Jul 25, 2015
Hi Folks!
I've changed the title of this issue to Support a JoinPythonOperator to Work with the BranchPythonOperator Already Supported. Prior to the creation of the BranchPythonOperator, we had ability to execute DAGs containing "diamond" topologies. With the advent and use of the BranchPythonOperator, we lost that ability, since every downstream node is labeled as skipped. I think the support of branching sets Airflow apart from other workflow engines, but it does require support for joining, as shown above. If this were available I would use it instead of the 'if-else' templating method, which I feel is less elegant.
changed the title [-]Support a JoinPythonOperator to Parallel the BranchPythonOperator Already Supported[/-][+]Support a JoinPythonOperator to Work with the BranchPythonOperator Already Supported[/+]on Jul 25, 2015
Btw, when attempting to use the branch operator, I am getting a "import error" on the line trying to import the branch python operator. (from airflow.operators import BranchPythonOperator)
i am using v1.1.1. is the branch operator only available in a specific version or release of airflow ?
@smnaveen the operator showed up in 1.2.0 if I am correct, but I would recommend using the latest release (There have been a decent amount of bug fixes since)
Activity
[-]Need the possibility of skipping a BashOperator at Execution Time[/-][+]Need the Ability to skip a BashOperator at Execution Time[/+][-]Need the Ability to skip a BashOperator at Execution Time[/-][+]Need the Ability to skip a BashOperator at Execution Time Based on Airflow Read-Only Variable Values[/+][-]Need the Ability to skip a BashOperator at Execution Time Based on Airflow Read-Only Variable Values[/-][+]Need the Ability to Optionally Execute a (Bash) Operator based on a Read-only Variable Value[/+]mistercrunch commentedon Jul 23, 2015
For the templated operators like
BashOperatorit's pretty easy to skip and succeed:We've been doing this for skipping tasks before a certain date for instance as in
{% if ds >= '2015-01-01' %}A more generic way could be (not a feature yet) to pass a
skip_and_succeedparam that expects a callable that receives the context object and skips and succeeds if the callable returnsTrue. It may look something like this:r39132 commentedon Jul 23, 2015
Cool. This works.
It's a handy solution, but I guess I was thinking of the more general problem of handling branched flows that need to be joined later. Branching is a great feature, but with branching often comes joining. The legs of the branch could be different lengths. Currently, you set all descendants to "Skipped", but perhaps the code can be changed to set only those descendants to Skipped that do not join with a Non-skipped branch. In other words, we would need to set descendants to skipped until we come across a node that has multiple parents and one of those parents is not skipped.
r39132 commentedon Jul 23, 2015
BTW, I was not able to follow your FooOperator example. I'd like to keep this open in hopes there is a more generic join approach!
[-]Need the Ability to Optionally Execute a (Bash) Operator based on a Read-only Variable Value[/-][+]Support a JoinPythonOperator to Parallel the BranchPythonOperator Already Supported[/+]r39132 commentedon Jul 25, 2015
Hi Folks!
I've changed the title of this issue to
Support a JoinPythonOperator to Work with the BranchPythonOperator Already Supported. Prior to the creation of the BranchPythonOperator, we had ability to execute DAGs containing "diamond" topologies. With the advent and use of the BranchPythonOperator, we lost that ability, since every downstream node is labeled asskipped. I think the support of branching sets Airflow apart from other workflow engines, but it does require support for joining, as shown above. If this were available I would use it instead of the 'if-else' templating method, which I feel is less elegant.[-]Support a JoinPythonOperator to Parallel the BranchPythonOperator Already Supported[/-][+]Support a JoinPythonOperator to Work with the BranchPythonOperator Already Supported[/+]mistercrunch commentedon Jul 27, 2015
Sounds right. We'd need the
skippedstate to propagate downstream until it hits a JoinOperator of some sort.azaroth42 commentedon Aug 14, 2015
👍
mistercrunch commentedon Aug 14, 2015
Joining will be possible using any operator once this PR is merged!
#261
r39132 commentedon Aug 14, 2015
👍
smnaveen commentedon Aug 24, 2015
Btw, when attempting to use the branch operator, I am getting a "import error" on the line trying to import the branch python operator. (from airflow.operators import BranchPythonOperator)
i am using v1.1.1. is the branch operator only available in a specific version or release of airflow ?
artwr commentedon Aug 24, 2015
@smnaveen the operator showed up in 1.2.0 if I am correct, but I would recommend using the latest release (There have been a decent amount of bug fixes since)
mistercrunch commentedon Sep 19, 2015
Joining can now be achieve with "trigger rules":
http://pythonhosted.org/airflow/concepts.html#trigger-rules
r39132 commentedon Nov 21, 2015
I finally got to a point where I needed to use this.. excellent!
Thanks!
Merge pull request apache#167 from nestjs/renovate/npm-ws-vulnerability