Search in sources :

Example 31 with BufferedDataTable

use of org.knime.core.node.BufferedDataTable in project knime-core by knime.

the class MovingAggregationNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    if (inData == null || inData.length != 1) {
        throw new InvalidSettingsException("No input table available");
    }
    final BufferedDataTable table = inData[0];
    if (table.getRowCount() == 0) {
        setWarningMessage("Empty input table found");
    } else if (!m_cumulativeComputing.getBooleanValue() && table.getRowCount() < m_winLength.getIntValue()) {
        throw new InvalidSettingsException("Window length is larger than the number of rows of the input table");
    }
    final DataTableSpec spec = table.getDataTableSpec();
    final MovingAggregationTableFactory tableFactory = createTableFactory(FileStoreFactory.createWorkflowFileStoreFactory(exec), spec);
    BufferedDataTable resultTable = tableFactory.createTable(exec, table);
    return new BufferedDataTable[] { resultTable };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 32 with BufferedDataTable

use of org.knime.core.node.BufferedDataTable in project knime-core by knime.

the class DateGeneratorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    // prepare the calendars
    Calendar from = m_from.getCalendar();
    // new since 2.8. the start time is the current time.
    if (m_useExecution.getBooleanValue()) {
        from = DateAndTimeCell.getUTCCalendar();
        from.setTimeInMillis(System.currentTimeMillis() + TimeZone.getDefault().getOffset(System.currentTimeMillis()));
    }
    Calendar to = m_to.getCalendar();
    // if the use execution time is set, we ignore the settings for the from date
    boolean useDate = (m_from.useDate() && !m_useExecution.getBooleanValue()) || m_to.useDate();
    boolean useTime = (m_from.useTime() && !m_useExecution.getBooleanValue()) || m_to.useTime();
    boolean useMillis = (m_from.useMilliseconds() && !m_useExecution.getBooleanValue()) || m_to.useMilliseconds();
    if (useDate && !useTime) {
        DateAndTimeCell.resetTimeFields(from);
        DateAndTimeCell.resetTimeFields(to);
    } else if (useTime && !useDate) {
        DateAndTimeCell.resetDateFields(from);
        DateAndTimeCell.resetDateFields(to);
    }
    if (!useMillis) {
        from.clear(Calendar.MILLISECOND);
        to.clear(Calendar.MILLISECOND);
    }
    BufferedDataContainer container = exec.createDataContainer(createOutSpec());
    int nrRows = m_noOfRows.getIntValue();
    double offset = calculateOffset(from, to, nrRows);
    double currentTime = from.getTimeInMillis();
    for (int i = 0; i < nrRows; i++) {
        // zero based row key as FileReader
        RowKey key = new RowKey("Row" + i);
        DateAndTimeCell cell = new DateAndTimeCell((long) Math.ceil(currentTime), useDate, useTime, useMillis);
        container.addRowToTable(new DefaultRow(key, cell));
        currentTime += offset;
        exec.setProgress((i + 1) / (double) nrRows, "Generating row #" + (i + 1));
        exec.checkCanceled();
    }
    container.close();
    return new BufferedDataTable[] { exec.createBufferedDataTable(container.getTable(), exec) };
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) Calendar(java.util.Calendar) SettingsModelCalendar(org.knime.timeseries.util.SettingsModelCalendar) BufferedDataTable(org.knime.core.node.BufferedDataTable) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 33 with BufferedDataTable

use of org.knime.core.node.BufferedDataTable in project knime-core by knime.

the class ReadPNGFromURLNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    DataTableSpec spec = inData[0].getDataTableSpec();
    AtomicLong failCount = new AtomicLong();
    ColumnRearranger rearranger = createColumnRearranger(spec, failCount);
    BufferedDataTable out = exec.createColumnRearrangeTable(inData[0], rearranger, exec);
    long rowCount = out.size();
    long fail = failCount.get();
    if (rowCount > 0 && rowCount == fail) {
        throw new Exception("None of the URLs could be read " + "as PNG (see log for details)");
    } else if (fail > 0) {
        setWarningMessage("Failed to read " + fail + "/" + rowCount + " files");
    }
    return new BufferedDataTable[] { out };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) AtomicLong(java.util.concurrent.atomic.AtomicLong) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException)

