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 };
}
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) };
}
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 };
}
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 };
}
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 };
}
Aggregations