Every same component that I use, has different configuration and output, so it would be convenient to place these inside it’s own component directory.
I was checking on ways to save data inside the directory of a component that is placed in the workflow.
I know that storing data in shared components and not in the workflow cannot be done yet, but I was wondering if there’s a workaround.
My aim now is to query the path of the directory of the component once it’s placed in the workflow.
Once placed, it’s named automatically by KNIME, with a hashtag followed by a number, e.g COMPONENT (#1).
The problem is that “COMPONENT (#1)” is only in the workflow.knime xml file of the parent directory - where the workflow is located.
Is there a way to query this “COMPONENT (#1)”, so I can use that to create and save files inside it.
TLDR; How do you identify the unique name of a component when you are inside it?
I hope that was clear enough!
I would very much appreciate any help!
it’s always fun to tinker with the inner workings of KNIME
The number you are referring to is the Node ID. Components have IDs, too, and nested Nodes/Components will have their IDs concatenated so that you can identify them uniquely in a workflow. For reasons that are rather complicated and not relevant here, there is a 0: added as well. As an example, 6:0:5:0:1 is the Node inside of Component #6, inside of Component #5 with ID #1. I’d probably write a component that first “finds itself” from the workflow.knime file, i.e., get where its nested, probably based on its name. The I’d join this in with the path from the workflow folder itself, to get the actual path. Note, that the Component name on the file system is truncated to 12 characters length.
I’ve once done something similar with this Component, and I think you can salvage some of the parts. It fetches the data from the file system (folders etc; top part) and the data from the workflow.knime xml (bottom part):
To make this work on a KNIME Server, you’d need to allow local file system access.
Hope that helps and inspires!
Thanks for the detailed response!
I read it and I’m curious about the creation of the component that “finds itself” as you noted.
I should remind that the whole reason I’m confused is that if I am inside a component and if I save a file, the file is saved in the workflow directory and not in the component directory.
Let’s say I have two exact same components. The only difference between them, is spotted in their automatically created directories within the workflow directory, these are settings.xml files
The uniqueness is indeed in the node names like 3:1:0:245 and 3:2:0:245 and also in the coordinates(x,y) of the nodes.
While working on the component though, I am in the knime.workspace directory not in knime.workspace/Component (#1) which causes the whole issue for me.
There I can find the workflow.knime, that shows the node names as COMPONENT (#1) and COMPONENT (#2).
What tricks me is that even if I can match these, I still don’t know in which component I’m at.
What I did is to create a random flow variable within the component, which I then try to match from all the component directories. Then I would know that this is the directory I am at and save my files there.
I need to test the performance of it, since if I have a lot of components inside the workflow, all the components will create their own unique random flow variable, then try to match it along all the different component directories.
Hope I didn’t confuse you a lot!
I will upload the component to show what I am exactly doing.
I’d rather make it more simple.
I tried your node and I have this issue, which also is the main problem I encounter:
Having the List Files/Folders node inside a Component and trying to show the files that are included in this component is not allowed, because it’s not understood by KNIME that this is indeed a folder.
As you note too, it will work only with absolute paths.
Which means you need to specify the path you are looking for.
The only way I see is to create a unique variable inside the component, which will be later queried from all the xml’s of the different component directories. Once this unique variable is matched then we can easily conclude the Component’s path.
Hopefully I am not making it more complex than it is!
I like this idea! Indeed, I don’t see another way other than “marking” the component you are currently in in its settings.xml, as you need some sort of distinguisher. From that you know where you are, can create a folder “data”, move/write files there and so on…
I think this is the least complex way you can have it
I am happy about the confirmation.
Here is the component if anyone encounters something similar.
If you place this component inside your own component, it will return its path in the file system.
Then you can save your files there if you wish to organize your workflows like that.
That’s great, thank you very much for sharing!
So it turns out that Timer info node shows the NodeID and I completely missed that out.
Now it’s simple, parsing the NodeID from Timer Info and then trying to find that in workflow.knime xml with a simple python script, we can easily return the ComponentID which is also the Component auto-created directory.
I updated the shared component.