https://kedro.org/ logo
#questions
Title
# questions
a

Afiq Johari

02/07/2024, 3:28 PM
Hi, How can I access the current namespace when I run a node? I want to reuse a node for two different namespaces. However, one of the namespaces will require a minor data transformation. So I want to be able to define within the node by saying that if the current namespace is ABC, then perform this extra data transformation, if not, just continue. Similarly, some namespaces may skip some nodes all together. So when I perform kedro run --namespace=ABC, only relevant nodes related to the namespace should be executed
K 1
a

Ahdra Merali

02/07/2024, 5:47 PM
Hi Afiq, It's not possible to access the pipeline namespace form within the node. For this use case you could do the following: ā€¢ Extend your node function to accept an additional argument (e.g
transform: bool = False
), and add a condition to the function, e.g.:
Copy code
#nodes.py
...
if transform: 
    transform_data(...)
ā€¢ Add parameters that will hold the value for the condition, e.g.
Copy code
#parameters.yml
...
transform_namespace: true
ā€¢ When defining a node within your namespace pipeline, include the parameter in your inputs where you wish to trigger the condition
Copy code
#pipelines.py
...
node(
    func=...,
    inputs=[..., "params:transform_namespace"],
    ...
šŸ‘ 1
j

Juan Luis

02/07/2024, 6:03 PM
on top of what @Ahdra Merali said, maybe something could be hacked with the
before_node_run
hook https://docs.kedro.org/en/stable/kedro.framework.hooks.specs.NodeSpecs.html#kedro.framework.hooks.specs.NodeSpecs.before_node_run
šŸ‘ 1