Hello Team, If I have 20 nodes where I want to con...
# questions
a
Hello Team, If I have 20 nodes where I want to conditionally execute nodes, like node_1 if true else node_2 Is it possible in kedro? I did go through conditionally executing pipelines but was not able to find relevant docs for nodes
👀 1
e
Hi @Ayushi, Kedro does not support
if/else
node execution by default, because node execution order is determined by a topological sort of nodes based on inputs and outputs, not runtime conditions. However, there are workarounds: 1. Use parameters inside a node - have one node that checks a flag and internally decides which logic to run. Pipeline sees it as one node.
Copy code
def conditional_node(param, data1, data2):
    if param:
        return process_node1(data1)
    else:
        return process_node2(data2)
2. Use node tags - assign different tags to nodes and run only the branch you want based on a condition. Kedro allows selective execution of nodes by tags. You can create two nodes:
Copy code
node_1 = node(func=process_node1, inputs="data1", outputs="out1", name="node_1", tags=["branch1"])
node_2 = node(func=process_node2, inputs="data2", outputs="out2", name="node_2", tags=["branch2"])
Then conditionally run the pipeline:
Copy code
with KedroSession.create(...) as session:
    if condition:
        session.run(tags=["branch1"])
    else:
        session.run(tags=["branch2"])
K 1
👍 1