0

I have a wide table filled with ID numbers (starting with a variable number of zeros) and I want to import it into KNIME but the columns are automatically detected as Integer. I tried to manually modify the settings.xml file corresponding to the import node in order to enforce a String type import without spending my afternoon clicking on each column, every time I get a new file. The entry is now:

<entry key="cell_class" type="xstring" value="org.knime.core.data.def.StringCell"/>

I get an error when re-opening the workflow. So I also modified the MissValuePattern entry to:

<entry key="MissValuePattern" type="xstring" value="?"/>

Still getting an error when re-opening the workflow. I don't see any difference between a string and an integer column so I'm a bit stuck.

ATN
  • 665
  • 8
  • 26
  • Which node do you use? Does not the Preserve user settings in File Reader works for your use case? (Or the number/order of columns differ in the input files?) – Gábor Bakos May 15 '14 at 17:02
  • I use the basic File Reader node. The number and the sequence of my columns both vary, but I can cast a String to an Integer afterwards, the opposite is not always possible. – ATN May 19 '14 at 09:12

5 Answers5

1

Use the Line Reader Node to read each line in one at a time into one column. Then attach it to a Cell Splitter node and use the a space character (or whatever it is) that is separating the columns. Select the "as new columns" radio button and the new columns will have the same type as the original column, i.e., a String.

1

You can manually execute arbitrary java code to create a new column or to replace an existing one using Java Snippet (simple) or Java Snippen. For example, you can concatenate your number of values of the Integer columns Col0, Col1, Col2 as

String myCol = $Col0$ + " " + $Col1$ + " " + $Col2$;
return myCol; 
//or return $Col0$ + " " + $Col1$ + " " + $Col2$;

In general it is relly useful method for creating new parameters of a dataset.

0

Use the Number to String Node. You can click the "always include all columns" and it should automatically select all columns every time you import a new file.

  • Once the String is imported as a number, I lose information (e.g. leading zeros). So this is not a suitable solution for me. – ATN May 21 '14 at 08:09
0

Probably it would work better if you were using a Line Reader and split the columns based on your preferred delimiter.

Gábor Bakos
  • 8,982
  • 52
  • 35
  • 52
  • In this case I have the opposite problem with all columns being character columns (if I read the header line), or to take a guess (which is basically the same problem) when discarding the header line. Plus I would like to understand why any modification of the XML file generates an error in knime. – ATN May 21 '14 at 08:13
  • @hadinbe I have no idea what might cause the problem with the xml file changes. Probably there is a derived data in other places. Regarding the header problem: You can remove the first row, split it independently, and reassign with the Insert Column Header (http://www.knime.org/files/nodedetails/_manipulation_row_row_other_Insert_Column_Header.html) node. – Gábor Bakos May 21 '14 at 16:49
0

You can specify the column type for each column in the dialog of the File Reader node. Therefore open the dialog and double click on the header of the column you want to change. A little window will open, in which you can specify the type of the column. Change it from Integer to String.

Kilian
  • 26
  • 3