Optional input ports

I haven’t looked very hard but I haven’t found an example of using this capability. Some initial questions:

  1. Are ports configured as optional in the NodeFactory.XML or .java - and how is this property set. (I assume its set when the input is created and can’t be subsequently altered).

  2. Its not obvious to me how to deduce whether an input is optional from a tableSpec. Will the tableSpec be null? (The PortObjectSpec is document as not for public use).

I’m aware that I’m returning to coding KNIME nodes after some time away from JAVA and I may consequently be seeking answers which I should either know or be able to find …

Hi everybody,

while reading the release notes of 2.2 (great release btw, worded smoothly out of the box without any problems), the same questions popped into my mind too. An example would be indeed wonderful.




You can try this

public static final PortType OPTIONAL_PORT_TYPE = new PortType(BufferedDataTable.class, true);
 * Constructor for the node model.
protected MyLearnerNodeModel()
    // three incoming ports where port 1 and 3 are optional and one outgoing port is assumed
    super(createOPOs(3, 1, 3), createOPOs(1));
private static PortType[] createOPOs(final int nrDataPorts, final int... optionalPortsIds)
    PortType[] portTypes = new PortType[nrDataPorts];
    Arrays.fill(portTypes, BufferedDataTable.TYPE);        

    if (optionalPortsIds.length > 0) {
        for (int portId : optionalPortsIds) {
            if ((portId - 1) < nrDataPorts) {
                portTypes[portId - 1] = OPTIONAL_PORT_TYPE;
    return portTypes;

1 Like

Thanks.  I'll give this a try tomorrow ...


What do I need to import to define PortType?


What ide/editor do You use for dev knime? I use the traditional one KNIME Software Development Kit which you can find here http://www.knime.org/downloads/overview. When You paste this code in [...]NodeModel.java file enviroment should tell You what it is missing and how to and from import it.

import org.knime.core.node.port.PortType;
import org.knime.core.node.BufferedDataTable;

Thanks for the help.

I'm using a new download of the 32-bit windows SDK from http://www.knime.org/downloads/sdk/win32

This version did report that PortType was undefined but I'd forgotten that you have to left click for the dialog with change suggestions. (Windows convention would be float for tool tip help or right click for options  Left click is for buttons.)

Optional inputs nodes working nicely.

Thank you.