Preset Column Data Type from a File Reader Node (Forcing for String Type)

Good evening everyone,

Ok, i’ve been searching since like 1 year about a solution for this God Forsaken topic… Forcing a Table column data type to string (or whatever data type we want) from the beginning.

Well let me talk about why this is bothering me, It results that I’m importing a data archive with a File Reader node since it is a TXT file with like 100 columns and there is many columns with codes (like Barcodes, GLN, Customer Product Codes, Internal Product Codes, etc.) that are columns for string purposes and not for arithmetic operation purposes.

So when I import the data it results that the reader identifies these columns with codes as Integer or Double (many of my codes have certain quantity of zeroes to the left and they get erased, also it adds commas and dots)… well someone would say that I could do right click at the column header inside the File Reader node and change the type from the column properties… and that is 100% right and I would not have a problem if there is one thing that would never happens… that the node never forget the settings.

Ok, so this is the problem and maybe i’m not doing something right and maybe somebody could give me an advice to how operate better.

  1. The file I’m reading in the node changes every week (manually) and sometimes between the week… but not only the data changes, but also changes the name of the file because there is an historic data saving from dates (Is not an overwrite).

  2. When I read the file in the node (after setting the data type on each column manually) I click the check box that says “Preserve user settings for new location”… and through here we are doing absolutely great… till the next data update, because the check box don´t keep selected and that’s the problem, sometimes other people and I forget to select the check box in the next update and saves after the running process so we have to set the Data Type for the column again manually and rerun the process.

That’s the problem I have but actually it could be a great help if there would be an option to save the manual setting as a preset or forcing the node to make every column data as a String, but I’ve been searching a simple solution to this problem but no Luck. Is there someone that have some advice or simple solution to this problem?

Maybe this would be a simple issue but I guess that this topic will help a lot of people that have this similar problem from different ways, and I want to thanks to you for the help in advance.

Thanks.

Hi,

See attached workflow, hope it helps !

Martin K.

WF_01.ZIP (32.9 KB)

4 Likes

Hi Martin!

Thank You very much for your response. This is a very interesting Solution!

Exploring the work flow I see that you used variables to define every column to be string, is there a way to include the variables for Integer and Double? Do you know where can I find a list of Variables to use?

Thank you for your help!

Hi Andres,

Sorry for late response.

  1. Generally, in File Reader node, if you want to know a string defining class (type) of any column, put some variable name (e.g. X) in the rightmost empty cell on “cell_class”.
    After you run the node, go on node output and on the tab “Flow Variables”
    you will see class of the X variable related to particular column.
    For your convenience, strings for Integer and Double are:

org.knime.core.data.def.IntCell
org.knime.core.data.def.DoubleCell

  1. As for the workflow, on “Table Creator” node, put another 2 columns into the table,
    the first one, e.g. named “class_Int” with related string, the second one for Double.
    Then, you will be able to specify on “File Reader” node, for each column any of those 3 variable types.

Best regards !

1 Like

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