Does component has it's own data dir?

Hi, KNIMEr :partying_face: :partying_face: :partying_face:

We all know workflow has a dir called data which can have data in it with great portability.

If I want add some extra data to component for further share, what’s the best practice? It seems it doesn’t has data dir, right?

How do you guys do it and do you have any good ideas?

1 Like

Hi @HaveF , a component can be considered as what a function is in programming languages, so they do not usually have a link to a file, but rather would take input parameters - either some data that can be read from a file, or perhaps a link to a file path (as data row or as a variable).

While some components can have some data, for example a list for mapping, this can be stored in a table within the component.

Can you tell us a bit more what your component is doing, and how the file you want to attach to it is related to the component?

3 Likes

@HaveF you can use the data directory of you share the whole workflow. If you want static data to be shared you could create the data in a script or with the

2 Likes

Yes, component is a function, and it is a pure function :smiley:

Here is my case:

I want to use some Java Jar file in Java Snippet as additional libraries, I don’t know where to put them If I want to make this part as a component.

Of course I can put it on some specific positions, but if I want to share the component with others, like on KNIME hub, it seems I still tell others to download jar file, and put it some where. It just looks awkward.

share the whole workflow is an interesting idea. But it looks like it’s missing the updated features as component.

@HaveF I have created an example like this. You have a code as a string and dynamically write that to a (temporary) folder and use that as a source. The example is about a Python code. Maybe you can adapt that.

Not the most elegant solution but it could work.

2 Likes

Hi @mlauber71 , thanks for the hint. It’s an interesting solution for portable Python code.

Please forgive me for being picky at first.

Your example is an example of using the same node to run on different platforms.
What I want is an example of using the same component in different workflows.

As I said before:

  1. I want to use some Java jar file in Java Snippet as additional libraries and build it as a component.
  2. I want to use this component in different workflows.

It seems a working solution is to dynamically download the jar file in the component, then use the jar file in Java Snippet. It feels a bit clumsy, but it seems to be the only way.

Sometimes I stick to clear and best practices. Sorry for being picky again

@HaveF no worries :slight_smile: discussing ideas and selecting the best is one aim of this forum. If you can savely provide a Component or a JAR file on a central storage this might be the best solution. If people would load a whole workflow you might be able to use the /data/ folder. In the other thread there were suggestions of putting the (Python) code on a repository - you also might think about a company repository (with JFrog/Artifactory or something similar).

The thing with dynamically creating a .PY file from a KNIME node and reading that back is more like a hack to have everything within KNIME nodes. Might not really be a serious option, more to demonstrate that if you have restrictions you still could do this :slight_smile:

2 Likes

Hi @HaveF ahhh, jar files… this is certainly a good use case. I chose not to create public components if they were dependent on jar files. For internal usage, that is components that gonna run on the same machine, such as in your case where you simply want to reuse the component in the same workflow and to benefit from the “auto-update” when updating the component, then you can leave the path to the jar file hardcoded inside the component. The component itself does not need to include the jar file, as long as the jar file exists at the path it’s pointing to.

Alternatively, there are some libraries that come with Knime, and if the jar file you wanted to include already comes with Knime, then you don’t have to include the jar file and simply configure your Java Snippet to use it (or multiple ones).

You can do this in the “Additional Bundles” tab in the Java Snippet node:

You can add from the Bundles that are available. One of the libraries that I used a lot is the Apache Commons for encoding. Just look for it in the Bundles list and then add it:
image

Once you add it, you will see it added in the top section:

You can add multiple libraries, not just one.

4 Likes

I see. But I suspect there will be some issues with version migration if KNIME bumped its version. Am I right?

Hi @HaveF , but isn’t this applicable to anything we do within the component? Nodes deprecated, etc. But that’s the beauty of the using components, where you can update the component, and any workflow that’s linked to the component will be updated :wink:

1 Like

haha @bruno29a it make sense. :grin: :grin: :handshake: :handshake:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.