This node allows you to execute arbitrary java code to create
a new column or to replace an existing one. Enter the java code in
the text area. To address certain input values of the table
use $name_of_col$
(a double click on the elements in the
column list will insert a the place holder at the current cursor
position). For instance, the sum of the first two columns is
$col_1$ + $col_2$
(replace col_1 and col_2 by the
name of the columns). Please also specify the return type with one
of the radio buttons. You can also use more complex
statements such as if-else switches. For instance, to bin a numeric
column you could enter code as follows and check the String return type:
String bin; if ($col_1$ < 0.5) { bin = "Very small"; } else if ($col_1$ < 2.0) { bin = "Small"; } else if ($col_1$ < 10.0) { bin = "Medium"; } else if ($col_1$ < 20) { bin = "Large"; } else { bin = "Very Large"; } return bin;
You can also use static methods of java utility classes, e.g. to get a
column with random values, simply enter Math.random()
and
check the double return type.
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.
Exceptions in the snippet are caught by the framework and will
result in a missing value for the current row. If the snippet
throws an exception of class Abort
(an inner class that
is available to each snippet without further import statements),
the entire execution will halt, using the exception message
as error that is presented to the user.
Double
,
int-compatible columns as Integer
and any other column type
as String
. If the input type represents a collection type,
it will be available as (typed) array in the snippet.null
in the expression. It is your responsibility to check
for null
in this case (the fields are all real classes,
so even int
and double
are represented as their
respective class Integer
and Double
). If unselected,
a missing value in the relevant input cell will immediately produce
a missing output cell (snippet not called).You want to see the source code for this node? Click the following button and we’ll use our super-powers to find it for you.
To use this node in KNIME, install the extension KNIME Javasnippet from the below update site following our NodePit Product and Node Installation Guide:
A zipped version of the software site can be downloaded here.
Deploy, schedule, execute, and monitor your KNIME workflows locally, in the cloud or on-premises – with our brand new NodePit Runner.
Try NodePit Runner!Do you have feedback, questions, comments about NodePit, want to support this platform, or want your own nodes or workflows listed here as well? Do you think, the search results could be improved or something is missing? Then please get in touch! Alternatively, you can send us an email to mail@nodepit.com.
Please note that this is only about NodePit. We do not provide general support for KNIME — please use the KNIME forums instead.