Search in sources :

Example 16 with RowInput

use of org.knime.core.node.streamable.RowInput in project knime-core by knime.

the class RowKeyUtil2 method changeRowKey.

/**
 * <p>Replaces the row key by the values of the column with the given name
 * and appends a new column with the old key values if the
 * <code>newColName</code> variable is a non empty <code>String</code>.</p>
 * <p>
 * Call the {@link RowKeyUtil2#getDuplicatesCounter()} and
 * {@link RowKeyUtil2#getMissingValueCounter()}
 * methods to get information about the replaced duplicates and missing
 * values after this method is completed.
 * </p>
 * @param inData The {@link BufferedDataTable} with the input data
 * @param exec the {@link ExecutionContext} to check for cancel and to
 * provide status messages
 * @param selRowKeyColName the name of the column which should replace
 * the row key or <code>null</code> if a new one should be created
 * @param appendColumn <code>true</code> if a new column should be created
 * @param newColSpec the {@link DataColumnSpec} of the new column or
 * <code>null</code>  if no column should be created at all
 * @param ensureUniqueness if set to <code>true</code> the method ensures
 * the uniqueness of the row key even if the values of the selected row
 * aren't unique
 * @param replaceMissingVals if set to <code>true</code> the method
 * replaces missing values with ?
 * @param removeRowKeyCol removes the selected row key column if set
 * to <code>true</code>
 * @param hiliteMap <code>true</code> if a map should be maintained that
 * maps the new row id to the old row id
 * @return the {@link BufferedDataTable} with the replaced row key and
 * the optional appended new column with the old row keys.
 * @throws Exception if the cancel button was pressed or the input data
 * isn't valid.
 */
