I am trying to find out how to use the Python Script node to make a generator for single UUID. I have not been able to figure out what data type output_tables is respectively how I can convert a scalar or uuid.UUID object to knime.api.Table. I have seen the pandas.DataFrame example, but am reluctant to use it and throw away unused parts in the aftermath.
The background of this is that I want to generate a UUID that will be used to identify a load process. So, I know the overhead of the aftermath would be negligible, but it is very awkward to me.
[edit] An efficient implementation might be suitable as ID generator for payload records.
If I understand correctly, you want to create a single unique identifier that you will use throughout your workflow. Perhaps to record some sort of “Session ID” for you to reference later on.
If you simply use the Empty Table Creator node and set it to generate one row, then use the GUID Generator component, that will effectively create a single GUID/UUID that can be accessed elsewhere in your workflows.
If you really wanted to do it in Python, you could use a Python Script node with a script like the one below, but I wouldn’t recommend it. The GUID Generator component uses Java which would likely execute a bit faster.
import knime.scripting.io as knio
import pandas as pd
import uuid
knio.output_tables[0] = knio.Table.from_pandas(
pd.DataFrame({'session_id': [str(uuid.uuid4())]})
)
From the doc at DataFrame — pandas 2.1.1 documentation I was thinking that DataFrame are two dimensional only. Maybe I need much more time to understand the concept behind it.
Is the input to the constructor invalid JSON?
In my Python script I am simply declaring a DataFrame with a single column (session_id) and a single row containing the uuid. The output is still a “two dimensional” object with columns and rows, there is just only one column and one row in this case.
Thanks for the shed light. I got confused by the “two”. If they just spoke of a table, I would have got it right from the beginning. I am a simple database person.