Search in sources :

Example 21 with RowInput

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

the class AppendedRowsNodeModel method run.

void run(final RowInput[] inputs, final RowOutput output, final ExecutionMonitor exec, final long totalRowCount) throws Exception {
    RowInput[] corrected;
    if (m_isIntersection) {
        final RowInput[] noNullArray = noNullArray(inputs);
        corrected = new RowInput[noNullArray.length];
        DataTableSpec[] inSpecs = new DataTableSpec[noNullArray.length];
        for (int i = 0; i < noNullArray.length; i++) {
            inSpecs[i] = noNullArray[i].getDataTableSpec();
        }
        String[] intersection = getIntersection(inSpecs);
        for (int i = 0; i < noNullArray.length; i++) {
            corrected[i] = new FilterColumnRowInput(noNullArray[i], intersection);
        }
    } else {
        corrected = inputs;
    }
    AppendedRowsTable.DuplicatePolicy duplPolicy;
    if (m_isFailOnDuplicate) {
        duplPolicy = AppendedRowsTable.DuplicatePolicy.Fail;
    } else if (m_isAppendSuffix) {
        duplPolicy = AppendedRowsTable.DuplicatePolicy.AppendSuffix;
    } else {
        duplPolicy = AppendedRowsTable.DuplicatePolicy.Skip;
    }
    AppendedRowsRowInput appendedInput = AppendedRowsRowInput.create(corrected, duplPolicy, m_suffix, exec, totalRowCount);
    try {
        DataRow next;
        // note, this iterator throws runtime exceptions when canceled.
        while ((next = appendedInput.poll()) != null) {
            // may throw exception, also sets progress
            output.push(next);
        }
    } catch (AppendedRowsIterator.RuntimeCanceledExecutionException rcee) {
        throw rcee.getCause();
    } finally {
        output.close();
    }
    if (appendedInput.getNrRowsSkipped() > 0) {
        setWarningMessage("Filtered out " + appendedInput.getNrRowsSkipped() + " duplicate row(s).");
    }
    if (m_enableHiliting) {
        Map<RowKey, Set<RowKey>> map = createHiliteTranslationMap(appendedInput.getDuplicateNameMap());
        m_hiliteTranslator.setMapper(new DefaultHiLiteMapper(map));
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) RowKey(org.knime.core.data.RowKey) 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) DataRow(org.knime.core.data.DataRow) DuplicatePolicy(org.knime.core.data.append.AppendedRowsTable.DuplicatePolicy) AppendedRowsIterator(org.knime.core.data.append.AppendedRowsIterator) AppendedRowsTable(org.knime.core.data.append.AppendedRowsTable) AppendedRowsRowInput(org.knime.core.data.append.AppendedRowsRowInput) FilterColumnRowInput(org.knime.base.data.filter.column.FilterColumnRowInput) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper)

Example 22 with RowInput

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

