Search in sources :

Example 6 with DataTableRowInput

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

the class FilterApplyNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    exec.setProgress(0);
    PortObject portObject = inObjects[1];
    DataTableSpec filterSpec = portObject == null ? ((BufferedDataTable) inObjects[0]).getDataTableSpec() : ((FilterDefinitionHandlerPortObject) portObject).getSpec();
    final BufferedDataTableRowOutput out = new BufferedDataTableRowOutput(exec.createDataContainer(((BufferedDataTable) inObjects[0]).getDataTableSpec()));
    execute(new DataTableRowInput((BufferedDataTable) inObjects[0]), out, filterSpec, exec, ((BufferedDataTable) inObjects[0]).size());
    return new BufferedDataTable[] { out.getDataTable() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) FilterDefinitionHandlerPortObject(org.knime.core.node.port.viewproperty.FilterDefinitionHandlerPortObject) PortObject(org.knime.core.node.port.PortObject) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Example 7 with DataTableRowInput

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

the class FilterApplyNodeModel 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 {
            final DataTableRowInput in = (DataTableRowInput) inputs[0];
            final RowOutput out = (RowOutput) outputs[0];
            PortObjectInput portObjectInput = (PortObjectInput) inputs[1];
            DataTableSpec filterSpec = portObjectInput == null ? in.getDataTableSpec() : ((FilterDefinitionHandlerPortObject) portObjectInput.getPortObject()).getSpec();
            FilterApplyNodeModel.this.execute(in, out, filterSpec, exec, -1);
        }
    };
}
Also used : BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) PortObjectInput(org.knime.core.node.streamable.PortObjectInput)

Example 8 with DataTableRowInput

use of org.knime.core.node.streamable.DataTableRowInput 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 9 with DataTableRowInput

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

the class ConcatenateTableFactory method addTable.

/**
 * Table is added and rows are copied to a new data container. Creates a new data container if this data table spec
 * differs from the previous table. This method call checks for row keys duplicates and throws a
 * {@link DuplicateKeyException}.
 *
 * @param table the table to be added
 * @param exec the execution context to possibly create a new data container
 * @throws InterruptedException
 * @throws IOException
 * @throws DuplicateKeyException
 * @throws CanceledExecutionException
 */
void addTable(final BufferedDataTable table, final ExecutionContext exec) throws InterruptedException, DuplicateKeyException, IOException, CanceledExecutionException {
    DataTableRowInput rowInput = new DataTableRowInput(table);
    addTable(rowInput, exec);
    rowInput.close();
}
Also used : DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput)

Example 10 with DataTableRowInput

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

the class CSVWriter method write.

/**
 * Same as above just usable with a streaming node implementation.
 * @param input
 * @param exec
 * @throws IOException
 * @throws CanceledExecutionException
 * @throws InterruptedException
 * @since 2.12
 */
public void write(final RowInput input, final ExecutionMonitor exec) throws IOException, CanceledExecutionException, InterruptedException {
    DataTableSpec inSpec = input.getDataTableSpec();
    final int colCount = inSpec.getNumColumns();
    // if first entry in the row (skip separator then)
    boolean first;
    // reset any previous warning
    m_lastWarning = null;
    // write column names
    if (m_settings.writeColumnHeader()) {
        if (m_settings.writeRowID()) {
            // RowHeader header
            write(quoteString("row ID", false));
            first = false;
        } else {
            first = true;
        }
        for (int i = 0; i < colCount; i++) {
            String cName = inSpec.getColumnSpec(i).getName();
            if (!first) {
                write(m_settings.getColSeparator());
            }
            first = false;
            write(quoteString(cName, false));
        }
        newLine();
    }
    // end of if write column names
    // write each row of the data
    int i = 0;
    long rowCnt = -1;
    if (input instanceof DataTableRowInput) {
        rowCnt = ((DataTableRowInput) input).getRowCount();
    }
    DataRow row;
    while ((row = input.poll()) != null) {
        String rowKey = row.getKey().toString();
        String msg;
        // set the progress
        if (rowCnt <= 0) {
            msg = "Writing row " + (i + 1) + " (\"" + rowKey + "\")";
        } else {
            msg = "Writing row " + (i + 1) + " (\"" + rowKey + "\") of " + rowCnt;
            exec.setProgress(i / (double) rowCnt, msg);
        }
        // Check if execution was canceled !
        exec.checkCanceled();
        // write the columns
        first = true;
        // first, the row id
        if (m_settings.writeRowID()) {
            write(quoteString(row.getKey().getString(), false));
            first = false;
        }
        // now all data cells
        for (int c = 0; c < colCount; c++) {
            DataCell colValue = row.getCell(c);
            if (!first) {
                write(m_settings.getColSeparator());
            }
            first = false;
            if (colValue.isMissing()) {
                // never quote missing patterns.
                write(m_settings.getMissValuePattern());
            } else {
                boolean isNumerical = false;
                DataType type = inSpec.getColumnSpec(c).getType();
                String strVal = colValue.toString();
                if (type.isCompatible(DoubleValue.class)) {
                    isNumerical = true;
                }
                if (isNumerical && (m_settings.getDecimalSeparator() != '.')) {
                    // contained in the value.
                    if (strVal.indexOf(m_settings.getDecimalSeparator()) < 0) {
                        strVal = replaceDecimalSeparator(strVal, m_settings.getDecimalSeparator());
                    } else {
                        if (m_lastWarning == null) {
                            m_lastWarning = "Specified decimal separator ('" + m_settings.getDecimalSeparator() + "') is" + " contained in the numerical value. " + "Not replacing decimal separator (e.g. " + "in row #" + i + " column #" + c + ").";
                        }
                    }
                }
                write(quoteString(strVal, isNumerical));
            }
        }
        newLine();
        i++;
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) DataCell(org.knime.core.data.DataCell) DataType(org.knime.core.data.DataType) DataRow(org.knime.core.data.DataRow)

Aggregations

DataTableRowInput (org.knime.core.node.streamable.DataTableRowInput)24 BufferedDataTableRowOutput (org.knime.core.node.streamable.BufferedDataTableRowOutput)16 BufferedDataTable (org.knime.core.node.BufferedDataTable)15 DataTableSpec (org.knime.core.data.DataTableSpec)9 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)9 RowInput (org.knime.core.node.streamable.RowInput)7 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)6 RowOutput (org.knime.core.node.streamable.RowOutput)6 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)4 DataRow (org.knime.core.data.DataRow)3 ExecutionContext (org.knime.core.node.ExecutionContext)3 PortObject (org.knime.core.node.port.PortObject)3 PortInput (org.knime.core.node.streamable.PortInput)3 DataCell (org.knime.core.data.DataCell)2 PartitionInfo (org.knime.core.node.streamable.PartitionInfo)2 PortObjectInput (org.knime.core.node.streamable.PortObjectInput)2 PortOutput (org.knime.core.node.streamable.PortOutput)2 SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)2 File (java.io.File)1 IOException (java.io.IOException)1