Example 34 with BufferedDataTable

use of org.knime.core.node.BufferedDataTable in project knime-core by knime.

the class AppendVariableToTableNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable t = (BufferedDataTable) inData[1];
    DataTableSpec ts = t.getSpec();
    ColumnRearranger ar = createColumnRearranger(ts);
    BufferedDataTable out = exec.createColumnRearrangeTable(t, ar, exec);
    return new BufferedDataTable[] { out };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 35 with BufferedDataTable

use of org.knime.core.node.BufferedDataTable in project knime-core by knime.

the class VariableFileReaderNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    Map<String, FlowVariable> stack = createStack(m_frSettings.getVariableName());
    VariableFileReaderNodeSettings settings = m_frSettings.createSettingsFrom(stack);
    LOGGER.info("Preparing to read from '" + m_frSettings.getDataFileLocation().toString() + "'.");
    // check again the settings - especially file existence (under Linux
    // files could be deleted/renamed since last config-call...
    SettingsStatus status = settings.getStatusOfSettings(true, null);
    if (status.getNumOfErrors() > 0) {
        throw new InvalidSettingsException(status.getAllErrorMessages(10));
    }
    DataTableSpec tSpec = settings.createDataTableSpec();
    FileTable fTable = new FileTable(tSpec, settings, settings.getSkippedColumns(), exec);
    // create a DataContainer and fill it with the rows read. It is faster
    // then reading the file every time (for each row iterator), and it
    // collects the domain for each column for us. Also, if things fail,
    // the error message is printed during file reader execution (were it
    // belongs to) and not some time later when a node uses the row
    // iterator from the file table.
    BufferedDataContainer c = exec.createDataContainer(fTable.getDataTableSpec(), /* initDomain= */
    true);
    int row = 0;
    FileRowIterator it = fTable.iterator();
    try {
        if (it.getZipEntryName() != null) {
            // seems we are reading a ZIP archive.
            LOGGER.info("Reading entry '" + it.getZipEntryName() + "' from the specified ZIP archive.");
        }
        while (it.hasNext()) {
            row++;
            DataRow next = it.next();
            String message = "Caching row #" + row + " (\"" + next.getKey() + "\")";
            exec.setMessage(message);
            exec.checkCanceled();
            c.addRowToTable(next);
        }
        if (it.zippedSourceHasMoreEntries()) {
            // after reading til the end of the file this returns a valid
            // result
            setWarningMessage("Source is a ZIP archive with multiple " + "entries. Only reading first entry!");
        }
    } catch (DuplicateKeyException dke) {
        String msg = dke.getMessage();
        if (msg == null) {
            msg = "Duplicate row IDs";
        }
        msg += ". Consider making IDs unique in the advanced settings.";
        DuplicateKeyException newDKE = new DuplicateKeyException(msg);
        newDKE.initCause(dke);
        throw newDKE;
    } finally {
        c.close();
    }
    // user settings allow for truncating the table
    if (it.iteratorEndedEarly()) {
        setWarningMessage("Data was truncated due to user settings.");
    }
    BufferedDataTable out = c.getTable();
    // closes all sources.
    fTable.dispose();
    return new BufferedDataTable[] { out };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) SettingsStatus(org.knime.core.util.tokenizer.SettingsStatus) DataRow(org.knime.core.data.DataRow) DuplicateKeyException(org.knime.core.util.DuplicateKeyException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Aggregations

BufferedDataTable (org.knime.core.node.BufferedDataTable)460 DataTableSpec (org.knime.core.data.DataTableSpec)221 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)148 DataRow (org.knime.core.data.DataRow)130 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)104 PortObject (org.knime.core.node.port.PortObject)102 DataCell (org.knime.core.data.DataCell)93 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)66 DataColumnSpec (org.knime.core.data.DataColumnSpec)65 DefaultRow (org.knime.core.data.def.DefaultRow)63 RowKey (org.knime.core.data.RowKey)59 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)55 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)54 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)50 ExecutionContext (org.knime.core.node.ExecutionContext)47 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)44 IOException (java.io.IOException)43 ArrayList (java.util.ArrayList)37 LinkedHashMap (java.util.LinkedHashMap)31 Test (org.junit.Test)30