Search in sources :

Example 1 with FlowVariablePortObject

use of org.knime.core.node.port.flowvariable.FlowVariablePortObject in project knime-core by knime.

the class TableColumnToVariableNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    if (inData[0] instanceof BufferedDataTable) {
        final BufferedDataTable table = (BufferedDataTable) inData[0];
        final int colIndex = table.getSpec().findColumnIndex(m_column.getStringValue());
        assert colIndex >= 0 : colIndex;
        for (DataRow dataRow : table) {
            DataCell cell = dataRow.getCell(colIndex);
            if (cell.isMissing()) {
                if (m_ignoreMissing.getBooleanValue()) {
                    continue;
                }
                throw new Exception("Missing value in column (" + m_column.getColumnName() + ") in row: " + dataRow.getKey());
            }
            if (cell instanceof IntValue) {
                final IntValue iv = (IntValue) cell;
                pushFlowVariableInt(dataRow.getKey().getString(), iv.getIntValue());
            } else if (cell instanceof DoubleValue) {
                final DoubleValue dv = (DoubleValue) cell;
                pushFlowVariableDouble(dataRow.getKey().getString(), dv.getDoubleValue());
            } else if (cell instanceof StringValue) {
                final StringValue sv = (StringValue) cell;
                pushFlowVariableString(dataRow.getKey().getString(), sv.getStringValue());
            }
        }
    }
    return new FlowVariablePortObject[] { FlowVariablePortObject.INSTANCE };
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) StringValue(org.knime.core.data.StringValue) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) DataRow(org.knime.core.data.DataRow) IntValue(org.knime.core.data.IntValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 DataCell (org.knime.core.data.DataCell)1 DataRow (org.knime.core.data.DataRow)1 DoubleValue (org.knime.core.data.DoubleValue)1 IntValue (org.knime.core.data.IntValue)1 StringValue (org.knime.core.data.StringValue)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)1