Search in sources :

Example 6 with BufferedDataTableRowOutput

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

the class RowFilter2PortNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable in = inData[0];
    // in case the node was configured and the workflow is closed
    // (and saved), the row filter isn't configured upon reloading.
    // here, we give it a chance to configure itself (e.g. find the column
    // index)
    m_rowFilter.configure(in.getDataTableSpec());
    BufferedDataContainer match = exec.createDataContainer(in.getDataTableSpec());
    BufferedDataContainer miss = exec.createDataContainer(in.getDataTableSpec());
    RowOutput rowOutput1 = new BufferedDataTableRowOutput(match);
    RowOutput rowOutput2 = new BufferedDataTableRowOutput(miss);
    RowInput rowInput = new DataTableRowInput(inData[0]);
    // do it
    this.execute(rowInput, rowOutput1, rowOutput2, inData[0].size(), exec);
    // note: tables are closed in the private execute method
    return new BufferedDataTable[] { match.getTable(), miss.getTable() };
}
Also used : BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) BufferedDataTable(org.knime.core.node.BufferedDataTable) 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 7 with BufferedDataTableRowOutput

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

the class FileReaderNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] data, final ExecutionContext exec) throws Exception {
    DataTableSpec spec = m_frSettings.createDataTableSpec(false);
    BufferedDataTableRowOutput output = new BufferedDataTableRowOutput(exec.createDataContainer(spec));
    createStreamableOperator(null, null).runFinal(new PortInput[0], new PortOutput[] { output }, exec);
    return new BufferedDataTable[] { output.getDataTable() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataTable(org.knime.core.node.BufferedDataTable) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Example 8 with BufferedDataTableRowOutput

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

the class JavaRowSplitterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    final int rowCount = inData[0].getRowCount();
    m_rowCount = rowCount;
    DataTableRowInput input = new DataTableRowInput(inData[0]);
    DataTableSpec spec = inData[0].getDataTableSpec();
    BufferedDataContainer trueMatch = exec.createDataContainer(spec);
    BufferedDataTableRowOutput[] outputs;
    BufferedDataContainer falseMatch = null;
    if (getNrOutPorts() == 2) {
        falseMatch = exec.createDataContainer(spec);
    }
    outputs = Stream.of(trueMatch, falseMatch).filter(f -> f != null).map(f -> new BufferedDataTableRowOutput(f)).toArray(BufferedDataTableRowOutput[]::new);
    execute(input, outputs, exec);
    BufferedDataTable[] outTables = Stream.of(trueMatch, falseMatch).filter(f -> f != null).map(f -> f.getTable()).toArray(BufferedDataTable[]::new);
    return outTables;
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) JavaScriptingCustomizer(org.knime.ext.sun.nodes.script.settings.JavaScriptingCustomizer) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) Expression(org.knime.ext.sun.nodes.script.expression.Expression) ExecutionContext(org.knime.core.node.ExecutionContext) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) BooleanValue(org.knime.core.data.BooleanValue) DataCell(org.knime.core.data.DataCell) PortInput(org.knime.core.node.streamable.PortInput) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) RowInput(org.knime.core.node.streamable.RowInput) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) ColumnCalculator(org.knime.ext.sun.nodes.script.calculator.ColumnCalculator) IOException(java.io.IOException) OutputPortRole(org.knime.core.node.streamable.OutputPortRole) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) NodeModel(org.knime.core.node.NodeModel) File(java.io.File) DataRow(org.knime.core.data.DataRow) PortOutput(org.knime.core.node.streamable.PortOutput) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) BufferedDataTable(org.knime.core.node.BufferedDataTable) Stream(java.util.stream.Stream) KnowsRowCountTable(org.knime.core.node.BufferedDataTable.KnowsRowCountTable) FlowVariableProvider(org.knime.ext.sun.nodes.script.calculator.FlowVariableProvider) InputPortRole(org.knime.core.node.streamable.InputPortRole) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) CheckUtils(org.knime.core.node.util.CheckUtils) MergeOperator(org.knime.core.node.streamable.MergeOperator) RowOutput(org.knime.core.node.streamable.RowOutput) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings) DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) BufferedDataTable(org.knime.core.node.BufferedDataTable) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Example 9 with BufferedDataTableRowOutput

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

the class UngroupOperation2 method compute.

/**
 * Performs the ungroup operation on the given data table.
 *
 * @param exec the execution context
 * @param table table to perform the ungroup operation on
 * @param trans the hilite translater, will be modified directly. Must be non-null if hiliting is enabled, can be
 *            <code>null</code> otherwise
 * @return the table with the ungrouped collections
 * @throws CanceledExecutionException if the execution has been canceled
 * @throws InterruptedException if the execution has been interrupted
 * @throws InvalidSettingsException thrown if the table doesn't contain a collection column at one of the column
 *             indices to be ungrouped
 * @throws IllegalArgumentException if hiliting is enabled and no hilite translater is given
 */
public BufferedDataTable compute(final ExecutionContext exec, final BufferedDataTable table, final HiLiteTranslator trans) throws CanceledExecutionException, InterruptedException, InvalidSettingsException {
    final BufferedDataContainer dc = exec.createDataContainer(createTableSpec(table.getDataTableSpec(), m_removeCollectionCol, m_colIndices));
    if (table.size() == 0) {
        dc.close();
        return dc.getTable();
    }
    DataTableRowInput in = new DataTableRowInput(table);
    BufferedDataTableRowOutput out = new BufferedDataTableRowOutput(dc);
    try {
        compute(in, out, exec, table.size(), trans);
    } finally {
        in.close();
        out.close();
    }
    return out.getDataTable();
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Example 10 with BufferedDataTableRowOutput

use of org.knime.core.node.streamable.BufferedDataTableRowOutput 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)

Aggregations

BufferedDataTableRowOutput (org.knime.core.node.streamable.BufferedDataTableRowOutput)18 DataTableRowInput (org.knime.core.node.streamable.DataTableRowInput)14 BufferedDataTable (org.knime.core.node.BufferedDataTable)13 DataTableSpec (org.knime.core.data.DataTableSpec)9 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)8 RowInput (org.knime.core.node.streamable.RowInput)6 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)4 RowOutput (org.knime.core.node.streamable.RowOutput)4 DataRow (org.knime.core.data.DataRow)3 DataCell (org.knime.core.data.DataCell)2 RowKey (org.knime.core.data.RowKey)2 PortObject (org.knime.core.node.port.PortObject)2 FilterDefinitionHandlerPortObject (org.knime.core.node.port.viewproperty.FilterDefinitionHandlerPortObject)2 PartitionInfo (org.knime.core.node.streamable.PartitionInfo)2 PortInput (org.knime.core.node.streamable.PortInput)2 PortOutput (org.knime.core.node.streamable.PortOutput)2 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)2 SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)2 File (java.io.File)1 IOException (java.io.IOException)1