public BufferedDataTable changeRowKey(final BufferedDataTable inData, final ExecutionContext exec, final String selRowKeyColName, final boolean appendColumn, final DataColumnSpec newColSpec, final boolean ensureUniqueness, final boolean replaceMissingVals, final boolean removeRowKeyCol, final boolean hiliteMap) throws Exception {
    LOGGER.debug("Entering changeRowKey(inData, exec, selRowKeyColName, " + "newColName) of class RowKeyUtil.");
    DataTableSpec outSpec = inData.getDataTableSpec();
    if (removeRowKeyCol) {
        outSpec = createTableSpec(outSpec, selRowKeyColName);
    }
    if (appendColumn) {
        if (newColSpec == null) {
            throw new NullPointerException("NewColumnSpec must not be null");
        }
        outSpec = AppendedColumnTable.getTableSpec(outSpec, newColSpec);
    }
    final BufferedDataContainer newContainer = exec.createDataContainer(outSpec, true);
    RowInput rowInput = new DataTableRowInput(inData);
    RowOutput rowOutput = new BufferedDataTableRowOutput(newContainer);
    changeRowKey(rowInput, rowOutput, exec, selRowKeyColName, appendColumn, newColSpec, ensureUniqueness, replaceMissingVals, removeRowKeyCol, hiliteMap, outSpec.getNumColumns(), inData.getRowCount());
    newContainer.close();
    return newContainer.getTable();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Example 17 with RowInput

use of org.knime.core.node.streamable.RowInput in project knime-core by knime.

the class SplitNodeModel2 method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    if (m_conf == null) {
        m_conf = createColFilterConf();
    }
    final DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
    return new StreamableOperator() {

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            ColumnRearranger[] a = createColumnRearrangers(inSpec);
            StreamableFunction func1 = a[0].createStreamableFunction(0, 0);
            StreamableFunction func2 = a[1].createStreamableFunction(0, 1);
            // use both functions to actually do it
            RowInput rowInput = ((RowInput) inputs[0]);
            RowOutput rowOutput1 = ((RowOutput) outputs[0]);
            RowOutput rowOutput2 = ((RowOutput) outputs[1]);
            StreamableFunction.runFinalInterwoven(rowInput, func1, rowOutput1, func2, rowOutput2, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableFunction(org.knime.core.node.streamable.StreamableFunction) RowInput(org.knime.core.node.streamable.RowInput)

Example 18 with RowInput

use of org.knime.core.node.streamable.RowInput in project knime-core by knime.

the class RowKeyNodeModel2 method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    LOGGER.debug("Entering createStreamableOperator-method of class RowKeyNodeModel");
    if (m_replaceKey.getBooleanValue()) {
        DataTableSpec outSpec = configure((DataTableSpec) inSpecs[DATA_IN_PORT], true);
        return new StreamableOperator() {

            @Override
            public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
                RowInput rowInput = (RowInput) inputs[DATA_IN_PORT];
                RowOutput rowOutput = (RowOutput) outputs[DATA_OUT_PORT];
                replaceKey(rowInput, rowOutput, outSpec.getNumColumns(), -1, exec);
            }
        };
    } else if (m_appendRowKey.getBooleanValue()) {
        LOGGER.debug("The user only wants to append a new column with " + "name " + m_newColumnName);
        // the user wants only a column with the given name which
        // contains the rowkey as value
        final DataTableSpec tableSpec = (DataTableSpec) inSpecs[DATA_IN_PORT];
        final String newColumnName = m_newColumnName.getStringValue();
        final ColumnRearranger c = RowKeyUtil2.createColumnRearranger(tableSpec, newColumnName, StringCell.TYPE);
        return c.createStreamableFunction();
    } else {
        // the given data
        return new StreamableFunction() {

            @Override
            public DataRow compute(final DataRow input) throws Exception {
                return input;
            }
        };
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) StreamableFunction(org.knime.core.node.streamable.StreamableFunction) DataRow(org.knime.core.data.DataRow) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException)

Example 19 with RowInput

use of org.knime.core.node.streamable.RowInput in project knime-core by knime.

the class RowKeyNodeModel2 method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    LOGGER.debug("Entering execute(inData, exec) of class RowKeyNodeModel");
    // check input data
    if (inData == null || inData.length != 1 || inData[DATA_IN_PORT] == null) {
        throw new IllegalArgumentException("No input data available.");
    }
    final BufferedDataTable data = inData[DATA_IN_PORT];
    BufferedDataTable outData = null;
    if (m_replaceKey.getBooleanValue()) {
        // create outspec
        DataTableSpec outSpec = configure(data.getDataTableSpec(), true);
        // create table
        final BufferedDataContainer newContainer = exec.createDataContainer(outSpec, true);
        RowInput rowInput = new DataTableRowInput(data);
        RowOutput rowOutput = new BufferedDataTableRowOutput(newContainer);
        replaceKey(rowInput, rowOutput, outSpec.getNumColumns(), data.getRowCount(), exec);
        newContainer.close();
        outData = newContainer.getTable();
    } else if (m_appendRowKey.getBooleanValue()) {
        LOGGER.debug("The user only wants to append a new column with " + "name " + m_newColumnName);
        // the user wants only a column with the given name which
        // contains the rowkey as value
        final DataTableSpec tableSpec = data.getDataTableSpec();
        final String newColumnName = m_newColumnName.getStringValue();
        final ColumnRearranger c = RowKeyUtil2.createColumnRearranger(tableSpec, newColumnName, StringCell.TYPE);
        outData = exec.createColumnRearrangeTable(data, c, exec);
        exec.setMessage("New column created");
        LOGGER.debug("Column appended successfully");
    } else {
        // the user doesn't want to do anything at all so we simply return
        // the given data
        outData = data;
        LOGGER.debug("The user hasn't selected a new row ID column" + " and hasn't entered a new column name.");
    }
    LOGGER.debug("Exiting execute(inData, exec) of class RowKeyNodeModel.");
    return new BufferedDataTable[] { outData };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Example 20 with RowInput

use of org.knime.core.node.streamable.RowInput in project knime-core by knime.

the class AppendedRowsNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    return new StreamableOperator() {

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            List<RowInput> noNullList = new ArrayList<RowInput>();
            for (PortInput p : inputs) {
                if (p != null) {
                    noNullList.add((RowInput) p);
                }
            }
            RowInput[] rowInputs = noNullList.toArray(new RowInput[noNullList.size()]);
            run(rowInputs, (RowOutput) outputs[0], exec, -1);
        }
    };
}
Also used : ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) ArrayList(java.util.ArrayList) FilterColumnRowInput(org.knime.base.data.filter.column.FilterColumnRowInput) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) AppendedRowsRowInput(org.knime.core.data.append.AppendedRowsRowInput) PortInput(org.knime.core.node.streamable.PortInput)

Aggregations

RowInput (org.knime.core.node.streamable.RowInput)33 ExecutionContext (org.knime.core.node.ExecutionContext)25 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)25 RowOutput (org.knime.core.node.streamable.RowOutput)21 DataTableSpec (org.knime.core.data.DataTableSpec)17 DataTableRowInput (org.knime.core.node.streamable.DataTableRowInput)16 DataRow (org.knime.core.data.DataRow)11 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)11 BufferedDataTable (org.knime.core.node.BufferedDataTable)10 BufferedDataTableRowOutput (org.knime.core.node.streamable.BufferedDataTableRowOutput)9 StreamableOperatorInternals (org.knime.core.node.streamable.StreamableOperatorInternals)9 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)8 SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)7 DataCell (org.knime.core.data.DataCell)6 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)6 PortInput (org.knime.core.node.streamable.PortInput)6 IOException (java.io.IOException)5 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)5 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)5 File (java.io.File)4