The following node is available in the Open Source KNIME predictive analytics and data mining platform version 2.8.0. Discover over 1000 other nodes, as well as enterprise functionality at http://knime.com.

Java Snippet

This node allows you to execute arbitrary java code to create a new columns or to replace an existing ones. Enter the java code in the text area.

An output columns is defined by creating a java field bound to this column. The value assigned to this field will be written to the output.

Note, that this node allows to add or modify flow variables in the same manner.

It is also possible to use external java libraries (that is, libraries that are not part of java boot classpath). In order to include such external jar or zip files, add their location in the "Additional Libraries" tab using the control buttons.

You can define reusable templates with the "Create templates..." button. Templates are stored in the users workspace by default and can be accessed via the "Templates" tab.

Dialog Options

Column List
The list contains the columns that are available in the input table. Double click any of the column names to insert the respective field in the expression editor. It will replace your current selection or simply insert at the current caret position.
Flow Variable List
The list contains the flow variables that are currently available at the node input. Double clicking any of the entries will insert the respective identifier at the current cursor position (replacing the selection, if any).
Snippet text area
Enter your java code here. You can access input columns or flow variables by defining them in the Input table. A second way is to use the methods getCell(name, type) or getFlowVariable(name, type) where name is the name of the input column or the flow variable, respectively. You can use the following values for the type parameter.
tString : String (f)
tInt : Integer (f)
tDouble : Double (f)
tLong : Long
tBoolean : Boolean
tDate : java.util.Date
tCalendar : java.util.Calendar
tXML : org.w3c.document
(f) These Types can be used for flow variables.
Java Snippet Methods:
getCell(name, type)* : Get value of a cell by column name
isType(name, type)* : Test for type by column name
isMissing(name)* : Check if missing by column name
getColumnCount(index, type) : Number of columns in the input table
getColumnName(index) : Retrieve column name at index

getFlowVariable(name, type) : Get value of a flow variable by name
* Methods exist in a variant that takes the column index instead of its name.

You can hit ctrl+space to get an auto completion box with all available classes, methods and fields. When you select a class and hit enter a import statement will be generated if missing.

Note, that the snippet allows to define custom global variables and custom imports.

Exceptions in the snippet are caught by the framework and will result in missing values for all output columns for the row being processed unless there are flow variables defined by the snippet (in which case the execution will always fail). You can force the node to fail execution by throwing an exception of class Abort.

Input
Define system input fields for the snippet text area. Every field will be populated with the data of the defined input during execution.
Output
To define output columns and flow variables by adding columns to this table. Every row in the Output table defines a java field bound to a column. Values assigned to this field in the snippet will show up at the output.

Ports

Input Ports
0 Input table.
Output Ports
0 Input table with additional or replaced columns.
This node is contained in KNIME Java Snippet Nodes (draft) provided by KNIME GmbH, Konstanz, Germany.