the class AppendedRowsNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] rawInData, final ExecutionContext exec) throws Exception {
    // remove all null tables first (optional input data)
    BufferedDataTable[] noNullArray = noNullArray(rawInData);
    DataTableSpec[] noNullSpecs = new DataTableSpec[noNullArray.length];
    for (int i = 0; i < noNullArray.length; i++) {
        noNullSpecs[i] = noNullArray[i].getDataTableSpec();
    }
    // table can only be wrapped if a suffix is to be append or the node fails in case of duplicate row ID's
    if (m_isAppendSuffix || m_isFailOnDuplicate) {
        // just wrap the tables virtually instead of traversing it and copying the rows
        // virtually create the concatenated table (no traverse necessary)
        Optional<String> suffix = m_isAppendSuffix ? Optional.of(m_suffix) : Optional.empty();
        BufferedDataTable concatTable = exec.createConcatenateTable(exec, suffix, m_isFailOnDuplicate, noNullArray);
        if (m_isIntersection) {
            // wrap the table and filter the non-intersecting columns
            DataTableSpec actualOutSpec = getOutputSpec(noNullSpecs);
            DataTableSpec currentOutSpec = concatTable.getDataTableSpec();
            String[] intersectCols = getIntersection(actualOutSpec, currentOutSpec);
            ColumnRearranger cr = new ColumnRearranger(currentOutSpec);
            cr.keepOnly(intersectCols);
            concatTable = exec.createColumnRearrangeTable(concatTable, cr, exec);
        }
        if (m_enableHiliting) {
            AppendedRowsTable tmp = new AppendedRowsTable(DuplicatePolicy.Fail, null, noNullArray);
            Map<RowKey, Set<RowKey>> map = createHiliteTranslationMap(createDuplicateMap(tmp, exec, m_suffix == null ? "" : m_suffix));
            m_hiliteTranslator.setMapper(new DefaultHiLiteMapper(map));
        }
        return new BufferedDataTable[] { concatTable };
    } else {
        // traverse the table and copy the rows
        long totalRowCount = 0L;
        RowInput[] inputs = new RowInput[noNullArray.length];
        for (int i = 0; i < noNullArray.length; i++) {
            totalRowCount += noNullArray[i].size();
            inputs[i] = new DataTableRowInput(noNullArray[i]);
        }
        DataTableSpec outputSpec = getOutputSpec(noNullSpecs);
        BufferedDataTableRowOutput output = new BufferedDataTableRowOutput(exec.createDataContainer(outputSpec));
        run(inputs, output, exec, totalRowCount);
        return new BufferedDataTable[] { output.getDataTable() };
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) RowKey(org.knime.core.data.RowKey) 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) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) AppendedRowsTable(org.knime.core.data.append.AppendedRowsTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Example 23 with RowInput

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

the class NormalizerApplyNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    if (getNrOutPorts() == 2) {
        // by default call the default implementation of this method
        return super.createStreamableOperator(partitionInfo, inSpecs);
    } else {
        return new StreamableOperator() {

            @Override
            public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
                assert outputs.length == 1;
                NormalizerPortObject model = (NormalizerPortObject) ((PortObjectInput) inputs[0]).getPortObject();
                RowInput rowInput = (RowInput) inputs[1];
                AffineTransTable t = new AffineTransTable(rowInput, getAffineTrans(model.getConfiguration()));
                RowOutput rowOutput = (RowOutput) outputs[0];
                RowIterator it = t.iterator();
                while (it.hasNext()) {
                    rowOutput.push(it.next());
                }
                if (t.getErrorMessage() != null) {
                    // TODO collect error message from remote nodes if run distributed
                    setWarningMessage(t.getErrorMessage());
                }
                rowInput.close();
                rowOutput.close();
            }
        };
    }
}
Also used : NormalizerPortObject(org.knime.base.data.normalize.NormalizerPortObject) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) RowIterator(org.knime.core.data.RowIterator) AffineTransTable(org.knime.base.data.normalize.AffineTransTable) RowInput(org.knime.core.node.streamable.RowInput)

Example 24 with RowInput

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

the class NominalValueRowFilterNodeModel method createStreamableOperator.

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

        @SuppressWarnings("null")
        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            RowInput in = (RowInput) inputs[0];
            RowOutput match = (RowOutput) outputs[0];
            RowOutput miss = m_splitter ? (RowOutput) outputs[1] : null;
            try {
                long rowIdx = -1;
                DataRow row;
                while ((row = in.poll()) != null) {
                    rowIdx++;
                    exec.setProgress("Adding row " + rowIdx + ".");
                    exec.checkCanceled();
                    if (matches(row)) {
                        match.push(row);
                    } else if (m_splitter) {
                        miss.push(row);
                    }
                }
            } finally {
                match.close();
                if (m_splitter) {
                    miss.close();
                }
            }
        }
    };
}
Also used : RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) RowInput(org.knime.core.node.streamable.RowInput) DataRow(org.knime.core.data.DataRow)

Example 25 with RowInput

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

the class LagColumnStreamableOperator method execute.

BufferedDataTable execute(final BufferedDataTable table, final ExecutionContext exec) throws Exception {
    long maxRows = table.size();
    int maxLag = m_configuration.getLag() * m_configuration.getLagInterval();
    if (m_configuration.isSkipInitialIncompleteRows()) {
        maxRows -= maxLag;
    }
    if (!m_configuration.isSkipLastIncompleteRows()) {
        maxRows += maxLag;
    }
    m_maxRows = maxRows;
    BufferedDataContainer output = exec.createDataContainer(m_outSpec);
    RowInput wrappedInput = new DataTableRowInput(table);
    DataContainerPortOutput wrappedOutput = new DataContainerPortOutput(output);
    runFinal(new PortInput[] { wrappedInput }, new PortOutput[] { wrappedOutput }, exec);
    return wrappedOutput.getTable();
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput)

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